/** * This method returns true if the current node is allowed to delete the given index. * This is the case if the index is deleted in the metadata or there is no allocation * on the local node and the index isn't on a shared file system. * @param index {@code Index} to check whether deletion is allowed * @param indexSettings {@code IndexSettings} for the given index * @return true if the index can be deleted on this node */ public boolean canDeleteIndexContents(Index index, IndexSettings indexSettings) { // index contents can be deleted if its an already closed index (so all its resources have // already been relinquished) final IndexService indexService = indexService(index); if (indexService == null && nodeEnv.hasNodeFile()) { return true; } return false; }
case NOOP: UpdateResponse update = result.action(); IndexService indexServiceOrNull = indicesService.indexService(shardId.getIndex()); if (indexServiceOrNull != null) { IndexShard shard = indexService.getShardOrNull(shardId.getId());
private IndexShard getShard(ShardActiveRequest request) { ClusterName thisClusterName = clusterService.getClusterName(); if (!thisClusterName.equals(request.clusterName)) { logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName); return null; } ShardId shardId = request.shardId; IndexService indexService = indicesService.indexService(shardId.getIndex()); if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) { return indexService.getShardOrNull(shardId.id()); } return null; }
IndexService indexService = indicesService.indexService(indexMetaData.getIndex()); if (indexService == null) {
/** * Clears the caches for the given shard id if the shard is still allocated on this node */ public void clearIndexShardCache(ShardId shardId, boolean queryCache, boolean fieldDataCache, boolean requestCache, String...fields) { final IndexService service = indexService(shardId.getIndex()); if (service != null) { IndexShard shard = service.getShardOrNull(shardId.id()); final boolean clearedAtLeastOne = service.clearCaches(queryCache, fieldDataCache, fields); if ((requestCache || (clearedAtLeastOne == false && fields.length == 0)) && shard != null) { indicesRequestCache.clear(new IndexShardCacheEntity(shard)); } } }
@Override public IndexShard createShard(ShardRouting shardRouting, RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, Consumer<IndexShard.ShardFailure> onShardFailure, Consumer<ShardId> globalCheckpointSyncer) throws IOException { ensureChangesAllowed(); IndexService indexService = indexService(shardRouting.index()); IndexShard indexShard = indexService.createShard(shardRouting, globalCheckpointSyncer); indexShard.addShardFailureCallback(onShardFailure); indexShard.startRecovery(recoveryState, recoveryTargetService, recoveryListener, repositoriesService, (type, mapping) -> { assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS: "mapping update consumer only required by local shards recovery"; client.admin().indices().preparePutMapping() .setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid .setType(type) .setSource(mapping.source().string(), XContentType.JSON) .get(); }, this); return indexShard; }
boolean exists = false; try { IndexService indexService = indicesService.indexService(shardId.getIndex()); if (indexService != null) { IndexShard indexShard = indexService.getShardOrNull(shardId.id());
/** * Returns <code>ShardDeletionCheckResult</code> signaling whether the shards content for the given shard can be deleted. * * @param shardId the shard to delete. * @param indexSettings the shards's relevant {@link IndexSettings}. This is required to access the indexes settings etc. */ public ShardDeletionCheckResult canDeleteShardContent(ShardId shardId, IndexSettings indexSettings) { assert shardId.getIndex().equals(indexSettings.getIndex()); final IndexService indexService = indexService(shardId.getIndex()); if (nodeEnv.hasNodeFile()) { final boolean isAllocated = indexService != null && indexService.hasShard(shardId.id()); if (isAllocated) { return ShardDeletionCheckResult.STILL_ALLOCATED; // we are allocated - can't delete the shard } else if (indexSettings.hasCustomDataPath()) { // lets see if it's on a custom path (return false if the shared doesn't exist) // we don't need to delete anything that is not there return Files.exists(nodeEnv.resolveCustomLocation(indexSettings, shardId)) ? ShardDeletionCheckResult.FOLDER_FOUND_CAN_DELETE : ShardDeletionCheckResult.NO_FOLDER_FOUND; } else { // lets see if it's path is available (return false if the shared doesn't exist) // we don't need to delete anything that is not there return FileSystemUtils.exists(nodeEnv.availableShardPaths(shardId)) ? ShardDeletionCheckResult.FOLDER_FOUND_CAN_DELETE : ShardDeletionCheckResult.NO_FOLDER_FOUND; } } else { return ShardDeletionCheckResult.NO_LOCAL_STORAGE; } }
final Index resizeSourceIndex = indexMetaData.getResizeSourceIndex(); final List<IndexShard> startedShards = new ArrayList<>(); final IndexService sourceIndexService = indicesService.indexService(resizeSourceIndex); final Set<ShardId> requiredShards; final int numShards;
/** * Deletes the index store trying to acquire all shards locks for this index. * This method will delete the metadata for the index even if the actual shards can't be locked. * * Package private for testing */ void deleteIndexStore(String reason, IndexMetaData metaData, ClusterState clusterState) throws IOException { if (nodeEnv.hasNodeFile()) { synchronized (this) { Index index = metaData.getIndex(); if (hasIndex(index)) { String localUUid = indexService(index).indexUUID(); throw new IllegalStateException("Can't delete index store for [" + index.getName() + "] - it's still part of the indices service [" + localUUid + "] [" + metaData.getIndexUUID() + "]"); } if (clusterState.metaData().hasIndex(index.getName()) && (clusterState.nodes().getLocalNode().isMasterNode() == true)) { // we do not delete the store if it is a master eligible node and the index is still in the cluster state // because we want to keep the meta data for indices around even if no shards are left here final IndexMetaData idxMeta = clusterState.metaData().index(index.getName()); throw new IllegalStateException("Can't delete index store for [" + index.getName() + "] - it's still part of the " + "cluster state [" + idxMeta.getIndexUUID() + "] [" + metaData.getIndexUUID() + "], " + "we are master eligible, so will keep the index metadata even if no shards are left."); } } final IndexSettings indexSettings = buildIndexSettings(metaData); deleteIndexStore(reason, indexSettings.getIndex(), indexSettings); } }
ShardId shardId = indexShardRoutingTable.shardId(); if (folderNotFoundCache.contains(shardId) == false && shardCanBeDeleted(localNodeId, indexShardRoutingTable)) { IndexService indexService = indicesService.indexService(indexRoutingTable.getIndex()); final IndexSettings indexSettings; if (indexService == null) {
IndexService indexService = indices.get(index.getIndex().getName()); if (indexService == null) { indexService = indicesService.indexService(index.getIndex()); if (indexService == null) {
/** * Returns an IndexService for the specified index if exists otherwise a {@link IndexNotFoundException} is thrown. */ public IndexService indexServiceSafe(String index) { IndexService indexService = indexService(index); if (indexService == null) { throw new IndexNotFoundException(index); } return indexService; }
private IndexShard getShard(ShardActiveRequest request) { ClusterName thisClusterName = clusterService.getClusterName(); if (!thisClusterName.equals(request.clusterName)) { logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName); return null; } ShardId shardId = request.shardId; IndexService indexService = indicesService.indexService(shardId.getIndex()); if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) { return indexService.getShardOrNull(shardId.id()); } return null; }
private IndexShard getShard(ShardActiveRequest request) { ClusterName thisClusterName = clusterService.getClusterName(); if (!thisClusterName.equals(request.clusterName)) { logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName); return null; } ShardId shardId = request.shardId; IndexService indexService = indicesService.indexService(shardId.getIndex()); if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) { return indexService.getShardOrNull(shardId.id()); } return null; }
private IndexShard getShard(ShardActiveRequest request) { ClusterName thisClusterName = clusterService.getClusterName(); if (!thisClusterName.equals(request.clusterName)) { logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName); return null; } ShardId shardId = request.shardId; IndexService indexService = indicesService.indexService(shardId.getIndex()); if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) { return indexService.getShardOrNull(shardId.id()); } return null; }
/** * Clears the caches for the given shard id if the shard is still allocated on this node */ public void clearIndexShardCache(ShardId shardId, boolean queryCache, boolean fieldDataCache, boolean requestCache, String...fields) { final IndexService service = indexService(shardId.getIndex()); if (service != null) { IndexShard shard = service.getShardOrNull(shardId.id()); final boolean clearedAtLeastOne = service.clearCaches(queryCache, fieldDataCache, fields); if ((requestCache || (clearedAtLeastOne == false && fields.length == 0)) && shard != null) { indicesRequestCache.clear(new IndexShardCacheEntity(shard)); } } }
private IndexShard getShard(ShardActiveRequest request) { ClusterName thisClusterName = clusterService.state().getClusterName(); if (!thisClusterName.equals(request.clusterName)) { logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName); return null; } ShardId shardId = request.shardId; IndexService indexService = indicesService.indexService(shardId.index().getName()); if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) { return indexService.shard(shardId.id()); } return null; } }
@Override public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard) { IndexService indexService = indicesService.indexService(shardId.index().name()); if (indexService != null) { ShardSuggestService suggestShardService = indexService.shardInjectorSafe(shardId.id()).getInstance(ShardSuggestService.class); suggestShardService.shutDown(); } } });
@Override protected ShardReconstructIndexResponse shardOperation(ShardReconstructIndexRequest request) throws ElasticsearchException { IndexService indexService = indicesService.indexService(request.index()); InternalIndexShard indexShard = (InternalIndexShard) indexService.shardSafe(request.shardId()); Engine.Searcher searcher = indexShard.engine().acquireSearcher("transport_reconstruct"); IndexReader reader = searcher.reader(); DocumentReconstructor dr = new DocumentReconstructor(reader); try { return new ShardReconstructIndexResponse(true, dr.reconstruct(request.shardId())); } catch (IOException e) { throw new ElasticsearchException("failed to reconstruct index", e); } }