Skip to content

Commit

Permalink
Add extra check around the uncertain case if hits==0
Browse files Browse the repository at this point in the history
Signed-off-by: Mikayla Thompson <[email protected]>
  • Loading branch information
mikaylathompson committed Oct 24, 2024
1 parent 1a926d1 commit f573157
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Check warning on line 439 in RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java

View check run for this annotation

Codecov / codecov/patch

RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java#L439

Added line #L439 was not covered by tests
}
return totalHits;
}
}

@Override
public int numWorkItemsNotYetComplete(Supplier<IWorkCoordinationContexts.IPendingWorkItemsContext> 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);

Check warning on line 449 in RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java

View check run for this annotation

Codecov / codecov/patch

RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java#L449

Added line #L449 was not covered by tests
}

Expand Down

0 comments on commit f573157

Please sign in to comment.