Skip to content

Commit

Permalink
Added UT for replica shard recovery
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <[email protected]>
  • Loading branch information
ashking94 committed Sep 5, 2022
1 parent 057a8fe commit 4d7061f
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.settings.Settings;
import org.opensearch.index.engine.DocIdSeqNoAndSource;
import org.opensearch.index.engine.NRTReplicationEngine;
import org.opensearch.index.engine.NRTReplicationEngineFactory;
import org.opensearch.index.replication.OpenSearchIndexLevelReplicationTestCase;
import org.opensearch.index.translog.WriteOnlyTranslogManager;
import org.opensearch.indices.replication.common.ReplicationType;

import java.util.List;

public class ReplicaRecoveryWithRemoteTranslogOnPrimaryTests extends OpenSearchIndexLevelReplicationTestCase {

private static final Settings settings = Settings.builder()
Expand Down Expand Up @@ -56,4 +61,35 @@ public void testReplicaShardRecoveryUptoLastFlushedCommit() throws Exception {
shards.assertAllEqual(numDocs + moreDocs);
}
}

public void testNoTranslogHistoryTransferred() throws Exception {
try (ReplicationGroup shards = createGroup(0, settings, new NRTReplicationEngineFactory())) {

// Step1 - Start primary, index docs, flush, index more docs, check translog in primary as expected
shards.startPrimary();
final IndexShard primary = shards.getPrimary();
int numDocs = shards.indexDocs(randomIntBetween(10, 100));
shards.flush();
List<DocIdSeqNoAndSource> docIdAndSeqNosAfterFlush = getDocIdAndSeqNos(primary);
int moreDocs = shards.indexDocs(randomIntBetween(20, 100));
assertEquals(moreDocs, getTranslog(primary).totalOperations());

// Step 2 - Start replica, recovery happens, check docs recovered till last flush
final IndexShard replica = shards.addReplica();
shards.startAll();
assertEquals(docIdAndSeqNosAfterFlush, getDocIdAndSeqNos(replica));
assertDocCount(replica, numDocs);
assertEquals(NRTReplicationEngine.class, replica.getEngine().getClass());

// Step 3 - Check replica's translog has no operations
assertEquals(WriteOnlyTranslogManager.class, replica.getEngine().translogManager().getClass());
WriteOnlyTranslogManager replicaTranslogManager = (WriteOnlyTranslogManager) replica.getEngine().translogManager();
assertEquals(0, replicaTranslogManager.getTranslog().totalOperations());

// Adding this for close to succeed
shards.flush();
replicateSegments(primary, shards.getReplicas());
shards.assertAllEqual(numDocs + moreDocs);
}
}
}

0 comments on commit 4d7061f

Please sign in to comment.