Skip to content

Commit

Permalink
Fix test SegmentReplicationIndexShardTests.testPrimaryRestart. (opens…
Browse files Browse the repository at this point in the history
  • Loading branch information
mch2 authored Aug 11, 2023
1 parent 48ec206 commit d352f2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,34 @@ public void testRepicaCleansUpOldCommitsWhenReceivingNew() throws Exception {
}
}

public void testPrimaryRestart() throws Exception {
final Path remotePath = createTempDir();
try (ReplicationGroup shards = createGroup(0, getIndexSettings(), indexMapping, new NRTReplicationEngineFactory(), remotePath)) {
shards.startAll();
// ensure primary has uploaded something
shards.indexDocs(10);
IndexShard primary = shards.getPrimary();
if (randomBoolean()) {
flushShard(primary);
} else {
primary.refresh("test");
}
assertDocCount(primary, 10);
// get a metadata map - we'll use segrep diff to ensure segments on reader are identical after restart.
final Map<String, StoreFileMetadata> metadataBeforeRestart = primary.getSegmentMetadataMap();
// restart the primary
shards.reinitPrimaryShard(remotePath);
// the store is open at this point but the shard has not yet run through recovery
primary = shards.getPrimary();
shards.startPrimary();
assertDocCount(primary, 10);
final Store.RecoveryDiff diff = Store.segmentReplicationDiff(metadataBeforeRestart, primary.getSegmentMetadataMap());
assertTrue(diff.missing.isEmpty());
logger.info("DIFF FILE {}", diff.different);
assertTrue(diff.different.isEmpty());
}
}

private void assertSingleSegmentFile(IndexShard shard, String fileName) throws IOException {
final Set<String> segmentsFileNames = Arrays.stream(shard.store().directory().listAll())
.filter(file -> file.startsWith(IndexFileNames.SEGMENTS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -774,33 +773,6 @@ public void testNoDuplicateSeqNo() throws Exception {
}
}

public void testPrimaryRestart() throws Exception {
final Path remotePath = createTempDir();
try (ReplicationGroup shards = createGroup(0, getIndexSettings(), indexMapping, new NRTReplicationEngineFactory(), remotePath)) {
shards.startAll();
// ensure primary has uploaded something
shards.indexDocs(10);
IndexShard primary = shards.getPrimary();
if (randomBoolean()) {
flushShard(primary);
} else {
primary.refresh("test");
}
assertDocCount(primary, 10);
// get a metadata map - we'll use segrep diff to ensure segments on reader are identical after restart.
final Map<String, StoreFileMetadata> metadataBeforeRestart = primary.getSegmentMetadataMap();
// restart the primary
shards.reinitPrimaryShard(remotePath);
// the store is open at this point but the shard has not yet run through recovery
primary = shards.getPrimary();
shards.startPrimary();
assertDocCount(primary, 10);
final Store.RecoveryDiff diff = Store.segmentReplicationDiff(metadataBeforeRestart, primary.getSegmentMetadataMap());
assertTrue(diff.missing.isEmpty());
assertTrue(diff.different.isEmpty());
}
}

/**
* Assert persisted and searchable doc counts. This method should not be used while docs are concurrently indexed because
* it asserts point in time seqNos are relative to the doc counts.
Expand Down

0 comments on commit d352f2c

Please sign in to comment.