public String getIndexUUID() { return index.getUUID(); }
/** * Resolves index directory against this NodePath * ${data.paths}/nodes/{node.id}/indices/{index.uuid} */ public Path resolve(Index index) { return indicesPath.resolve(index.getUUID()); }
public boolean hasIndex(Index index) { return indices.containsKey(index.getUUID()); }
/** * Returns the indexes UUID */ public String getUUID() { return getIndex().getUUID(); }
/** * Returns an IndexService for the specified index if exists otherwise returns <code>null</code>. */ @Override @Nullable public IndexService indexService(Index index) { return indices.get(index.getUUID()); } /**
/** * Returns an IndexService for the specified index if exists otherwise a {@link IndexNotFoundException} is thrown. */ public IndexService indexServiceSafe(Index index) { IndexService indexService = indices.get(index.getUUID()); if (indexService == null) { throw new IndexNotFoundException(index); } assert indexService.indexUUID().equals(index.getUUID()) : "uuid mismatch local: " + indexService.indexUUID() + " incoming: " + index.getUUID(); return indexService; }
public ShardPath(boolean isCustomDataPath, Path dataPath, Path shardStatePath, ShardId shardId) { assert dataPath.getFileName().toString().equals(Integer.toString(shardId.id())) : "dataPath must end with the shard ID but didn't: " + dataPath.toString(); assert shardStatePath.getFileName().toString().equals(Integer.toString(shardId.id())) : "shardStatePath must end with the shard ID but didn't: " + dataPath.toString(); assert dataPath.getParent().getFileName().toString().equals(shardId.getIndex().getUUID()) : "dataPath must end with index path id but didn't: " + dataPath.toString(); assert shardStatePath.getParent().getFileName().toString().equals(shardId.getIndex().getUUID()) : "shardStatePath must end with index path id but didn't: " + dataPath.toString(); if (isCustomDataPath && dataPath.equals(shardStatePath)) { throw new IllegalArgumentException("shard state path must be different to the data path when using custom data paths"); } this.isCustomDataPath = isCustomDataPath; this.path = dataPath; this.shardId = shardId; this.shardStatePath = shardStatePath; }
private static Set<ShardId> findAllShardsForIndex(Path indexPath, Index index) throws IOException { assert indexPath.getFileName().toString().equals(index.getUUID()); Set<ShardId> shardIds = new HashSet<>(); if (Files.isDirectory(indexPath)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(indexPath)) { for (Path shardPath : stream) { String fileName = shardPath.getFileName().toString(); if (Files.isDirectory(shardPath) && fileName.chars().allMatch(Character::isDigit)) { int shardId = Integer.parseInt(fileName); ShardId id = new ShardId(index, shardId); shardIds.add(id); } } } } return shardIds; }
/** * Find all the shards for this index, returning a map of the {@code NodePath} to the number of shards on that path * @param index the index by which to filter shards * @return a map of NodePath to count of the shards for the index on that path * @throws IOException if an IOException occurs */ public Map<NodePath, Long> shardCountPerPath(final Index index) throws IOException { assert index != null; if (nodePaths == null || locks == null) { throw new IllegalStateException("node is not configured to store local location"); } assertEnvIsLocked(); final Map<NodePath, Long> shardCountPerPath = new HashMap<>(); final String indexUniquePathId = index.getUUID(); for (final NodePath nodePath : nodePaths) { Path indexLocation = nodePath.indicesPath.resolve(indexUniquePathId); if (Files.isDirectory(indexLocation)) { shardCountPerPath.put(nodePath, (long) findAllShardsForIndex(indexLocation, index).size()); } } return shardCountPerPath; }
/** * Cleans dangling indices if they are already allocated on the provided meta data. */ void cleanupAllocatedDangledIndices(MetaData metaData) { for (Index index : danglingIndices.keySet()) { final IndexMetaData indexMetaData = metaData.index(index); if (indexMetaData != null && indexMetaData.getIndex().getName().equals(index.getName())) { if (indexMetaData.getIndex().getUUID().equals(index.getUUID()) == false) { logger.warn("[{}] can not be imported as a dangling index, as there is already another index " + "with the same name but a different uuid. local index will be ignored (but not deleted)", index); } else { logger.debug("[{}] no longer dangling (created), removing from dangling list", index); } danglingIndices.remove(index); } } }
public IndexMetaData getSafe(Index index) { IndexMetaData indexMetaData = get(index.getName()); if (indexMetaData != null) { if(indexMetaData.getIndexUUID().equals(index.getUUID())) { return indexMetaData; } throw new IndexNotFoundException(index, new IllegalStateException("index uuid doesn't match expected: [" + index.getUUID() + "] but got: [" + indexMetaData.getIndexUUID() +"]")); } throw new IndexNotFoundException(index); }
public IndexMetaData index(Index index) { IndexMetaData metaData = index(index.getName()); if (metaData != null && metaData.getIndexUUID().equals(index.getUUID())) { return metaData; } return null; }
/** * Returns the {@link IndexMetaData} for this index. * @throws IndexNotFoundException if no metadata for this index is found */ public IndexMetaData getIndexSafe(Index index) { IndexMetaData metaData = index(index.getName()); if (metaData != null) { if(metaData.getIndexUUID().equals(index.getUUID())) { return metaData; } throw new IndexNotFoundException(index, new IllegalStateException("index uuid doesn't match expected: [" + index.getUUID() + "] but got: [" + metaData.getIndexUUID() +"]")); } throw new IndexNotFoundException(index); }
public void setIndex(Index index) { if (index != null) { addMetadata(INDEX_METADATA_KEY, index.getName()); addMetadata(INDEX_METADATA_KEY_UUID, index.getUUID()); } }
private Map<String, AliasFilter> buildPerIndexAliasFilter(SearchRequest request, ClusterState clusterState, Index[] concreteIndices, Map<String, AliasFilter> remoteAliasMap) { final Map<String, AliasFilter> aliasFilterMap = new HashMap<>(); for (Index index : concreteIndices) { clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.READ, index.getName()); AliasFilter aliasFilter = searchService.buildAliasFilter(clusterState, index.getName(), request.indices()); assert aliasFilter != null; aliasFilterMap.put(index.getUUID(), aliasFilter); } aliasFilterMap.putAll(remoteAliasMap); return aliasFilterMap; }
public final ShardSearchTransportRequest buildShardSearchRequest(SearchShardIterator shardIt) { String clusterAlias = shardIt.getClusterAlias(); AliasFilter filter = aliasFilter.get(shardIt.shardId().getIndex().getUUID()); assert filter != null; float indexBoost = concreteIndexBoosts.getOrDefault(shardIt.shardId().getIndex().getUUID(), DEFAULT_INDEX_BOOST); String indexName = shardIt.shardId().getIndex().getName(); final String[] routings = indexRoutings.getOrDefault(indexName, Collections.emptySet()) .toArray(new String[0]); return new ShardSearchTransportRequest(shardIt.getOriginalIndices(), request, shardIt.shardId(), getNumShards(), filter, indexBoost, timeProvider.getAbsoluteStartMillis(), clusterAlias, routings); }
private Map<String, Float> resolveIndexBoosts(SearchRequest searchRequest, ClusterState clusterState) { if (searchRequest.source() == null) { return Collections.emptyMap(); } SearchSourceBuilder source = searchRequest.source(); if (source.indexBoosts() == null) { return Collections.emptyMap(); } Map<String, Float> concreteIndexBoosts = new HashMap<>(); for (SearchSourceBuilder.IndexBoost ib : source.indexBoosts()) { Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, searchRequest.indicesOptions(), ib.getIndex()); for (Index concreteIndex : concreteIndices) { concreteIndexBoosts.putIfAbsent(concreteIndex.getUUID(), ib.getBoost()); } } return Collections.unmodifiableMap(concreteIndexBoosts); }
private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) { List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size()); String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID(); ClusterName clusterName = state.getClusterName(); for (ShardRouting shardRouting : indexShardRoutingTable) { assert shardRouting.started() : "expected started shard but was " + shardRouting; DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId()); requests.add(new Tuple<>(currentNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout))); } ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(), requests.size()); for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) { logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1()); transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler); } }
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache, BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis, String clusterAlias) { super(xContentRegistry, namedWriteableRegistry,client, nowInMillis); this.shardId = shardId; this.similarityService = similarityService; this.mapperService = mapperService; this.bitsetFilterCache = bitsetFilterCache; this.indexFieldDataService = indexFieldDataLookup; this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields(); this.nestedScope = new NestedScope(); this.scriptService = scriptService; this.indexSettings = indexSettings; this.reader = reader; this.clusterAlias = clusterAlias; this.fullyQualifiedIndex = new Index(RemoteClusterAware.buildRemoteIndexName(clusterAlias, indexSettings.getIndex().getName()), indexSettings.getIndex().getUUID()); }