From 4de7ebcb9969a789702bcae922dc770cb71531a6 Mon Sep 17 00:00:00 2001 From: Suraj Singh Date: Mon, 26 Jun 2023 15:55:53 -0700 Subject: [PATCH] Handle 0 doc count segments Signed-off-by: Suraj Singh --- .../java/org/opensearch/upgrades/IndexingIT.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java index f1ef796443f32..9dc9a23440af0 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java @@ -99,13 +99,19 @@ private void waitForSearchableDocs(String index, int shardCount, int replicaCoun Response segrepStatsResponse = client().performRequest(segrepStatsRequest); logger.info("--> _cat/segments response\n {}", EntityUtils.toString(segrepStatsResponse.getEntity())); List responseList = Streams.readAllLines(segrepStatsResponse.getEntity().getContent()); - for (int primaryIndex=0; primaryIndex < responseList.size(); primaryIndex+=replicaCount+1) { - String[] primaryRow = responseList.get(primaryIndex).split(" +"); + for (int segmentsIndex=0; segmentsIndex < responseList.size();) { + String[] primaryRow = responseList.get(segmentsIndex++).split(" +"); String shardId = primaryRow[0] + primaryRow[1]; assertTrue(primaryRow[2].equals("p")); - for(int replicaIdx = 1; replicaIdx <= replicaCount; replicaIdx++) { - String[] replicaRow = responseList.get(primaryIndex + replicaIdx).split(" +"); + for(int replicaIndex = 1; replicaIndex <= replicaCount; replicaIndex++) { + String[] replicaRow = responseList.get(segmentsIndex).split(" +"); String replicaShardId = replicaRow[0] + replicaRow[1]; + // When segment has 0 doc count, not all replica copies posses that segment. Skip to next segment + if (replicaRow[2].equals("p")) { + assertTrue(primaryRow[4].equals("0")); + break; + } + // verify same shard id assertTrue(replicaShardId.equals(shardId)); // verify replica row assertTrue(replicaRow[2].equals("r")); @@ -113,6 +119,7 @@ private void waitForSearchableDocs(String index, int shardCount, int replicaCoun assertTrue(replicaRow[3].equals(primaryRow[3])); // Verify doc count matches assertTrue(replicaRow[4].equals(primaryRow[4])); + segmentsIndex++; } } });