saurabhd336 commented on code in PR #11576:
URL: https://github.com/apache/pinot/pull/11576#discussion_r1328232706
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java:
##########
@@ -964,6 +965,77 @@ public String getTableAggregateMetadata(
return segmentsMetadata;
}
+ @GET
+ @Path("tables/{tableName}/indexes")
+ @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action =
Actions.Table.GET_METADATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get the aggregate index details of all segments for a
table", notes = "Get the aggregate "
+ + "index details of all segments for a table")
+ public String getTableIndexes(
+ @ApiParam(value = "Name of the table", required = true)
@PathParam("tableName") String tableName,
+ @ApiParam(value = "OFFLINE|REALTIME") @QueryParam("type") String
tableTypeStr) {
+ LOGGER.info("Received a request to fetch aggregate metadata for a table
{}", tableName);
+ TableType tableType = Constants.validateTableType(tableTypeStr);
+ String tableNameWithType =
+
ResourceUtils.getExistingTableNamesWithType(_pinotHelixResourceManager,
tableName, tableType, LOGGER).get(0);
+
+ String tableIndexMetadata;
+ try {
+ JsonNode segmentsMetadataJson =
getAggregateIndexMetadataFromServer(tableNameWithType);
+ tableIndexMetadata =
JsonUtils.objectToPrettyString(segmentsMetadataJson);
+ } catch (InvalidConfigException e) {
+ throw new ControllerApplicationException(LOGGER, e.getMessage(),
Response.Status.BAD_REQUEST);
+ } catch (IOException ioe) {
+ throw new ControllerApplicationException(LOGGER, "Error parsing Pinot
server response: " + ioe.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR, ioe);
+ }
+ return tableIndexMetadata;
+ }
+
+ private JsonNode getAggregateIndexMetadataFromServer(String
tableNameWithType)
+ throws InvalidConfigException, JsonProcessingException {
+ final Map<String, List<String>> serverToSegments =
+ _pinotHelixResourceManager.getServerToSegmentsMap(tableNameWithType);
+ BiMap<String, String> endpoints =
+
_pinotHelixResourceManager.getDataInstanceAdminEndpoints(serverToSegments.keySet());
+
+ BiMap<String, String> serverEndPoints =
+
_pinotHelixResourceManager.getDataInstanceAdminEndpoints(serverToSegments.keySet());
+ CompletionServiceHelper completionServiceHelper =
+ new CompletionServiceHelper(_executor, _connectionManager,
serverEndPoints);
+
+ List<String> serverUrls = new ArrayList<>();
+ BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
+ for (String endpoint : endpointsToServers.keySet()) {
+ String reloadTaskStatusEndpoint = endpoint +
String.format("/tables/%s/indexes", tableNameWithType);
+ serverUrls.add(reloadTaskStatusEndpoint);
+ }
+
+ CompletionServiceHelper.CompletionServiceResponse serviceResponse =
+ completionServiceHelper.doMultiGetRequest(serverUrls, null, true,
10000);
+
+ long totalSegments = 0;
+ Map<String, Map<String, Long>> columnToIndexCountMap = new HashMap<>();
+ for (Map.Entry<String, String> streamResponse :
serviceResponse._httpResponses.entrySet()) {
+ String responseString = streamResponse.getValue();
+ TableIndexMetadataResponse response =
JsonUtils.stringToObject(responseString, TableIndexMetadataResponse.class);
+ totalSegments += response.getTotalOnlineSegments();
+ response.getColumnToIndexesCount().forEach((col, indexToCount) -> {
+ columnToIndexCountMap.putIfAbsent(col, new HashMap<>());
+
+ indexToCount.forEach((indexName, count) -> {
+ columnToIndexCountMap.get(col)
+ .put(indexName,
columnToIndexCountMap.get(col).getOrDefault(indexName, 0L) + count);
+ });
Review Comment:
Ack
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]