Jackie-Jiang commented on code in PR #16067: URL: https://github.com/apache/pinot/pull/16067#discussion_r2150662514
########## pinot-common/src/main/java/org/apache/pinot/common/utils/LLCSegmentName.java: ########## @@ -152,4 +153,9 @@ public int hashCode() { public String toString() { return _segmentName; } + + @JsonValue Review Comment: (minor) Maybe just annotate `getSegmentName()`? ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java: ########## @@ -171,52 +177,109 @@ public String getSegmentsStatusDetails( return JsonUtils.objectToPrettyString(segmentStatusInfoListMap); } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/tables/{tableName}/badSegments") + @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action = Actions.Table.GET_SEGMENT_STATUS) + @ApiOperation(value = "Get bad segment names per partition group for a realtime table.", notes = "Get a sorted list" + + " of bad segments per partition group (sort order is in increasing order of segment sequence number)") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Returns a map of partition group IDs to the list of segment names in sorted" + + " order of sequence number"), + @ApiResponse(code = 500, message = "Internal Server Error") + }) + public String getBadSegments( + @ApiParam(value = "Name of the table.", required = true) @PathParam("tableName") String tableName, + @Context HttpHeaders headers) { + try { + tableName = DatabaseUtils.translateTableName(tableName, headers); + } catch (Exception e) { + throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.BAD_REQUEST); + } + String tableNameWithType = + ResourceUtils.getExistingTableNamesWithType(_pinotHelixResourceManager, tableName, TableType.REALTIME, LOGGER) + .get(0); + try { + TableViews.TableView idealStateView = getTableState(tableNameWithType, TableViews.IDEALSTATE, null); + TableViews.TableView externalView = getTableState(tableNameWithType, TableViews.EXTERNALVIEW, null); + + Map<String, Map<String, String>> idealStateMap = getStateMap(idealStateView); + Map<String, Map<String, String>> externalViewStateMap = getStateMap(externalView); + + List<SegmentStatusInfo> segmentStatusInfoList = getSegmentStatuses(externalViewStateMap, idealStateMap, + CommonConstants.Helix.StateModel.DisplaySegmentStatus.BAD); + + if (segmentStatusInfoList.isEmpty()) { + return JsonUtils.objectToPrettyString(new HashMap<>()); + } + + Map<Integer, SortedSet<LLCSegmentName>> partitionGroupIdToSegments = new HashMap<>(); + for (SegmentStatusInfo segmentStatusInfo : segmentStatusInfoList) { + String segmentName = segmentStatusInfo.getSegmentName(); + LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName); + Preconditions.checkNotNull(llcSegmentName, "Unable to convert segmentName to LLCSegment."); Review Comment: We shouldn't throw exception here. If the intention is to only collect bad LLC segment, we should skip other segments ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java: ########## @@ -171,52 +177,109 @@ public String getSegmentsStatusDetails( return JsonUtils.objectToPrettyString(segmentStatusInfoListMap); } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/tables/{tableName}/badSegments") Review Comment: Let's make the path more specific. Seems you are only collecting bad LLC segments, grouped on partition basis ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java: ########## @@ -171,52 +177,109 @@ public String getSegmentsStatusDetails( return JsonUtils.objectToPrettyString(segmentStatusInfoListMap); } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/tables/{tableName}/badSegments") + @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action = Actions.Table.GET_SEGMENT_STATUS) + @ApiOperation(value = "Get bad segment names per partition group for a realtime table.", notes = "Get a sorted list" Review Comment: Let's call it `partition` instead of `partition group`, same for other places -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org