public class IndexShard extends AbstractIndexShardComponent implements IndicesClusterStateService.Shard
Modifier and Type | Class and Description |
---|---|
static class |
IndexShard.ShardFailure
Simple struct encapsulating a shard failure
|
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.atomic.AtomicReference<Engine> |
currentEngineReference |
protected EngineFactory |
engineFactory |
protected long |
primaryTerm |
protected ShardRouting |
shardRouting |
protected IndexShardState |
state |
static java.util.EnumSet<IndexShardState> |
writeAllowedStatesForPrimary |
deprecationLogger, indexSettings, logger, shardId
Constructor and Description |
---|
IndexShard(ShardRouting shardRouting,
IndexSettings indexSettings,
ShardPath path,
Store store,
IndexCache indexCache,
MapperService mapperService,
SimilarityService similarityService,
IndexFieldDataService indexFieldDataService,
EngineFactory engineFactory,
IndexEventListener indexEventListener,
IndexSearcherWrapper indexSearcherWrapper,
ThreadPool threadPool,
BigArrays bigArrays,
Engine.Warmer warmer,
java.util.List<SearchOperationListener> searchOperationListener,
java.util.List<IndexingOperationListener> listeners) |
Modifier and Type | Method and Description |
---|---|
org.apache.lucene.index.IndexCommit |
acquireIndexCommit(boolean flushFirst)
Creates a new
IndexCommit snapshot form the currently running engine. |
void |
acquirePrimaryOperationLock(ActionListener<Releasable> onLockAcquired,
java.lang.String executorOnDelay)
Acquire a primary operation lock whenever the shard is ready for indexing.
|
void |
acquireReplicaOperationLock(long opPrimaryTerm,
ActionListener<Releasable> onLockAcquired,
java.lang.String executorOnDelay)
Acquire a replica operation lock whenever the shard is ready for indexing (see acquirePrimaryOperationLock).
|
Engine.Searcher |
acquireSearcher(java.lang.String source) |
Translog.View |
acquireTranslogView() |
void |
activateThrottling() |
void |
addRefreshListener(Translog.Location location,
java.util.function.Consumer<java.lang.Boolean> listener)
Add a listener for refreshes.
|
void |
addShardFailureCallback(java.util.function.Consumer<IndexShard.ShardFailure> onShardFailure) |
protected RefreshListeners |
buildRefreshListeners()
Build RefreshListeners for this shard.
|
boolean |
canIndex()
returns true if this shard supports indexing (i.e., write) operations.
|
void |
checkIdle(long inactiveTimeNS)
Called by
IndexingMemoryController to check whether more than inactiveTimeNS has passed since the last
indexing operation, and notify listeners that we are now inactive so e.g. |
void |
close(java.lang.String reason,
boolean flushEngine) |
CommitStats |
commitStats() |
CompletionStats |
completionStats(java.lang.String... fields) |
void |
deactivateThrottling() |
Engine.DeleteResult |
delete(Engine.Delete delete) |
DocsStats |
docStats() |
void |
failShard(java.lang.String reason,
java.lang.Exception e)
Fails the shard and marks the shard store as corrupted if
e is caused by index corruption |
ShardFieldData |
fieldData() |
FieldDataStats |
fieldDataStats(java.lang.String... fields) |
void |
finalizeRecovery()
perform the last stages of recovery once all translog operations are done.
|
Engine.CommitId |
flush(FlushRequest request) |
void |
flushAndCloseEngine() |
FlushStats |
flushStats() |
void |
forceMerge(ForceMergeRequest forceMerge) |
Engine.GetResult |
get(Engine.Get get) |
int |
getActiveOperationsCount() |
protected Engine |
getEngineOrNull()
NOTE: returns null if engine is not yet started (e.g.
|
long |
getIndexBufferRAMBytesUsed()
Returns number of heap bytes used by the indexing buffer for this shard, or 0 if the shard is closed
|
IndexEventListener |
getIndexEventListener() |
long |
getPrimaryTerm()
Returns the primary term the index shard is on.
|
org.apache.lucene.search.QueryCachingPolicy |
getQueryCachingPolicy() |
SearchOperationListener |
getSearchOperationListener() |
ShardGetService |
getService() |
GetStats |
getStats() |
Translog |
getTranslog() |
Translog.Durability |
getTranslogDurability()
Returns the current translog durability mode
|
long |
getWritingBytes()
Returns how many bytes we are currently moving from heap to disk
|
boolean |
ignoreRecoveryAttempt()
Returns true if this shard can ignore a recovery attempt made to it (since the already doing/done it)
|
Engine.IndexResult |
index(Engine.Index index) |
IndexFieldDataService |
indexFieldDataService() |
IndexingStats |
indexingStats(java.lang.String... types) |
boolean |
isActive() |
boolean |
isRefreshNeeded()
Returns
true iff one or more changes to the engine are not visible to via the current searcher *or* there are pending
refresh listeners. |
MapperService |
mapperService() |
IndexShardState |
markAsRecovering(java.lang.String reason,
RecoveryState recoveryState)
Marks the shard as recovering based on a recovery state, fails with exception is recovering is not allowed to be set.
|
boolean |
maybeFlush()
Schedules a flush if needed but won't schedule more than one flush concurrently.
|
MergeStats |
mergeStats() |
org.apache.lucene.util.Version |
minimumCompatibleVersion() |
protected Engine |
newEngine(EngineConfig config) |
void |
noopUpdate(java.lang.String type)
Should be called for each no-op update operation to increment relevant statistics.
|
protected void |
onNewEngine(Engine newEngine) |
void |
onSettingsChanged() |
int |
performBatchRecovery(java.lang.Iterable<Translog.Operation> operations)
Applies all operations in the iterable to the current engine and returns the number of operations applied.
|
void |
performRecoveryRestart()
called if recovery has to be restarted after network error / delay **
|
void |
performTranslogRecovery(boolean indexExists)
After the store has been recovered, we need to start the engine in order to apply operations
|
IndexShard |
postRecovery(java.lang.String reason) |
Engine.Delete |
prepareDeleteOnPrimary(java.lang.String type,
java.lang.String id,
long version,
VersionType versionType) |
Engine.Delete |
prepareDeleteOnReplica(java.lang.String type,
java.lang.String id,
long version,
VersionType versionType) |
void |
prepareForIndexRecovery()
called before starting to copy index files over
|
Engine.Index |
prepareIndexOnPrimary(SourceToParse source,
long version,
VersionType versionType,
long autoGeneratedIdTimestamp,
boolean isRetry) |
Engine.Index |
prepareIndexOnReplica(SourceToParse source,
long version,
VersionType versionType,
long autoGeneratedIdTimestamp,
boolean isRetry) |
void |
readAllowed() |
boolean |
recoverFromLocalShards(java.util.function.BiConsumer<java.lang.String,MappingMetaData> mappingUpdateConsumer,
java.util.List<IndexShard> localShards) |
boolean |
recoverFromStore() |
RecoveryState |
recoveryState()
Returns the current
RecoveryState if this shard is recovering or has been recovering. |
RecoveryStats |
recoveryStats()
returns stats about ongoing recoveries, both source and target
|
void |
refresh(java.lang.String source)
Writes all indexing changes to disk and opens a new searcher reflecting all changes.
|
RefreshStats |
refreshStats() |
void |
releaseIndexCommit(org.apache.lucene.index.IndexCommit snapshot)
Releases a snapshot taken from
acquireIndexCommit(boolean) this must be called to release the resources
referenced by the given snapshot IndexCommit . |
void |
relocated(java.lang.String reason) |
ShardRequestCache |
requestCache() |
boolean |
restoreFromRepository(Repository repository) |
ShardRouting |
routingEntry()
Returns the latest cluster routing entry received with this shard.
|
SearchStats |
searchStats(java.lang.String... groups) |
java.util.List<Segment> |
segments(boolean verbose) |
SegmentsStats |
segmentStats(boolean includeSegmentFileSizes) |
ShardBitsetFilterCache |
shardBitsetFilterCache() |
ShardPath |
shardPath() |
void |
skipTranslogRecovery(long maxUnsafeAutoIdTimestamp)
After the store has been recovered, we need to start the engine.
|
Store.MetadataSnapshot |
snapshotStoreMetadata()
gets a
Store.MetadataSnapshot for the current directory. |
void |
startRecovery(RecoveryState recoveryState,
PeerRecoveryTargetService recoveryTargetService,
PeerRecoveryTargetService.RecoveryListener recoveryListener,
RepositoriesService repositoriesService,
java.util.function.BiConsumer<java.lang.String,MappingMetaData> mappingUpdateConsumer,
IndicesService indicesService) |
IndexShardState |
state()
Returns the latest internal shard state.
|
Store |
store() |
StoreStats |
storeStats() |
void |
sync(Translog.Location location,
java.util.function.Consumer<java.lang.Exception> syncListener)
Syncs the given location with the underlying storage unless already synced.
|
Engine.SyncedFlushResult |
syncFlush(java.lang.String syncId,
Engine.CommitId expectedCommitId) |
TranslogStats |
translogStats() |
void |
updatePrimaryTerm(long newTerm)
notifies the shard of an increase in the primary term
|
void |
updateRoutingEntry(ShardRouting newRouting)
Updates the shards routing entry.
|
org.apache.lucene.util.Version |
upgrade(UpgradeRequest upgrade)
Upgrades the shard to the current version of Lucene and returns the minimum segment version
|
protected void |
verifyActive() |
ShardIndexWarmerService |
warmerService() |
WarmerStats |
warmerStats() |
void |
writeIndexingBuffer()
Called when our shard is using too much heap and should move buffered indexed/deleted documents to disk.
|
indexSettings, nodeName, shardId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
shardId
protected volatile ShardRouting shardRouting
protected volatile IndexShardState state
protected volatile long primaryTerm
protected final java.util.concurrent.atomic.AtomicReference<Engine> currentEngineReference
protected final EngineFactory engineFactory
public static final java.util.EnumSet<IndexShardState> writeAllowedStatesForPrimary
public IndexShard(ShardRouting shardRouting, IndexSettings indexSettings, ShardPath path, Store store, IndexCache indexCache, MapperService mapperService, SimilarityService similarityService, IndexFieldDataService indexFieldDataService, @Nullable EngineFactory engineFactory, IndexEventListener indexEventListener, IndexSearcherWrapper indexSearcherWrapper, ThreadPool threadPool, BigArrays bigArrays, Engine.Warmer warmer, java.util.List<SearchOperationListener> searchOperationListener, java.util.List<IndexingOperationListener> listeners) throws java.io.IOException
java.io.IOException
public Store store()
public boolean canIndex()
public ShardGetService getService()
public ShardBitsetFilterCache shardBitsetFilterCache()
public IndexFieldDataService indexFieldDataService()
public MapperService mapperService()
public SearchOperationListener getSearchOperationListener()
public ShardIndexWarmerService warmerService()
public ShardRequestCache requestCache()
public ShardFieldData fieldData()
public long getPrimaryTerm()
IndexMetaData.primaryTerm(int)
public void updatePrimaryTerm(long newTerm)
public ShardRouting routingEntry()
routingEntry
in interface IndicesClusterStateService.Shard
public org.apache.lucene.search.QueryCachingPolicy getQueryCachingPolicy()
public void updateRoutingEntry(ShardRouting newRouting) throws java.io.IOException
updateRoutingEntry
in interface IndicesClusterStateService.Shard
IndexShardRelocatedException
- if shard is marked as relocated and relocation abortedjava.io.IOException
- if shard state could not be persistedpublic IndexShardState markAsRecovering(java.lang.String reason, RecoveryState recoveryState) throws IndexShardStartedException, IndexShardRelocatedException, IndexShardRecoveringException, IndexShardClosedException
public void relocated(java.lang.String reason) throws IllegalIndexShardStateException, java.lang.InterruptedException
IllegalIndexShardStateException
java.lang.InterruptedException
public IndexShardState state()
IndicesClusterStateService.Shard
state
in interface IndicesClusterStateService.Shard
public Engine.Index prepareIndexOnPrimary(SourceToParse source, long version, VersionType versionType, long autoGeneratedIdTimestamp, boolean isRetry)
public Engine.Index prepareIndexOnReplica(SourceToParse source, long version, VersionType versionType, long autoGeneratedIdTimestamp, boolean isRetry)
public Engine.IndexResult index(Engine.Index index) throws java.io.IOException
java.io.IOException
public Engine.Delete prepareDeleteOnPrimary(java.lang.String type, java.lang.String id, long version, VersionType versionType)
public Engine.Delete prepareDeleteOnReplica(java.lang.String type, java.lang.String id, long version, VersionType versionType)
public Engine.DeleteResult delete(Engine.Delete delete) throws java.io.IOException
java.io.IOException
public Engine.GetResult get(Engine.Get get)
public void refresh(java.lang.String source)
AlreadyClosedException
.public long getWritingBytes()
public RefreshStats refreshStats()
public FlushStats flushStats()
public DocsStats docStats()
@Nullable public CommitStats commitStats()
CommitStats
if engine is open, otherwise nullpublic IndexingStats indexingStats(java.lang.String... types)
public SearchStats searchStats(java.lang.String... groups)
public GetStats getStats()
public StoreStats storeStats()
public MergeStats mergeStats()
public SegmentsStats segmentStats(boolean includeSegmentFileSizes)
public WarmerStats warmerStats()
public FieldDataStats fieldDataStats(java.lang.String... fields)
public TranslogStats translogStats()
public CompletionStats completionStats(java.lang.String... fields)
public Engine.SyncedFlushResult syncFlush(java.lang.String syncId, Engine.CommitId expectedCommitId)
public Engine.CommitId flush(FlushRequest request) throws ElasticsearchException
ElasticsearchException
public void forceMerge(ForceMergeRequest forceMerge) throws java.io.IOException
java.io.IOException
public org.apache.lucene.util.Version upgrade(UpgradeRequest upgrade) throws java.io.IOException
java.io.IOException
public org.apache.lucene.util.Version minimumCompatibleVersion()
public org.apache.lucene.index.IndexCommit acquireIndexCommit(boolean flushFirst) throws EngineException
IndexCommit
snapshot form the currently running engine. All resources referenced by this
commit won't be freed until the commit / snapshot is released via releaseIndexCommit(IndexCommit)
.flushFirst
- true
if the index should first be flushed to disk / a low level lucene commit should be executedEngineException
public void releaseIndexCommit(org.apache.lucene.index.IndexCommit snapshot) throws java.io.IOException
acquireIndexCommit(boolean)
this must be called to release the resources
referenced by the given snapshot IndexCommit
.java.io.IOException
public Store.MetadataSnapshot snapshotStoreMetadata() throws java.io.IOException
Store.MetadataSnapshot
for the current directory. This method is safe to call in all lifecycle of the index shard,
without having to worry about the current state of the engine and concurrent flushes.org.apache.lucene.index.IndexNotFoundException
- if no index is found in the current directoryorg.apache.lucene.index.CorruptIndexException
- if the lucene index is corrupted. This can be caused by a checksum
mismatch or an unexpected exception when opening the index reading the
segments file.org.apache.lucene.index.IndexFormatTooOldException
- if the lucene index is too old to be opened.org.apache.lucene.index.IndexFormatTooNewException
- if the lucene index is too new to be opened.java.io.FileNotFoundException
- if one or more files referenced by a commit are not present.java.nio.file.NoSuchFileException
- if one or more files referenced by a commit are not present.java.io.IOException
public void failShard(java.lang.String reason, @Nullable java.lang.Exception e)
e
is caused by index corruptionpublic Engine.Searcher acquireSearcher(java.lang.String source)
public void close(java.lang.String reason, boolean flushEngine) throws java.io.IOException
java.io.IOException
public IndexShard postRecovery(java.lang.String reason) throws IndexShardStartedException, IndexShardRelocatedException, IndexShardClosedException
public void prepareForIndexRecovery()
public int performBatchRecovery(java.lang.Iterable<Translog.Operation> operations)
public void performTranslogRecovery(boolean indexExists) throws java.io.IOException
java.io.IOException
protected void onNewEngine(Engine newEngine)
public void skipTranslogRecovery(long maxUnsafeAutoIdTimestamp) throws java.io.IOException
java.io.IOException
public void performRecoveryRestart() throws java.io.IOException
java.io.IOException
public RecoveryStats recoveryStats()
public RecoveryState recoveryState()
RecoveryState
if this shard is recovering or has been recovering.
Returns null if the recovery has not yet started or shard was not recovered (created via an API).recoveryState
in interface IndicesClusterStateService.Shard
public void finalizeRecovery()
postRecovery(String)
.public boolean ignoreRecoveryAttempt()
public void readAllowed() throws IllegalIndexShardStateException
IllegalIndexShardStateException
protected final void verifyActive() throws IllegalIndexShardStateException
IllegalIndexShardStateException
public long getIndexBufferRAMBytesUsed()
public void addShardFailureCallback(java.util.function.Consumer<IndexShard.ShardFailure> onShardFailure)
public void checkIdle(long inactiveTimeNS)
IndexingMemoryController
to check whether more than inactiveTimeNS
has passed since the last
indexing operation, and notify listeners that we are now inactive so e.g. sync'd flush can happen.public boolean isActive()
public ShardPath shardPath()
public boolean recoverFromLocalShards(java.util.function.BiConsumer<java.lang.String,MappingMetaData> mappingUpdateConsumer, java.util.List<IndexShard> localShards) throws java.io.IOException
java.io.IOException
public boolean recoverFromStore()
public boolean restoreFromRepository(Repository repository)
public void onSettingsChanged()
public Translog.View acquireTranslogView()
public java.util.List<Segment> segments(boolean verbose)
public void flushAndCloseEngine() throws java.io.IOException
java.io.IOException
public Translog getTranslog()
public IndexEventListener getIndexEventListener()
public void activateThrottling()
public void deactivateThrottling()
public void writeIndexingBuffer()
public void noopUpdate(java.lang.String type)
type
- the doc type of the updateprotected Engine getEngineOrNull()
public void startRecovery(RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, java.util.function.BiConsumer<java.lang.String,MappingMetaData> mappingUpdateConsumer, IndicesService indicesService)
protected Engine newEngine(EngineConfig config)
public void acquirePrimaryOperationLock(ActionListener<Releasable> onLockAcquired, java.lang.String executorOnDelay)
public void acquireReplicaOperationLock(long opPrimaryTerm, ActionListener<Releasable> onLockAcquired, java.lang.String executorOnDelay)
shardRouting
an IllegalArgumentException
is thrown.public int getActiveOperationsCount()
public final void sync(Translog.Location location, java.util.function.Consumer<java.lang.Exception> syncListener)
public Translog.Durability getTranslogDurability()
public boolean maybeFlush()
true
if a new flush is scheduled otherwise false
.protected RefreshListeners buildRefreshListeners()
public boolean isRefreshNeeded()
true
iff one or more changes to the engine are not visible to via the current searcher *or* there are pending
refresh listeners.
Otherwise false
.org.apache.lucene.store.AlreadyClosedException
- if the engine or internal indexwriter in the engine is already closedpublic void addRefreshListener(Translog.Location location, java.util.function.Consumer<java.lang.Boolean> listener)
location
- the location to listen forlistener
- for the refresh. Called with true if registering the listener ran it out of slots and forced a refresh. Called with
false otherwise.