|
10 | 10 |
|
11 | 11 | import org.opensearch.cluster.metadata.IndexMetadata; |
12 | 12 | import org.opensearch.common.settings.Settings; |
| 13 | +import org.opensearch.index.engine.DocIdSeqNoAndSource; |
| 14 | +import org.opensearch.index.engine.NRTReplicationEngine; |
13 | 15 | import org.opensearch.index.engine.NRTReplicationEngineFactory; |
14 | 16 | import org.opensearch.index.replication.OpenSearchIndexLevelReplicationTestCase; |
| 17 | +import org.opensearch.index.translog.WriteOnlyTranslogManager; |
15 | 18 | import org.opensearch.indices.replication.common.ReplicationType; |
16 | 19 |
|
| 20 | +import java.util.List; |
| 21 | + |
17 | 22 | public class ReplicaRecoveryWithRemoteTranslogOnPrimaryTests extends OpenSearchIndexLevelReplicationTestCase { |
18 | 23 |
|
19 | 24 | private static final Settings settings = Settings.builder() |
@@ -56,4 +61,35 @@ public void testReplicaShardRecoveryUptoLastFlushedCommit() throws Exception { |
56 | 61 | shards.assertAllEqual(numDocs + moreDocs); |
57 | 62 | } |
58 | 63 | } |
| 64 | + |
| 65 | + public void testNoTranslogHistoryTransferred() throws Exception { |
| 66 | + try (ReplicationGroup shards = createGroup(0, settings, new NRTReplicationEngineFactory())) { |
| 67 | + |
| 68 | + // Step1 - Start primary, index docs, flush, index more docs, check translog in primary as expected |
| 69 | + shards.startPrimary(); |
| 70 | + final IndexShard primary = shards.getPrimary(); |
| 71 | + int numDocs = shards.indexDocs(randomIntBetween(10, 100)); |
| 72 | + shards.flush(); |
| 73 | + List<DocIdSeqNoAndSource> docIdAndSeqNosAfterFlush = getDocIdAndSeqNos(primary); |
| 74 | + int moreDocs = shards.indexDocs(randomIntBetween(20, 100)); |
| 75 | + assertEquals(moreDocs, getTranslog(primary).totalOperations()); |
| 76 | + |
| 77 | + // Step 2 - Start replica, recovery happens, check docs recovered till last flush |
| 78 | + final IndexShard replica = shards.addReplica(); |
| 79 | + shards.startAll(); |
| 80 | + assertEquals(docIdAndSeqNosAfterFlush, getDocIdAndSeqNos(replica)); |
| 81 | + assertDocCount(replica, numDocs); |
| 82 | + assertEquals(NRTReplicationEngine.class, replica.getEngine().getClass()); |
| 83 | + |
| 84 | + // Step 3 - Check replica's translog has no operations |
| 85 | + assertEquals(WriteOnlyTranslogManager.class, replica.getEngine().translogManager().getClass()); |
| 86 | + WriteOnlyTranslogManager replicaTranslogManager = (WriteOnlyTranslogManager) replica.getEngine().translogManager(); |
| 87 | + assertEquals(0, replicaTranslogManager.getTranslog().totalOperations()); |
| 88 | + |
| 89 | + // Adding this for close to succeed |
| 90 | + shards.flush(); |
| 91 | + replicateSegments(primary, shards.getReplicas()); |
| 92 | + shards.assertAllEqual(numDocs + moreDocs); |
| 93 | + } |
| 94 | + } |
59 | 95 | } |
0 commit comments