Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com>
  • Loading branch information
Rishikesh1159 committed Mar 15, 2023
1 parent f7dcfb1 commit ffd94b1
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.opensearch.action.ActionFuture;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
import org.opensearch.action.admin.cluster.reroute.ClusterRerouteResponse;
import org.opensearch.action.admin.indices.replication.SegmentReplicationStatsResponse;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.action.support.WriteRequest;
import org.opensearch.cluster.ClusterState;
Expand Down Expand Up @@ -521,16 +522,19 @@ public void testFlushAfterRelocation() throws Exception {
assertEquals(clusterHealthResponse.isTimedOut(), false);
ensureGreen(INDEX_NAME);

// Start indexing docs and refresh index
// Start indexing docs
final int initialDocCount = scaledRandomIntBetween(2000, 3000);
final List<ActionFuture<IndexResponse>> pendingIndexResponses = new ArrayList<>();

for (int i = 0; i < initialDocCount; i++) {
pendingIndexResponses.add(
client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute()
);
client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();
}
refresh(INDEX_NAME);

// Verify segment replication event never happened on replica shard
SegmentReplicationStatsResponse segmentReplicationStatsResponse = dataNodeClient().admin()
.indices()
.prepareSegmentReplicationStats(INDEX_NAME)
.execute()
.actionGet();
assertFalse(segmentReplicationStatsResponse.hasSegmentReplicationStats());

// Relocate primary to new primary. When new primary starts it does perform a flush.
logger.info("--> relocate the shard from primary to newPrimary");
Expand All @@ -549,9 +553,16 @@ public void testFlushAfterRelocation() throws Exception {
.actionGet();
assertEquals(clusterHealthResponse.isTimedOut(), false);

// Verify if all docs are present in replica after flush, if new relocated primary doesn't flush after relocation the below assert
// Verify if all docs are present in replica after relocation, if new relocated primary doesn't flush after relocation the below
// assert
// will fail
waitForSearchableDocs(initialDocCount, replicaNode);
assertHitCount(client(replicaNode).prepareSearch(INDEX_NAME).setPreference("_only_local").setSize(0).get(), initialDocCount);
assertBusy(
() -> {
assertHitCount(
client(replicaNode).prepareSearch(INDEX_NAME).setPreference("_only_local").setSize(0).get(),
initialDocCount
);
}
);
}
}

0 comments on commit ffd94b1

Please sign in to comment.