From f57315797cb867709b848d4229d556b31d428340 Mon Sep 17 00:00:00 2001 From: Mikayla Thompson Date: Thu, 24 Oct 2024 16:16:43 -0600 Subject: [PATCH] Add extra check around the uncertain case if hits==0 Signed-off-by: Mikayla Thompson --- .../workcoordination/OpenSearchWorkCoordinator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java index 7947c4d1b..4f33b9d73 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java @@ -431,13 +431,21 @@ private int numWorkItemsNotYetCompleteInternal( + " instead of 200" ); } - return objectMapper.readTree(response.getPayloadBytes()).path("hits").path("total").path("value").asInt(); + var payload = objectMapper.readTree(response.getPayloadBytes()); + var totalHits = payload.path("hits").path("total").path("value").asInt(); + // In the case where totalHits is 0, we need to be particularly sure that we're not missing data. The `relation` + // for the total must be `eq` or we need to throw an error because it's not safe to rely on this data. + if (totalHits == 0 && !payload.path("hits").path("total").path("relation").textValue().equals("eq")) { + throw new IllegalStateException("Querying for notYetCompleted work returned 0 hits with an unexpected total relation."); + } + return totalHits; } } @Override public int numWorkItemsNotYetComplete(Supplier contextSupplier) throws IOException, InterruptedException { + // This result is not guaranteed to be accurate unless it is 0. All numbers greater than 0 are a lower bound. return numWorkItemsNotYetCompleteInternal(contextSupplier); }