Package org.elasticsearch.index.shard
Class IndexShardTestCase
- java.lang.Object
-
- org.junit.Assert
-
- org.apache.lucene.util.LuceneTestCase
-
- org.elasticsearch.test.ESTestCase
-
- org.elasticsearch.index.shard.IndexShardTestCase
-
- Direct Known Subclasses:
ESIndexLevelReplicationTestCase
public abstract class IndexShardTestCase extends ESTestCase
A base class for unit tests that need to create and shutdownIndexShard
instances easily, containing utilities for shard creation and recoveries. See {newShard(boolean)
} andnewStartedShard()
for a good starting points
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.test.ESTestCase
ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis
-
Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase
org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Monster, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.util.LuceneTestCase.SuppressFsync, org.apache.lucene.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.util.LuceneTestCase.Weekly
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.concurrent.atomic.AtomicLong
currentClusterStateVersion
static IndexEventListener
EMPTY_EVENT_LISTENER
protected long
primaryTerm
protected static PeerRecoveryTargetService.RecoveryListener
recoveryListener
protected ThreadPool
threadPool
-
Fields inherited from class org.elasticsearch.test.ESTestCase
checkIndexFailed, failureAndSuccessEvents, JAVA_TIMEZONE_IDS, JAVA_ZONE_IDS, JODA_TIMEZONE_IDS, logger
-
Fields inherited from class org.apache.lucene.util.LuceneTestCase
assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_BADAPPLES, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
-
-
Constructor Summary
Constructors Constructor Description IndexShardTestCase()
-
Method Summary
Modifier and Type Method Description protected void
allowShardFailures()
by default, tests will fail if any shard created by this class fails.static void
assertConsistentHistoryBetweenTranslogAndLucene(IndexShard shard)
protected void
assertDocCount(IndexShard shard, int docDount)
protected void
assertDocs(IndexShard shard, java.lang.String... ids)
protected void
closeShard(IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene)
protected void
closeShards(java.lang.Iterable<IndexShard> shards)
protected void
closeShards(IndexShard... shards)
protected Store
createStore(IndexSettings indexSettings, ShardPath shardPath)
protected Store
createStore(ShardId shardId, IndexSettings indexSettings, org.apache.lucene.store.Directory directory)
protected Engine.DeleteResult
deleteDoc(IndexShard shard, java.lang.String type, java.lang.String id)
protected void
failOnShardFailures()
protected void
flushShard(IndexShard shard)
protected void
flushShard(IndexShard shard, boolean force)
static java.util.List<DocIdSeqNoAndTerm>
getDocIdAndSeqNos(IndexShard shard)
static Engine
getEngine(IndexShard indexShard)
Helper method to access (package-protected) engine from testsprotected DiscoveryNode
getFakeDiscoNode(java.lang.String id)
static ReplicationTracker
getReplicationTracker(IndexShard indexShard)
static java.util.Set<java.lang.String>
getShardDocUIDs(IndexShard shard)
static Translog
getTranslog(IndexShard shard)
protected Engine.IndexResult
indexDoc(IndexShard shard, java.lang.String type, java.lang.String id)
protected Engine.IndexResult
indexDoc(IndexShard shard, java.lang.String type, java.lang.String id, java.lang.String source)
protected Engine.IndexResult
indexDoc(IndexShard shard, java.lang.String type, java.lang.String id, java.lang.String source, XContentType xContentType, java.lang.String routing)
protected IndexShard
newShard(boolean primary)
Creates a new initializing shard.protected IndexShard
newShard(boolean primary, Settings settings)
Creates a new initializing shard.protected IndexShard
newShard(boolean primary, Settings settings, EngineFactory engineFactory)
Creates a new initializing shard.protected IndexShard
newShard(ShardRouting routing, IndexMetaData indexMetaData, EngineFactory engineFactory, IndexingOperationListener... listeners)
creates a new initializing shard.protected IndexShard
newShard(ShardRouting routing, IndexMetaData indexMetaData, IndexSearcherWrapper indexSearcherWrapper, EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexingOperationListener... listeners)
creates a new initializing shard.protected IndexShard
newShard(ShardRouting shardRouting, Settings settings, EngineFactory engineFactory, IndexingOperationListener... listeners)
Creates a new initializing shard.protected IndexShard
newShard(ShardRouting shardRouting, IndexingOperationListener... listeners)
protected IndexShard
newShard(ShardRouting routing, ShardPath shardPath, IndexMetaData indexMetaData, CheckedFunction<IndexSettings,Store,java.io.IOException> storeProvider, IndexSearcherWrapper indexSearcherWrapper, EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexEventListener indexEventListener, IndexingOperationListener... listeners)
creates a new initializing shard.protected IndexShard
newShard(ShardId shardId, boolean primary, java.lang.String nodeId, IndexMetaData indexMetaData, IndexSearcherWrapper searcherWrapper)
creates a new initializing shard.protected IndexShard
newShard(ShardId shardId, boolean primary, java.lang.String nodeId, IndexMetaData indexMetaData, IndexSearcherWrapper searcherWrapper, java.lang.Runnable globalCheckpointSyncer)
creates a new initializing shard.protected IndexShard
newShard(ShardId shardId, boolean primary, IndexingOperationListener... listeners)
creates a new initializing shard.protected IndexShard
newStartedShard()
Creates a new empty shard and starts it.protected IndexShard
newStartedShard(boolean primary)
Creates a new empty shard and starts it.protected IndexShard
newStartedShard(boolean primary, Settings settings)
Creates a new empty shard and starts it.protected IndexShard
newStartedShard(boolean primary, Settings settings, EngineFactory engineFactory)
Creates a new empty shard with the specified settings and engine factory and starts it.protected IndexShard
newStartedShard(CheckedFunction<java.lang.Boolean,IndexShard,java.io.IOException> shardFunction, boolean primary)
creates a new empty shard and starts it.protected IndexShard
newStartedShard(Settings settings)
Creates a new empty shard and starts itprotected void
promoteReplica(IndexShard replica, java.util.Set<java.lang.String> inSyncIds, IndexShardRoutingTable routingTable)
promotes a replica to primary, incrementing it's term and starting it if neededprotected void
recoverReplica(IndexShard replica, IndexShard primary, boolean startReplica)
recovers a replica from the given primaryprotected void
recoverReplica(IndexShard replica, IndexShard primary, java.util.function.BiFunction<IndexShard,DiscoveryNode,RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted)
recovers a replica from the given primaryprotected void
recoverShardFromSnapshot(IndexShard shard, Snapshot snapshot, Repository repository)
Recover a shard from a snapshot using a given repositoryprotected void
recoverShardFromStore(IndexShard primary)
protected void
recoverUnstartedReplica(IndexShard replica, IndexShard primary, java.util.function.BiFunction<IndexShard,DiscoveryNode,RecoveryTarget> targetSupplier, boolean markAsRecovering, java.util.Set<java.lang.String> inSyncIds, IndexShardRoutingTable routingTable)
Recovers a replica from the give primary, allow the user to supply a custom recovery target.protected void
recoveryEmptyReplica(IndexShard replica, boolean startReplica)
protected IndexShard
reinitShard(IndexShard current, ShardRouting routing, EngineFactory engineFactory, IndexingOperationListener... listeners)
Takes an existing shard, closes it and starts a new initialing shard at the same locationprotected IndexShard
reinitShard(IndexShard current, ShardRouting routing, IndexingOperationListener... listeners)
Takes an existing shard, closes it and starts a new initialing shard at the same locationprotected IndexShard
reinitShard(IndexShard current, IndexingOperationListener... listeners)
Takes an existing shard, closes it and starts a new initialing shard at the same locationvoid
setUp()
protected ThreadPool
setUpThreadPool()
protected void
snapshotShard(IndexShard shard, Snapshot snapshot, Repository repository)
Snapshot a shard using a given repositoryprotected void
startReplicaAfterRecovery(IndexShard replica, IndexShard primary, java.util.Set<java.lang.String> inSyncIds, IndexShardRoutingTable routingTable)
void
tearDown()
protected void
tearDownThreadPool()
Settings
threadPoolSettings()
protected void
updateMappings(IndexShard shard, IndexMetaData indexMetadata)
static void
updateRoutingEntry(IndexShard shard, ShardRouting shardRouting)
-
Methods inherited from class org.elasticsearch.test.ESTestCase
after, afterIfFailed, afterIfSuccessful, assertAllIndicesRemovedAndDeletionCompleted, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertEqualsWithErrorMessageFromXContent, assertPathHasBeenCleared, assertSettingDeprecationsAndWarnings, assertSettingDeprecationsAndWarnings, assertWarnings, awaitBusy, awaitBusy, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, copyInstance, copyStreamable, copyWriteable, copyWriteable, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureSupportedLocale, frequently, generateRandomStringArray, generateRandomStringArray, getBwcIndicesPath, getDataPath, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, newTestIndicesModule, newTestScriptModule, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBoolean, randomByte, randomByteArrayOfLength, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomLong, randomLongBetween, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomZone, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, toShuffledXContent, writableRegistry, xContentRegistry
-
Methods inherited from class org.apache.lucene.util.LuceneTestCase
addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, assumeWorkingMMapOnWindows, atLeast, atLeast, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getBaseTempDirForTestClass, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, restoreSpins, runWithRestrictedPermissions, setIndexWriterMaxDocs, setupCPUCoreCount, setupSpins, slowFileExists, usually, usually, wrapReader
-
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
-
-
-
-
Field Detail
-
EMPTY_EVENT_LISTENER
public static final IndexEventListener EMPTY_EVENT_LISTENER
-
recoveryListener
protected static final PeerRecoveryTargetService.RecoveryListener recoveryListener
-
threadPool
protected ThreadPool threadPool
-
primaryTerm
protected long primaryTerm
-
currentClusterStateVersion
protected static java.util.concurrent.atomic.AtomicLong currentClusterStateVersion
-
-
Method Detail
-
setUp
public void setUp() throws java.lang.Exception
- Overrides:
setUp
in classorg.apache.lucene.util.LuceneTestCase
- Throws:
java.lang.Exception
-
setUpThreadPool
protected ThreadPool setUpThreadPool()
-
tearDown
public void tearDown() throws java.lang.Exception
- Overrides:
tearDown
in classorg.apache.lucene.util.LuceneTestCase
- Throws:
java.lang.Exception
-
tearDownThreadPool
protected void tearDownThreadPool()
-
allowShardFailures
protected void allowShardFailures()
by default, tests will fail if any shard created by this class fails. Tests that cause failures by design can call this method to ignore those failures
-
failOnShardFailures
protected void failOnShardFailures()
-
threadPoolSettings
public Settings threadPoolSettings()
-
createStore
protected Store createStore(IndexSettings indexSettings, ShardPath shardPath) throws java.io.IOException
- Throws:
java.io.IOException
-
createStore
protected Store createStore(ShardId shardId, IndexSettings indexSettings, org.apache.lucene.store.Directory directory) throws java.io.IOException
- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(boolean primary) throws java.io.IOException
Creates a new initializing shard. The shard will have its own unique data path.- Parameters:
primary
- indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(boolean primary, Settings settings) throws java.io.IOException
Creates a new initializing shard. The shard will have its own unique data path.- Parameters:
primary
- indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(boolean primary, Settings settings, EngineFactory engineFactory) throws java.io.IOException
Creates a new initializing shard. The shard will have its own unique data path.- Parameters:
primary
- indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)settings
- the settings to use for this shardengineFactory
- the engine factory to use for this shard- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardRouting shardRouting, IndexingOperationListener... listeners) throws java.io.IOException
- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardRouting shardRouting, Settings settings, EngineFactory engineFactory, IndexingOperationListener... listeners) throws java.io.IOException
Creates a new initializing shard. The shard will have its own unique data path.- Parameters:
shardRouting
- theShardRouting
to use for this shardsettings
- the settings to use for this shardengineFactory
- the engine factory to use for this shardlisteners
- an optional set of listeners to add to the shard- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardId shardId, boolean primary, IndexingOperationListener... listeners) throws java.io.IOException
creates a new initializing shard. The shard will have its own unique data path.- Parameters:
shardId
- the shard id to useprimary
- indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)listeners
- an optional set of listeners to add to the shard- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardId shardId, boolean primary, java.lang.String nodeId, IndexMetaData indexMetaData, @Nullable IndexSearcherWrapper searcherWrapper) throws java.io.IOException
creates a new initializing shard. The shard will will be put in its proper path under the supplied node id.- Parameters:
shardId
- the shard id to useprimary
- indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardId shardId, boolean primary, java.lang.String nodeId, IndexMetaData indexMetaData, @Nullable IndexSearcherWrapper searcherWrapper, java.lang.Runnable globalCheckpointSyncer) throws java.io.IOException
creates a new initializing shard. The shard will will be put in its proper path under the supplied node id.- Parameters:
shardId
- the shard id to useprimary
- indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardRouting routing, IndexMetaData indexMetaData, EngineFactory engineFactory, IndexingOperationListener... listeners) throws java.io.IOException
creates a new initializing shard. The shard will will be put in its proper path under the current node id the shard is assigned to.- Parameters:
routing
- shard routing to useindexMetaData
- indexMetaData for the shard, including any mappinglisteners
- an optional set of listeners to add to the shard- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardRouting routing, IndexMetaData indexMetaData, @Nullable IndexSearcherWrapper indexSearcherWrapper, @Nullable EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexingOperationListener... listeners) throws java.io.IOException
creates a new initializing shard. The shard will will be put in its proper path under the current node id the shard is assigned to.- Parameters:
routing
- shard routing to useindexMetaData
- indexMetaData for the shard, including any mappingindexSearcherWrapper
- an optional wrapper to be used during searchersglobalCheckpointSyncer
- callback for syncing global checkpointslisteners
- an optional set of listeners to add to the shard- Throws:
java.io.IOException
-
newShard
protected IndexShard newShard(ShardRouting routing, ShardPath shardPath, IndexMetaData indexMetaData, @Nullable CheckedFunction<IndexSettings,Store,java.io.IOException> storeProvider, @Nullable IndexSearcherWrapper indexSearcherWrapper, @Nullable EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexEventListener indexEventListener, IndexingOperationListener... listeners) throws java.io.IOException
creates a new initializing shard.- Parameters:
routing
- shard routing to useshardPath
- path to use for shard dataindexMetaData
- indexMetaData for the shard, including any mappingstoreProvider
- an optional custom store provider to use. If null a default file based store will be createdindexSearcherWrapper
- an optional wrapper to be used during searchersglobalCheckpointSyncer
- callback for syncing global checkpointsindexEventListener
- index event listenerlisteners
- an optional set of listeners to add to the shard- Throws:
java.io.IOException
-
reinitShard
protected IndexShard reinitShard(IndexShard current, IndexingOperationListener... listeners) throws java.io.IOException
Takes an existing shard, closes it and starts a new initialing shard at the same location- Parameters:
listeners
- new listerns to use for the newly created shard- Throws:
java.io.IOException
-
reinitShard
protected IndexShard reinitShard(IndexShard current, ShardRouting routing, IndexingOperationListener... listeners) throws java.io.IOException
Takes an existing shard, closes it and starts a new initialing shard at the same location- Parameters:
routing
- the shard routing to use for the newly created shard.listeners
- new listerns to use for the newly created shard- Throws:
java.io.IOException
-
reinitShard
protected IndexShard reinitShard(IndexShard current, ShardRouting routing, EngineFactory engineFactory, IndexingOperationListener... listeners) throws java.io.IOException
Takes an existing shard, closes it and starts a new initialing shard at the same location- Parameters:
routing
- the shard routing to use for the newly created shard.listeners
- new listerns to use for the newly created shardengineFactory
- the engine factory for the new shard- Throws:
java.io.IOException
-
newStartedShard
protected IndexShard newStartedShard() throws java.io.IOException
Creates a new empty shard and starts it. The shard will randomly be a replica or a primary.- Throws:
java.io.IOException
-
newStartedShard
protected IndexShard newStartedShard(Settings settings) throws java.io.IOException
Creates a new empty shard and starts it- Parameters:
settings
- the settings to use for this shard- Throws:
java.io.IOException
-
newStartedShard
protected IndexShard newStartedShard(boolean primary) throws java.io.IOException
Creates a new empty shard and starts it.- Parameters:
primary
- controls whether the shard will be a primary or a replica.- Throws:
java.io.IOException
-
newStartedShard
protected IndexShard newStartedShard(boolean primary, Settings settings) throws java.io.IOException
Creates a new empty shard and starts it.- Parameters:
primary
- controls whether the shard will be a primary or a replica.settings
- the settings to use for this shard- Throws:
java.io.IOException
-
newStartedShard
protected IndexShard newStartedShard(boolean primary, Settings settings, EngineFactory engineFactory) throws java.io.IOException
Creates a new empty shard with the specified settings and engine factory and starts it.- Parameters:
primary
- controls whether the shard will be a primary or a replica.settings
- the settings to use for this shardengineFactory
- the engine factory to use for this shard- Throws:
java.io.IOException
-
newStartedShard
protected IndexShard newStartedShard(CheckedFunction<java.lang.Boolean,IndexShard,java.io.IOException> shardFunction, boolean primary) throws java.io.IOException
creates a new empty shard and starts it.- Parameters:
shardFunction
- shard factory functionprimary
- controls whether the shard will be a primary or a replica.- Throws:
java.io.IOException
-
closeShards
protected void closeShards(IndexShard... shards) throws java.io.IOException
- Throws:
java.io.IOException
-
closeShard
protected void closeShard(IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene) throws java.io.IOException
- Throws:
java.io.IOException
-
closeShards
protected void closeShards(java.lang.Iterable<IndexShard> shards) throws java.io.IOException
- Throws:
java.io.IOException
-
recoverShardFromStore
protected void recoverShardFromStore(IndexShard primary) throws java.io.IOException
- Throws:
java.io.IOException
-
updateRoutingEntry
public static void updateRoutingEntry(IndexShard shard, ShardRouting shardRouting) throws java.io.IOException
- Throws:
java.io.IOException
-
recoveryEmptyReplica
protected void recoveryEmptyReplica(IndexShard replica, boolean startReplica) throws java.io.IOException
- Throws:
java.io.IOException
-
getFakeDiscoNode
protected DiscoveryNode getFakeDiscoNode(java.lang.String id)
-
recoverReplica
protected void recoverReplica(IndexShard replica, IndexShard primary, boolean startReplica) throws java.io.IOException
recovers a replica from the given primary- Throws:
java.io.IOException
-
recoverReplica
protected void recoverReplica(IndexShard replica, IndexShard primary, java.util.function.BiFunction<IndexShard,DiscoveryNode,RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted) throws java.io.IOException
recovers a replica from the given primary- Throws:
java.io.IOException
-
recoverUnstartedReplica
protected final void recoverUnstartedReplica(IndexShard replica, IndexShard primary, java.util.function.BiFunction<IndexShard,DiscoveryNode,RecoveryTarget> targetSupplier, boolean markAsRecovering, java.util.Set<java.lang.String> inSyncIds, IndexShardRoutingTable routingTable) throws java.io.IOException
Recovers a replica from the give primary, allow the user to supply a custom recovery target. A typical usage of a custom recovery target is to assert things in the various stages of recovery. Note: this method keeps the shard inIndexShardState.POST_RECOVERY
and doesn't start it.- Parameters:
replica
- the recovery target shardprimary
- the recovery source shardtargetSupplier
- supplies an instance ofRecoveryTarget
markAsRecovering
- set tofalse
if the replica is marked as recovering- Throws:
java.io.IOException
-
startReplicaAfterRecovery
protected void startReplicaAfterRecovery(IndexShard replica, IndexShard primary, java.util.Set<java.lang.String> inSyncIds, IndexShardRoutingTable routingTable) throws java.io.IOException
- Throws:
java.io.IOException
-
promoteReplica
protected void promoteReplica(IndexShard replica, java.util.Set<java.lang.String> inSyncIds, IndexShardRoutingTable routingTable) throws java.io.IOException
promotes a replica to primary, incrementing it's term and starting it if needed- Throws:
java.io.IOException
-
getShardDocUIDs
public static java.util.Set<java.lang.String> getShardDocUIDs(IndexShard shard) throws java.io.IOException
- Throws:
java.io.IOException
-
getDocIdAndSeqNos
public static java.util.List<DocIdSeqNoAndTerm> getDocIdAndSeqNos(IndexShard shard) throws java.io.IOException
- Throws:
java.io.IOException
-
assertDocCount
protected void assertDocCount(IndexShard shard, int docDount) throws java.io.IOException
- Throws:
java.io.IOException
-
assertDocs
protected void assertDocs(IndexShard shard, java.lang.String... ids) throws java.io.IOException
- Throws:
java.io.IOException
-
assertConsistentHistoryBetweenTranslogAndLucene
public static void assertConsistentHistoryBetweenTranslogAndLucene(IndexShard shard) throws java.io.IOException
- Throws:
java.io.IOException
-
indexDoc
protected Engine.IndexResult indexDoc(IndexShard shard, java.lang.String type, java.lang.String id) throws java.io.IOException
- Throws:
java.io.IOException
-
indexDoc
protected Engine.IndexResult indexDoc(IndexShard shard, java.lang.String type, java.lang.String id, java.lang.String source) throws java.io.IOException
- Throws:
java.io.IOException
-
indexDoc
protected Engine.IndexResult indexDoc(IndexShard shard, java.lang.String type, java.lang.String id, java.lang.String source, XContentType xContentType, java.lang.String routing) throws java.io.IOException
- Throws:
java.io.IOException
-
updateMappings
protected void updateMappings(IndexShard shard, IndexMetaData indexMetadata)
-
deleteDoc
protected Engine.DeleteResult deleteDoc(IndexShard shard, java.lang.String type, java.lang.String id) throws java.io.IOException
- Throws:
java.io.IOException
-
flushShard
protected void flushShard(IndexShard shard)
-
flushShard
protected void flushShard(IndexShard shard, boolean force)
-
recoverShardFromSnapshot
protected void recoverShardFromSnapshot(IndexShard shard, Snapshot snapshot, Repository repository) throws java.io.IOException
Recover a shard from a snapshot using a given repository- Throws:
java.io.IOException
-
snapshotShard
protected void snapshotShard(IndexShard shard, Snapshot snapshot, Repository repository) throws java.io.IOException
Snapshot a shard using a given repository- Throws:
java.io.IOException
-
getEngine
public static Engine getEngine(IndexShard indexShard)
Helper method to access (package-protected) engine from tests
-
getTranslog
public static Translog getTranslog(IndexShard shard)
-
getReplicationTracker
public static ReplicationTracker getReplicationTracker(IndexShard indexShard)
-
-