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 shutdown
IndexShard
instances easily,
containing utilities for shard creation and recoveries. See {newShard(boolean)
} and
newStartedShard()
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
LuceneTestCase.AwaitsFix, LuceneTestCase.BadApple, LuceneTestCase.Monster, LuceneTestCase.Nightly, LuceneTestCase.Slow, LuceneTestCase.SuppressCodecs, LuceneTestCase.SuppressFileSystems, LuceneTestCase.SuppressFsync, LuceneTestCase.SuppressReproduceLine, LuceneTestCase.SuppressSysoutChecks, LuceneTestCase.SuppressTempFileChecks, LuceneTestCase.ThrowingRunnable, 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
checkIndexFailures, DEFAULT_TEST_WORKER_ID, failureAndSuccessEvents, FIPS_SYSPROP, JAVA_TIMEZONE_IDS, JAVA_ZONE_IDS, JODA_TIMEZONE_IDS, logger, TEST_WORKER_SYS_PROPERTY, TEST_WORKER_VM_ID
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)
static Engine.Warmer
createTestWarmer(IndexSettings indexSettings)
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<DocIdSeqNoAndSource>
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, CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> indexReaderWrapper, EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexingOperationListener... listeners)
creates a new initializing shard.protected IndexShard
newShard(ShardRouting routing, IndexMetaData indexMetaData, CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> indexReaderWrapper, EngineFactory engineFactory, 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, Settings settings, IndexingOperationListener... listeners)
protected IndexShard
newShard(ShardRouting shardRouting, IndexingOperationListener... listeners)
protected IndexShard
newShard(ShardRouting routing, ShardPath shardPath, IndexMetaData indexMetaData, CheckedFunction<IndexSettings,Store,java.io.IOException> storeProvider, CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> indexReaderWrapper, 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, CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> readerWrapper)
creates a new initializing shard.protected IndexShard
newShard(ShardId shardId, boolean primary, java.lang.String nodeId, IndexMetaData indexMetaData, CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> readerWrapper, 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 neededstatic boolean
recoverFromStore(IndexShard newShard)
protected 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, IndexMetaData indexMetaData, 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 java.lang.String
snapshotShard(IndexShard shard, Snapshot snapshot, Repository repository)
Snapshot a shard using a given repository.protected 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, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertSettingDeprecationsAndWarnings, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, clearPossibleRoles, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createParser, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableJodaDeprecationWarningsCheck, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureSupportedLocale, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getDataPath, getPortRange, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBoolean, randomByte, randomByteArrayOfLength, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomList, randomList, 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, setPossibleRoles, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, waitUntil, waitUntil, 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, callStackContains, callStackContains, callStackContainsAnyOf, 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 Details
-
EMPTY_EVENT_LISTENER
-
recoveryListener
-
threadPool
-
primaryTerm
protected long primaryTerm -
currentClusterStateVersion
protected static java.util.concurrent.atomic.AtomicLong currentClusterStateVersion
-
-
Constructor Details
-
IndexShardTestCase
public IndexShardTestCase()
-
-
Method Details
-
setUp
public void setUp() throws java.lang.Exception- Overrides:
setUp
in classLuceneTestCase
- Throws:
java.lang.Exception
-
setUpThreadPool
-
tearDown
public void tearDown() throws java.lang.Exception- Overrides:
tearDown
in classLuceneTestCase
- 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
-
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
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
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.IOExceptionCreates 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, 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.IOExceptionCreates 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.IOExceptioncreates 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 CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> readerWrapper) throws java.io.IOExceptioncreates 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 CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> readerWrapper, java.lang.Runnable globalCheckpointSyncer) throws java.io.IOExceptioncreates 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, @Nullable CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> indexReaderWrapper, EngineFactory engineFactory, IndexingOperationListener... listeners) throws java.io.IOExceptioncreates 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 CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> indexReaderWrapper, @Nullable EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexingOperationListener... listeners) throws java.io.IOExceptioncreates 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 mappingindexReaderWrapper
- an optional wrapper to be used during searchglobalCheckpointSyncer
- 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 CheckedFunction<DirectoryReader,DirectoryReader,java.io.IOException> indexReaderWrapper, @Nullable EngineFactory engineFactory, java.lang.Runnable globalCheckpointSyncer, RetentionLeaseSyncer retentionLeaseSyncer, IndexEventListener indexEventListener, IndexingOperationListener... listeners) throws java.io.IOExceptioncreates 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 createdindexReaderWrapper
- an optional wrapper to be used during searchglobalCheckpointSyncer
- 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.IOExceptionTakes 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.IOExceptionTakes 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, IndexMetaData indexMetaData, EngineFactory engineFactory, IndexingOperationListener... listeners) throws java.io.IOExceptionTakes 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 shardindexMetaData
- the index metadata to use for the newly created shardengineFactory
- the engine factory for the new shard- Throws:
java.io.IOException
-
newStartedShard
Creates a new empty shard and starts it. The shard will randomly be a replica or a primary.- Throws:
java.io.IOException
-
newStartedShard
Creates a new empty shard and starts it- Parameters:
settings
- the settings to use for this shard- Throws:
java.io.IOException
-
newStartedShard
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.IOExceptionCreates 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.IOExceptionCreates 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.IOExceptioncreates 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
- Throws:
java.io.IOException
-
closeShard
protected void closeShard(IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene) throws java.io.IOException- Throws:
java.io.IOException
-
closeShards
- Throws:
java.io.IOException
-
recoverShardFromStore
- 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
-
recoverReplica
protected void recoverReplica(IndexShard replica, IndexShard primary, boolean startReplica) throws java.io.IOExceptionrecovers 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.IOExceptionrecovers 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.IOExceptionRecovers 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.IOExceptionpromotes 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<DocIdSeqNoAndSource> getDocIdAndSeqNos(IndexShard shard) throws java.io.IOException- Throws:
java.io.IOException
-
assertDocCount
- Throws:
java.io.IOException
-
assertDocs
- 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
-
deleteDoc
protected Engine.DeleteResult deleteDoc(IndexShard shard, java.lang.String type, java.lang.String id) throws java.io.IOException- Throws:
java.io.IOException
-
flushShard
-
flushShard
-
recoverFromStore
-
recoverShardFromSnapshot
protected void recoverShardFromSnapshot(IndexShard shard, Snapshot snapshot, Repository repository)Recover a shard from a snapshot using a given repository -
snapshotShard
protected java.lang.String snapshotShard(IndexShard shard, Snapshot snapshot, Repository repository) throws java.io.IOExceptionSnapshot a shard using a given repository.- Returns:
- new shard generation
- Throws:
java.io.IOException
-
getEngine
Helper method to access (package-protected) engine from tests -
getTranslog
-
getReplicationTracker
-
createTestWarmer
-