From d1cf4859df5749da8115e00b5055f47185b8c4b2 Mon Sep 17 00:00:00 2001 From: Mayank Shrivastava Date: Mon, 24 Jun 2024 12:50:46 -0700 Subject: [PATCH] Cleanup: Fix grammar in error message, also improve readability. (#13451) * Fixed grammar. * Now logging table name first, before the list of segments, for better readability. --- .../MultiStageBrokerRequestHandler.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java b/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java index 8e608473086b..d067749a1d5d 100644 --- a/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java +++ b/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java @@ -79,6 +79,7 @@ public class MultiStageBrokerRequestHandler extends BaseBrokerRequestHandler { private static final Logger LOGGER = LoggerFactory.getLogger(MultiStageBrokerRequestHandler.class); + private static final int NUM_UNAVAILABLE_SEGMENTS_TO_LOG = 10; private final WorkerManager _workerManager; private final QueryDispatcher _queryDispatcher; @@ -241,9 +242,11 @@ protected BrokerResponse handleRequest(long requestId, String query, @Nullable S for (Map.Entry> entry : dispatchableSubPlan.getTableToUnavailableSegmentsMap().entrySet()) { String tableName = entry.getKey(); Set unavailableSegments = entry.getValue(); - numUnavailableSegments += unavailableSegments.size(); + int unavailableSegmentsInSubPlan = unavailableSegments.size(); + numUnavailableSegments += unavailableSegmentsInSubPlan; brokerResponse.addException(QueryException.getException(QueryException.SERVER_SEGMENT_MISSING_ERROR, - String.format("Find unavailable segments: %s for table: %s", unavailableSegments, tableName))); + String.format("Found %d unavailable segments for table %s: %s", unavailableSegmentsInSubPlan, tableName, + toSizeLimitedString(unavailableSegments, NUM_UNAVAILABLE_SEGMENTS_TO_LOG)))); } requestContext.setNumUnavailableSegments(numUnavailableSegments); @@ -359,4 +362,15 @@ public boolean cancelQuery(long queryId, int timeoutMs, Executor executor, HttpC // TODO: Support query cancellation for multi-stage engine throw new UnsupportedOperationException(); } + + /** + * Returns the string representation of the Set of Strings with a limit on the number of elements. + * @param setOfStrings Set of strings + * @param limit Limit on the number of elements + * @return String representation of the set of the form [a,b,c...]. + */ + private static String toSizeLimitedString(Set setOfStrings, int limit) { + return setOfStrings.stream().limit(limit) + .collect(Collectors.joining(", ", "[", setOfStrings.size() > limit ? "...]" : "]")); + } }