- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<IndexService>
,LifecycleComponent
,Releasable
,IndexService.ShardStoreDeleter
,IndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
result type returned bysignaling different reasons why a shard can / cannot be deleted
Nested classes/interfaces inherited from interface org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices
IndicesClusterStateService.AllocatedIndices.IndexRemovalReason
-
Field Summary
FieldsFields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPendingDelete
(Index index, IndexSettings settings) Adds a pending delete for the given index.void
addPendingDelete
(ShardId shardId, IndexSettings settings) Adds a pending delete for the given index shard.boolean
boolean
awaitClose
(long timeout, TimeUnit timeUnit) Wait for thisIndicesService
to be effectively closed.buildAliasFilter
(ClusterState state, String index, Set<String> resolvedExpressions) static boolean
canCache
(ShardSearchRequest request, SearchContext context) Can the shard request be cached at all?boolean
canDeleteIndexContents
(Index index) This method returns true if the current node is allowed to delete the given index.canDeleteShardContent
(ShardId shardId, IndexSettings indexSettings) ReturnsShardDeletionCheckResult
signaling whether the shards content for the given shard can be deleted.void
clearIndexShardCache
(ShardId shardId, boolean queryCache, boolean fieldDataCache, boolean requestCache, String... fields) Clears the caches for the given shard id if the shard is still allocated on this nodecreateIndex
(IndexMetadata indexMetadata, List<IndexEventListener> builtInListeners, boolean writeDanglingIndices) Creates a newIndexService
for the given metadata.createIndexMapperServiceForValidation
(IndexMetadata indexMetadata) creates a new mapper service for the given index, in order to do administrative work like mapping updates.void
createShard
(ShardRouting shardRouting, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, Consumer<IndexShard.ShardFailure> onShardFailure, GlobalCheckpointSyncer globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, DiscoveryNode targetNode, DiscoveryNode sourceNode, long clusterStateVersion) Creates a shard for the specified shard routing and starts recovery.void
deleteShardStore
(String reason, ShardLock lock, IndexSettings indexSettings) Deletes the shard with an already acquired shard lock.void
deleteShardStore
(String reason, ShardId shardId, ClusterState clusterState) This method deletes the shard contents on disk for the given shard ID.void
deleteUnassignedIndex
(String reason, IndexMetadata oldIndexMetadata, ClusterState clusterState) Deletes an index that is not assigned to this node.protected void
doClose()
Close this component.protected void
doStart()
Start this component.protected void
doStop()
Stop this component.getCoordinatorRewriteContextProvider
(LongSupplier nowInMillis) getDataRewriteContext
(LongSupplier nowInMillis) Returns a function which given an index name, returns a predicate which fields must match in order to be returned by get mappings, get index, get field mappings and field capabilities API.getRewriteContext
(LongSupplier nowInMillis, ResolvedIndices resolvedIndices) Returns a newQueryRewriteContext
with the givennow
providergetTimestampFieldType
(Index index) boolean
boolean
Checks if all pending deletes have completed.indexService
(Index index) Returns an IndexService for the specified index if exists otherwise returnsnull
.indexServiceSafe
(Index index) Returns an IndexService for the specified index if exists otherwise aIndexNotFoundException
is thrown.iterator()
void
loadIntoContext
(ShardSearchRequest request, SearchContext context) Loads the cache result, computing it if needed by executing the query phase and otherwise deserializing the cached value into thecontext's query result
.void
processPendingDeletes
(Index index, IndexSettings indexSettings, TimeValue timeout) Processes all pending deletes for the given index.void
removeIndex
(Index index, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason, String extraInfo) Removes the given index from this service and releases all associated resources.stats
(CommonStatsFlags flags, boolean includeShardsStats) verifyIndexIsDeleted
(Index index, ClusterState clusterState) Verify that the contents on disk for the given index is deleted; if not, delete the contents.void
verifyIndexMetadata
(IndexMetadata metadata, IndexMetadata metadataUpdate) This method verifies that the givenmetadata
holds sane values to create anIndexService
.<T,
E extends Exception>
TwithTempIndexService
(IndexMetadata indexMetadata, CheckedFunction<IndexService, T, E> indexServiceConsumer) Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices
getShardOrNull
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
INDICES_SHARDS_CLOSED_TIMEOUT
- See Also:
-
INDICES_CACHE_CLEAN_INTERVAL_SETTING
-
INDICES_ID_FIELD_DATA_ENABLED_SETTING
-
WRITE_DANGLING_INDICES_INFO_SETTING
-
-
Method Details
-
doStart
protected void doStart()Description copied from class:AbstractLifecycleComponent
Start this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.
This method is called while synchronized on
AbstractLifecycleComponent.lifecycle
. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.- Specified by:
doStart
in classAbstractLifecycleComponent
-
clusterService
-
doStop
protected void doStop()Description copied from class:AbstractLifecycleComponent
Stop this component. Typically that means doing the reverse of whateverAbstractLifecycleComponent.doStart()
does.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle
. It is only called once in the lifetime of a component, after callingAbstractLifecycleComponent.doStart()
, although it will not be called at all if this component did not successfully start.- Specified by:
doStop
in classAbstractLifecycleComponent
-
doClose
Description copied from class:AbstractLifecycleComponent
Close this component. Typically that means doing the reverse of whatever happened during initialization, such as releasing resources acquired there.This method is called while synchronized on
AbstractLifecycleComponent.lifecycle
. It is called once in the lifetime of a component. If the component was started then it will be stopped before it is closed, and once it is closed it will not be started or stopped.- Specified by:
doClose
in classAbstractLifecycleComponent
- Throws:
IOException
-
awaitClose
Wait for thisIndicesService
to be effectively closed. When this returnstrue
, all shards and shard stores are closed and all shardclosed listeners
have run. However someshard closed listeners
might not have run.- Returns:
- true if all shards closed within the given timeout, false otherwise
- Throws:
InterruptedException
- if the current thread got interrupted while waiting for shards to close
-
stats
-
iterator
- Specified by:
iterator
in interfaceIterable<IndexService>
-
hasIndex
-
indexService
Returns an IndexService for the specified index if exists otherwise returnsnull
.- Specified by:
indexService
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService>
-
indexServiceSafe
Returns an IndexService for the specified index if exists otherwise aIndexNotFoundException
is thrown. -
createIndex
public IndexService createIndex(IndexMetadata indexMetadata, List<IndexEventListener> builtInListeners, boolean writeDanglingIndices) throws IOException Creates a newIndexService
for the given metadata.- Specified by:
createIndex
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService> - Parameters:
indexMetadata
- the index metadata to create the index forbuiltInListeners
- a list of built-in lifecycleIndexEventListener
that should be used alongside with the per-index listenerswriteDanglingIndices
- whether dangling indices information should be written- Throws:
ResourceAlreadyExistsException
- if the index already exists.IOException
-
withTempIndexService
public <T,E extends Exception> T withTempIndexService(IndexMetadata indexMetadata, CheckedFunction<IndexService, T, throws IOException, EE> indexServiceConsumer) - Throws:
IOException
E extends Exception
-
createIndexMapperServiceForValidation
public MapperService createIndexMapperServiceForValidation(IndexMetadata indexMetadata) throws IOException creates a new mapper service for the given index, in order to do administrative work like mapping updates. This *should not* be used for document parsing. Doing so will result in an exception. Note: the returnedMapperService
should be closed when unneeded.- Throws:
IOException
-
verifyIndexMetadata
public void verifyIndexMetadata(IndexMetadata metadata, IndexMetadata metadataUpdate) throws IOException This method verifies that the givenmetadata
holds sane values to create anIndexService
. This method tries to update the meta data of the createdIndexService
if the givenmetadataUpdate
is different from the givenmetadata
. This method will throw an exception if the creation or the update fails. The createdIndexService
will not be registered and will be closed immediately.- Throws:
IOException
-
createShard
public void createShard(ShardRouting shardRouting, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, Consumer<IndexShard.ShardFailure> onShardFailure, GlobalCheckpointSyncer globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, DiscoveryNode targetNode, DiscoveryNode sourceNode, long clusterStateVersion) throws IOException Description copied from interface:IndicesClusterStateService.AllocatedIndices
Creates a shard for the specified shard routing and starts recovery.- Specified by:
createShard
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService> - Parameters:
shardRouting
- the shard routingrecoveryTargetService
- recovery service for the targetrecoveryListener
- a callback when recovery changes state (finishes or fails)repositoriesService
- service responsible for snapshot/restoreonShardFailure
- a callback when this shard failsglobalCheckpointSyncer
- a callback when this shard syncs the global checkpointretentionLeaseSyncer
- a callback when this shard syncs retention leasestargetNode
- the node where this shard will be recoveredsourceNode
- the source node to recover this shard from (it might be null)clusterStateVersion
- the cluster state version in which the shard was created- Throws:
IOException
- if an I/O exception occurs when creating the shard
-
removeIndex
public void removeIndex(Index index, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason, String extraInfo) Description copied from interface:IndicesClusterStateService.AllocatedIndices
Removes the given index from this service and releases all associated resources. Persistent parts of the index like the shards files, state and transaction logs are kept around in the case of a disaster recovery.- Specified by:
removeIndex
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService> - Parameters:
index
- the index to removereason
- the reason to remove the indexextraInfo
- extra information that will be used for logging and reporting
-
getIndicesFieldDataCache
-
getCircuitBreakerService
-
getIndicesQueryCache
-
deleteUnassignedIndex
public void deleteUnassignedIndex(String reason, IndexMetadata oldIndexMetadata, ClusterState clusterState) Deletes an index that is not assigned to this node. This method cleans up all disk folders relating to the index but does not deal with in-memory structures. For those callremoveIndex(Index, IndexRemovalReason, String)
- Specified by:
deleteUnassignedIndex
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService>
-
deleteShardStore
public void deleteShardStore(String reason, ShardLock lock, IndexSettings indexSettings) throws IOException Deletes the shard with an already acquired shard lock.- Specified by:
deleteShardStore
in interfaceIndexService.ShardStoreDeleter
- Parameters:
reason
- the reason for the shard deletionlock
- the lock of the shard to deleteindexSettings
- the shards index settings.- Throws:
IOException
- if an IOException occurs
-
deleteShardStore
public void deleteShardStore(String reason, ShardId shardId, ClusterState clusterState) throws IOException, ShardLockObtainFailedException This method deletes the shard contents on disk for the given shard ID. This method will fail if the shard deleting is prevented bycanDeleteShardContent(ShardId, IndexSettings)
of if the shards lock can not be acquired. On data nodes, if the deleted shard is the last shard folder in its index, the method will attempt to remove the index folder as well.- Parameters:
reason
- the reason for the shard deletionshardId
- the shards ID to deleteclusterState
- . This is required to access the indexes settings etc.- Throws:
IOException
- if an IOException occursShardLockObtainFailedException
-
canDeleteIndexContents
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.- Parameters:
index
-Index
to check whether deletion is allowed- Returns:
- true if the index can be deleted on this node
-
verifyIndexIsDeleted
Verify that the contents on disk for the given index is deleted; if not, delete the contents. This method assumes that an index is already deleted in the cluster state and/or explicitly through index tombstones.- Specified by:
verifyIndexIsDeleted
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService> - Parameters:
index
-Index
to make sure its deleted from diskclusterState
-ClusterState
to ensure the index is not part of it- Returns:
- IndexMetadata for the index loaded from disk
-
canDeleteShardContent
public IndicesService.ShardDeletionCheckResult canDeleteShardContent(ShardId shardId, IndexSettings indexSettings) ReturnsShardDeletionCheckResult
signaling whether the shards content for the given shard can be deleted.- Parameters:
shardId
- the shard to delete.indexSettings
- the shards's relevantIndexSettings
. This is required to access the indexes settings etc.
-
addPendingDelete
Adds a pending delete for the given index shard.- Specified by:
addPendingDelete
in interfaceIndexService.ShardStoreDeleter
-
addPendingDelete
Adds a pending delete for the given index. -
processPendingDeletes
public void processPendingDeletes(Index index, IndexSettings indexSettings, TimeValue timeout) throws IOException, InterruptedException, ShardLockObtainFailedException Processes all pending deletes for the given index. This method will acquire all locks for the given index and will process all pending deletes for this index. Pending deletes might occur if the OS doesn't allow deletion of files because they are used by a different process ie. on Windows where files might still be open by a virus scanner. On a shared filesystem a replica might not have been closed when the primary is deleted causing problems on delete calls so we schedule there deletes later.- Specified by:
processPendingDeletes
in interfaceIndicesClusterStateService.AllocatedIndices<IndexShard,
IndexService> - Parameters:
index
- the index to process the pending deletes fortimeout
- the timeout used for processing pending deletes- Throws:
IOException
InterruptedException
ShardLockObtainFailedException
-
hasUncompletedPendingDeletes
public boolean hasUncompletedPendingDeletes()Checks if all pending deletes have completed. Used by tests to ensure we don't check directory contents while deletion still ongoing. * The reason is that, on Windows, browsing the directory contents can interfere with the deletion process and delay it unnecessarily. -
getAnalysis
-
canCache
Can the shard request be cached at all? -
loadIntoContext
Loads the cache result, computing it if needed by executing the query phase and otherwise deserializing the cached value into thecontext's query result
. The combination of load + compute allows to have a single load operation that will cause other requests with the same key to wait till its loaded an reuse the same cache.- Throws:
Exception
-
getTotalIndexingBufferBytes
-
buildAliasFilter
public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String> resolvedExpressions) -
getRewriteContext
public QueryRewriteContext getRewriteContext(LongSupplier nowInMillis, ResolvedIndices resolvedIndices) Returns a newQueryRewriteContext
with the givennow
provider -
getDataRewriteContext
-
getCoordinatorRewriteContextProvider
public CoordinatorRewriteContextProvider getCoordinatorRewriteContextProvider(LongSupplier nowInMillis) -
clearIndexShardCache
public void clearIndexShardCache(ShardId shardId, boolean queryCache, boolean fieldDataCache, boolean requestCache, String... fields) Clears the caches for the given shard id if the shard is still allocated on this node -
getFieldFilter
Returns a function which given an index name, returns a predicate which fields must match in order to be returned by get mappings, get index, get field mappings and field capabilities API. Useful to filter the fields that such API return. The predicate receives the field name as input argument. In case multiple plugins register a field filter throughMapperPlugin.getFieldFilter()
, only fields that match all the registered filters will be returned by get mappings, get index, get field mappings and field capabilities API. -
allPendingDanglingIndicesWritten
public boolean allPendingDanglingIndicesWritten() -
getTimestampFieldType
- Returns:
- the field type of the
@timestamp
field of the given index, ornull
if: - the index is not found, - the field is not found, or - the field is not a timestamp field.
-
getIndexScopedSettings
-
getBigArrays
-