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.DeprecationWarning, 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 AtomicLong
     
    static final org.elasticsearch.index.shard.IndexEventListener
     
    protected long
     
    protected static final org.elasticsearch.indices.recovery.PeerRecoveryTargetService.RecoveryListener
     
    protected org.elasticsearch.threadpool.ThreadPool
     

    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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    by default, tests will fail if any shard created by this class fails.
    static void
    assertConsistentHistoryBetweenTranslogAndLucene(org.elasticsearch.index.shard.IndexShard shard)
     
    protected void
    assertDocCount(org.elasticsearch.index.shard.IndexShard shard, int docDount)
     
    protected void
    assertDocs(org.elasticsearch.index.shard.IndexShard shard, String... ids)
     
    protected void
    closeShard(org.elasticsearch.index.shard.IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene)
     
    protected void
    closeShards(Iterable<org.elasticsearch.index.shard.IndexShard> shards)
     
    protected void
    closeShards(org.elasticsearch.index.shard.IndexShard... shards)
     
    protected org.elasticsearch.index.store.Store
    createStore(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.shard.ShardPath shardPath)
     
    protected org.elasticsearch.index.store.Store
    createStore(org.elasticsearch.index.shard.ShardId shardId, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.store.Directory directory)
     
    static org.elasticsearch.index.engine.Engine.Warmer
    createTestWarmer(org.elasticsearch.index.IndexSettings indexSettings)
     
    protected org.elasticsearch.index.engine.Engine.DeleteResult
    deleteDoc(org.elasticsearch.index.shard.IndexShard shard, String id)
     
    protected void
     
    protected void
    flushShard(org.elasticsearch.index.shard.IndexShard shard)
     
    protected void
    flushShard(org.elasticsearch.index.shard.IndexShard shard, boolean force)
     
    getDocIdAndSeqNos(org.elasticsearch.index.shard.IndexShard shard)
     
    static org.elasticsearch.index.engine.Engine
    getEngine(org.elasticsearch.index.shard.IndexShard indexShard)
    Helper method to access (package-protected) engine from tests
    protected org.elasticsearch.cluster.node.DiscoveryNode
     
    static org.elasticsearch.index.seqno.ReplicationTracker
    getReplicationTracker(org.elasticsearch.index.shard.IndexShard indexShard)
     
    static Set<String>
    getShardDocUIDs(org.elasticsearch.index.shard.IndexShard shard)
     
    static org.elasticsearch.index.translog.Translog
    getTranslog(org.elasticsearch.index.shard.IndexShard shard)
     
    protected org.elasticsearch.index.engine.Engine.IndexResult
    indexDoc(org.elasticsearch.index.shard.IndexShard shard, String type, String id)
     
    protected org.elasticsearch.index.engine.Engine.IndexResult
    indexDoc(org.elasticsearch.index.shard.IndexShard shard, String type, String id, String source)
     
    protected org.elasticsearch.index.engine.Engine.IndexResult
    indexDoc(org.elasticsearch.index.shard.IndexShard shard, String id, String source, org.elasticsearch.xcontent.XContentType xContentType, String routing)
     
    protected org.elasticsearch.index.shard.IndexShard
    newShard(boolean primary)
    Creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(boolean primary, org.elasticsearch.common.settings.Settings settings)
    Creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(boolean primary, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.engine.EngineFactory engineFactory)
    Creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> indexReaderWrapper, org.elasticsearch.index.engine.EngineFactory engineFactory, Runnable globalCheckpointSyncer, org.elasticsearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> indexReaderWrapper, org.elasticsearch.index.engine.EngineFactory engineFactory, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.cluster.routing.ShardRouting shardRouting, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.engine.EngineFactory engineFactory, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    Creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.cluster.routing.ShardRouting shardRouting, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
     
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.cluster.routing.ShardRouting shardRouting, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
     
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.index.shard.ShardPath shardPath, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.core.CheckedFunction<org.elasticsearch.index.IndexSettings,org.elasticsearch.index.store.Store,IOException> storeProvider, org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> indexReaderWrapper, org.elasticsearch.index.engine.EngineFactory engineFactory, Runnable globalCheckpointSyncer, org.elasticsearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.elasticsearch.index.shard.IndexEventListener indexEventListener, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.index.shard.ShardId shardId, boolean primary, String nodeId, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> readerWrapper)
    creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.index.shard.ShardId shardId, boolean primary, String nodeId, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> readerWrapper, Runnable globalCheckpointSyncer)
    creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    newShard(org.elasticsearch.index.shard.ShardId shardId, boolean primary, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    creates a new initializing shard.
    protected org.elasticsearch.index.shard.IndexShard
    Creates a new empty shard and starts it.
    protected org.elasticsearch.index.shard.IndexShard
    newStartedShard(boolean primary)
    Creates a new empty shard and starts it.
    protected org.elasticsearch.index.shard.IndexShard
    newStartedShard(boolean primary, org.elasticsearch.common.settings.Settings settings)
    Creates a new empty shard and starts it.
    protected org.elasticsearch.index.shard.IndexShard
    newStartedShard(boolean primary, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.engine.EngineFactory engineFactory)
    Creates a new empty shard with the specified settings and engine factory and starts it.
    protected org.elasticsearch.index.shard.IndexShard
    newStartedShard(org.elasticsearch.common.settings.Settings settings)
    Creates a new empty shard and starts it
    protected org.elasticsearch.index.shard.IndexShard
    newStartedShard(org.elasticsearch.core.CheckedFunction<Boolean,org.elasticsearch.index.shard.IndexShard,IOException> shardFunction, boolean primary)
    creates a new empty shard and starts it.
    protected void
    promoteReplica(org.elasticsearch.index.shard.IndexShard replica, Set<String> inSyncIds, org.elasticsearch.cluster.routing.IndexShardRoutingTable routingTable)
    promotes a replica to primary, incrementing it's term and starting it if needed
    static boolean
    recoverFromStore(org.elasticsearch.index.shard.IndexShard newShard)
     
    protected void
    recoverReplica(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, boolean startReplica)
    recovers a replica from the given primary
    protected void
    recoverReplica(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, BiFunction<org.elasticsearch.index.shard.IndexShard,org.elasticsearch.cluster.node.DiscoveryNode,org.elasticsearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted)
    recovers a replica from the given primary
    protected void
    recoverShardFromSnapshot(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.snapshots.Snapshot snapshot, org.elasticsearch.repositories.Repository repository)
    Recover a shard from a snapshot using a given repository
    protected void
    recoverShardFromStore(org.elasticsearch.index.shard.IndexShard primary)
     
    protected final void
    recoverUnstartedReplica(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, BiFunction<org.elasticsearch.index.shard.IndexShard,org.elasticsearch.cluster.node.DiscoveryNode,org.elasticsearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, Set<String> inSyncIds, org.elasticsearch.cluster.routing.IndexShardRoutingTable routingTable)
    Recovers a replica from the give primary, allow the user to supply a custom recovery target.
    protected void
    recoveryEmptyReplica(org.elasticsearch.index.shard.IndexShard replica, boolean startReplica)
     
    protected org.elasticsearch.index.shard.IndexShard
    reinitShard(org.elasticsearch.index.shard.IndexShard current, org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.index.engine.EngineFactory engineFactory, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    Takes an existing shard, closes it and starts a new initialing shard at the same location
    protected org.elasticsearch.index.shard.IndexShard
    reinitShard(org.elasticsearch.index.shard.IndexShard current, org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    Takes an existing shard, closes it and starts a new initialing shard at the same location
    protected org.elasticsearch.index.shard.IndexShard
    reinitShard(org.elasticsearch.index.shard.IndexShard current, org.elasticsearch.index.shard.IndexingOperationListener... listeners)
    Takes an existing shard, closes it and starts a new initialing shard at the same location
    void
     
    protected org.elasticsearch.threadpool.ThreadPool
     
    protected org.elasticsearch.repositories.ShardGeneration
    snapshotShard(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.snapshots.Snapshot snapshot, org.elasticsearch.repositories.Repository repository)
    Snapshot a shard using a given repository.
    protected void
    startReplicaAfterRecovery(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, Set<String> inSyncIds, org.elasticsearch.cluster.routing.IndexShardRoutingTable routingTable)
     
    void
     
    protected void
     
    org.elasticsearch.common.settings.Settings
     
    protected void
    updateMappings(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata)
     
    static void
    updateRoutingEntry(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.cluster.routing.ShardRouting shardRouting)
     

    Methods inherited from class org.elasticsearch.test.ESTestCase

    after, afterIfFailed, afterIfSuccessful, assertArrayEquals, assertBusy, assertBusy, assertCriticalWarnings, assertEquals, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, compatibleMediaType, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createParserWithCompatibilityFor, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureNoWarnings, ensureSupportedLocale, filteredWarnings, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getDataPath, getPortRange, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newEnvironment, newEnvironment, newNodeEnvironment, newNodeEnvironment, parserConfig, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomCompatibleMediaType, randomDateFormatterPattern, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomMap, randomMillisUpToYear9999, randomNonNegativeByte, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomVendorType, randomZone, removeHeaderWarningAppender, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffleMap, shuffleXContent, shuffleXContent, skipTestWaitingForLuceneFix, 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, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, 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, newSearcher, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, runWithRestrictedPermissions, setIndexWriterMaxDocs, setupCPUCoreCount, 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY_EVENT_LISTENER

      public static final org.elasticsearch.index.shard.IndexEventListener EMPTY_EVENT_LISTENER
    • recoveryListener

      protected static final org.elasticsearch.indices.recovery.PeerRecoveryTargetService.RecoveryListener recoveryListener
    • threadPool

      protected org.elasticsearch.threadpool.ThreadPool threadPool
    • primaryTerm

      protected long primaryTerm
    • currentClusterStateVersion

      protected static AtomicLong currentClusterStateVersion
  • Constructor Details

    • IndexShardTestCase

      public IndexShardTestCase()
  • Method Details

    • setUp

      public void setUp() throws Exception
      Overrides:
      setUp in class org.apache.lucene.util.LuceneTestCase
      Throws:
      Exception
    • setUpThreadPool

      protected org.elasticsearch.threadpool.ThreadPool setUpThreadPool()
    • tearDown

      public void tearDown() throws Exception
      Overrides:
      tearDown in class org.apache.lucene.util.LuceneTestCase
      Throws:
      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 org.elasticsearch.common.settings.Settings threadPoolSettings()
    • createStore

      protected org.elasticsearch.index.store.Store createStore(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.shard.ShardPath shardPath) throws IOException
      Throws:
      IOException
    • createStore

      protected org.elasticsearch.index.store.Store createStore(org.elasticsearch.index.shard.ShardId shardId, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.store.Directory directory) throws IOException
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(boolean primary) throws 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:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(boolean primary, org.elasticsearch.common.settings.Settings settings) throws 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:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(boolean primary, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.engine.EngineFactory engineFactory) throws 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 shard
      engineFactory - the engine factory to use for this shard
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.cluster.routing.ShardRouting shardRouting, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.cluster.routing.ShardRouting shardRouting, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.cluster.routing.ShardRouting shardRouting, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.engine.EngineFactory engineFactory, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws IOException
      Creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      shardRouting - the ShardRouting to use for this shard
      settings - the settings to use for this shard
      engineFactory - the engine factory to use for this shard
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.index.shard.ShardId shardId, boolean primary, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard. The shard will have its own unique data path.
      Parameters:
      shardId - the shard id to use
      primary - 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:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.index.shard.ShardId shardId, boolean primary, String nodeId, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> readerWrapper) throws 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 use
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.index.shard.ShardId shardId, boolean primary, String nodeId, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> readerWrapper, Runnable globalCheckpointSyncer) throws 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 use
      primary - indicates whether to a primary shard (ready to recover from an empty store) or a replica (ready to recover from another shard)
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> indexReaderWrapper, org.elasticsearch.index.engine.EngineFactory engineFactory, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws 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 use
      indexMetadata - indexMetadata for the shard, including any mapping
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> indexReaderWrapper, @Nullable org.elasticsearch.index.engine.EngineFactory engineFactory, Runnable globalCheckpointSyncer, org.elasticsearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws 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 use
      indexMetadata - indexMetadata for the shard, including any mapping
      indexReaderWrapper - an optional wrapper to be used during search
      globalCheckpointSyncer - callback for syncing global checkpoints
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • newShard

      protected org.elasticsearch.index.shard.IndexShard newShard(org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.index.shard.ShardPath shardPath, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, @Nullable org.elasticsearch.core.CheckedFunction<org.elasticsearch.index.IndexSettings,org.elasticsearch.index.store.Store,IOException> storeProvider, @Nullable org.elasticsearch.core.CheckedFunction<org.apache.lucene.index.DirectoryReader,org.apache.lucene.index.DirectoryReader,IOException> indexReaderWrapper, @Nullable org.elasticsearch.index.engine.EngineFactory engineFactory, Runnable globalCheckpointSyncer, org.elasticsearch.index.seqno.RetentionLeaseSyncer retentionLeaseSyncer, org.elasticsearch.index.shard.IndexEventListener indexEventListener, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws IOException
      creates a new initializing shard.
      Parameters:
      routing - shard routing to use
      shardPath - path to use for shard data
      indexMetadata - indexMetadata for the shard, including any mapping
      storeProvider - an optional custom store provider to use. If null a default file based store will be created
      indexReaderWrapper - an optional wrapper to be used during search
      globalCheckpointSyncer - callback for syncing global checkpoints
      indexEventListener - index event listener
      listeners - an optional set of listeners to add to the shard
      Throws:
      IOException
    • reinitShard

      protected org.elasticsearch.index.shard.IndexShard reinitShard(org.elasticsearch.index.shard.IndexShard current, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws 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:
      IOException
    • reinitShard

      protected org.elasticsearch.index.shard.IndexShard reinitShard(org.elasticsearch.index.shard.IndexShard current, org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws 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:
      IOException
    • reinitShard

      protected org.elasticsearch.index.shard.IndexShard reinitShard(org.elasticsearch.index.shard.IndexShard current, org.elasticsearch.cluster.routing.ShardRouting routing, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata, org.elasticsearch.index.engine.EngineFactory engineFactory, org.elasticsearch.index.shard.IndexingOperationListener... listeners) throws 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
      indexMetadata - the index metadata to use for the newly created shard
      engineFactory - the engine factory for the new shard
      Throws:
      IOException
    • newStartedShard

      protected org.elasticsearch.index.shard.IndexShard newStartedShard() throws IOException
      Creates a new empty shard and starts it. The shard will randomly be a replica or a primary.
      Throws:
      IOException
    • newStartedShard

      protected org.elasticsearch.index.shard.IndexShard newStartedShard(org.elasticsearch.common.settings.Settings settings) throws IOException
      Creates a new empty shard and starts it
      Parameters:
      settings - the settings to use for this shard
      Throws:
      IOException
    • newStartedShard

      protected org.elasticsearch.index.shard.IndexShard newStartedShard(boolean primary) throws IOException
      Creates a new empty shard and starts it.
      Parameters:
      primary - controls whether the shard will be a primary or a replica.
      Throws:
      IOException
    • newStartedShard

      protected org.elasticsearch.index.shard.IndexShard newStartedShard(boolean primary, org.elasticsearch.common.settings.Settings settings) throws 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:
      IOException
    • newStartedShard

      protected org.elasticsearch.index.shard.IndexShard newStartedShard(boolean primary, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.index.engine.EngineFactory engineFactory) throws 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 shard
      engineFactory - the engine factory to use for this shard
      Throws:
      IOException
    • newStartedShard

      protected org.elasticsearch.index.shard.IndexShard newStartedShard(org.elasticsearch.core.CheckedFunction<Boolean,org.elasticsearch.index.shard.IndexShard,IOException> shardFunction, boolean primary) throws IOException
      creates a new empty shard and starts it.
      Parameters:
      shardFunction - shard factory function
      primary - controls whether the shard will be a primary or a replica.
      Throws:
      IOException
    • closeShards

      protected void closeShards(org.elasticsearch.index.shard.IndexShard... shards) throws IOException
      Throws:
      IOException
    • closeShard

      protected void closeShard(org.elasticsearch.index.shard.IndexShard shard, boolean assertConsistencyBetweenTranslogAndLucene) throws IOException
      Throws:
      IOException
    • closeShards

      protected void closeShards(Iterable<org.elasticsearch.index.shard.IndexShard> shards) throws IOException
      Throws:
      IOException
    • recoverShardFromStore

      protected void recoverShardFromStore(org.elasticsearch.index.shard.IndexShard primary) throws IOException
      Throws:
      IOException
    • updateRoutingEntry

      public static void updateRoutingEntry(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.cluster.routing.ShardRouting shardRouting) throws IOException
      Throws:
      IOException
    • recoveryEmptyReplica

      protected void recoveryEmptyReplica(org.elasticsearch.index.shard.IndexShard replica, boolean startReplica) throws IOException
      Throws:
      IOException
    • getFakeDiscoNode

      protected org.elasticsearch.cluster.node.DiscoveryNode getFakeDiscoNode(String id)
    • recoverReplica

      protected void recoverReplica(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, boolean startReplica) throws IOException
      recovers a replica from the given primary
      Throws:
      IOException
    • recoverReplica

      protected void recoverReplica(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, BiFunction<org.elasticsearch.index.shard.IndexShard,org.elasticsearch.cluster.node.DiscoveryNode,org.elasticsearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, boolean markAsStarted) throws IOException
      recovers a replica from the given primary
      Throws:
      IOException
    • recoverUnstartedReplica

      protected final void recoverUnstartedReplica(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, BiFunction<org.elasticsearch.index.shard.IndexShard,org.elasticsearch.cluster.node.DiscoveryNode,org.elasticsearch.indices.recovery.RecoveryTarget> targetSupplier, boolean markAsRecovering, Set<String> inSyncIds, org.elasticsearch.cluster.routing.IndexShardRoutingTable routingTable) throws 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 in IndexShardState.POST_RECOVERY and doesn't start it.
      Parameters:
      replica - the recovery target shard
      primary - the recovery source shard
      targetSupplier - supplies an instance of RecoveryTarget
      markAsRecovering - set to false if the replica is marked as recovering
      Throws:
      IOException
    • startReplicaAfterRecovery

      protected void startReplicaAfterRecovery(org.elasticsearch.index.shard.IndexShard replica, org.elasticsearch.index.shard.IndexShard primary, Set<String> inSyncIds, org.elasticsearch.cluster.routing.IndexShardRoutingTable routingTable) throws IOException
      Throws:
      IOException
    • promoteReplica

      protected void promoteReplica(org.elasticsearch.index.shard.IndexShard replica, Set<String> inSyncIds, org.elasticsearch.cluster.routing.IndexShardRoutingTable routingTable) throws IOException
      promotes a replica to primary, incrementing it's term and starting it if needed
      Throws:
      IOException
    • getShardDocUIDs

      public static Set<String> getShardDocUIDs(org.elasticsearch.index.shard.IndexShard shard) throws IOException
      Throws:
      IOException
    • getDocIdAndSeqNos

      public static List<DocIdSeqNoAndSource> getDocIdAndSeqNos(org.elasticsearch.index.shard.IndexShard shard) throws IOException
      Throws:
      IOException
    • assertDocCount

      protected void assertDocCount(org.elasticsearch.index.shard.IndexShard shard, int docDount) throws IOException
      Throws:
      IOException
    • assertDocs

      protected void assertDocs(org.elasticsearch.index.shard.IndexShard shard, String... ids) throws IOException
      Throws:
      IOException
    • assertConsistentHistoryBetweenTranslogAndLucene

      public static void assertConsistentHistoryBetweenTranslogAndLucene(org.elasticsearch.index.shard.IndexShard shard) throws IOException
      Throws:
      IOException
    • indexDoc

      protected org.elasticsearch.index.engine.Engine.IndexResult indexDoc(org.elasticsearch.index.shard.IndexShard shard, String type, String id) throws IOException
      Throws:
      IOException
    • indexDoc

      protected org.elasticsearch.index.engine.Engine.IndexResult indexDoc(org.elasticsearch.index.shard.IndexShard shard, String type, String id, String source) throws IOException
      Throws:
      IOException
    • indexDoc

      protected org.elasticsearch.index.engine.Engine.IndexResult indexDoc(org.elasticsearch.index.shard.IndexShard shard, String id, String source, org.elasticsearch.xcontent.XContentType xContentType, String routing) throws IOException
      Throws:
      IOException
    • updateMappings

      protected void updateMappings(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.cluster.metadata.IndexMetadata indexMetadata)
    • deleteDoc

      protected org.elasticsearch.index.engine.Engine.DeleteResult deleteDoc(org.elasticsearch.index.shard.IndexShard shard, String id) throws IOException
      Throws:
      IOException
    • flushShard

      protected void flushShard(org.elasticsearch.index.shard.IndexShard shard)
    • flushShard

      protected void flushShard(org.elasticsearch.index.shard.IndexShard shard, boolean force)
    • recoverFromStore

      public static boolean recoverFromStore(org.elasticsearch.index.shard.IndexShard newShard)
    • recoverShardFromSnapshot

      protected void recoverShardFromSnapshot(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.snapshots.Snapshot snapshot, org.elasticsearch.repositories.Repository repository)
      Recover a shard from a snapshot using a given repository
    • snapshotShard

      protected org.elasticsearch.repositories.ShardGeneration snapshotShard(org.elasticsearch.index.shard.IndexShard shard, org.elasticsearch.snapshots.Snapshot snapshot, org.elasticsearch.repositories.Repository repository) throws IOException
      Snapshot a shard using a given repository.
      Returns:
      new shard generation
      Throws:
      IOException
    • getEngine

      public static org.elasticsearch.index.engine.Engine getEngine(org.elasticsearch.index.shard.IndexShard indexShard)
      Helper method to access (package-protected) engine from tests
    • getTranslog

      public static org.elasticsearch.index.translog.Translog getTranslog(org.elasticsearch.index.shard.IndexShard shard)
    • getReplicationTracker

      public static org.elasticsearch.index.seqno.ReplicationTracker getReplicationTracker(org.elasticsearch.index.shard.IndexShard indexShard)
    • createTestWarmer

      public static org.elasticsearch.index.engine.Engine.Warmer createTestWarmer(org.elasticsearch.index.IndexSettings indexSettings)