siddharthteotia commented on a change in pull request #7102:
URL: https://github.com/apache/incubator-pinot/pull/7102#discussion_r668180843
##########
File path:
pinot-server/src/main/java/org/apache/pinot/server/api/resources/TablesResource.java
##########
@@ -117,6 +126,103 @@ public String listTableSegments(
}
}
+ @GET
+ @Encoded
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/tables/{tableName}/metadata")
+ @ApiOperation(value = "List metadata for all segments of a given table",
notes = "List segments metadata of table hosted on this server")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code
= 404, message = "Table not found")})
+ public String getTableSize(
Review comment:
(nit) suggest renaming this
##########
File path:
pinot-controller/src/main/java/org/apache/pinot/controller/util/ServerSegmentMetadataReader.java
##########
@@ -47,6 +51,73 @@ public ServerSegmentMetadataReader(Executor executor,
HttpConnectionManager conn
_connectionManager = connectionManager;
}
+ /**
+ * This method is called when the API request is to fetch aggregated segment
metadata for all segments of the table.
+ * This method makes a MultiGet call to all servers that host their
respective segments and gets the results.
+ * This method accept a list of column names as filter, and will return
column metadata for the column in the
+ * list.
+ * TODO Some performance improvement ideas to explore:
+ * - If table has replica groups, only send requests to one replica group.
+ * - If table does not have replica groups, send requests to a minimal set
of servers hosting all segments of the
+ * table.
+ */
+ public AggregateTableMetadataInfo
getAggregatedTableMetadataFromServer(String tableNameWithType,
+ BiMap<String, String> serverEndPoints, List<String> columns, int
numReplica, int timeoutMs) {
+ int numServers = serverEndPoints.size();
+ LOGGER.info("Reading aggregated segment metadata from {} servers for
table: {} with timeout: {}ms", numServers,
+ tableNameWithType, timeoutMs);
+
+ List<String> serverUrls = new ArrayList<>(numServers);
+ BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
+ for (String endpoint : endpointsToServers.keySet()) {
+ String serverUrl =
generateAggregateSegmentMetadataServerURL(tableNameWithType, columns, endpoint);
+ serverUrls.add(serverUrl);
+ }
+
+ // Helper service to run a http get call to the server
+ CompletionServiceHelper completionServiceHelper =
+ new CompletionServiceHelper(_executor, _connectionManager,
endpointsToServers);
+ CompletionServiceHelper.CompletionServiceResponse serviceResponse =
+ completionServiceHelper.doMultiGetRequest(serverUrls,
tableNameWithType, false, timeoutMs);
+
+ AggregateTableMetadataInfo aggregateTableMetadataInfo = new
AggregateTableMetadataInfo();
+ int totalNumSegments = 0;
+ int failedParses = 0;
+ for (Map.Entry<String, String> streamResponse :
serviceResponse._httpResponses.entrySet()) {
+ try {
+ TableMetadataInfo tableMetadataInfo =
+ JsonUtils.stringToObject(streamResponse.getValue(),
TableMetadataInfo.class);
+ aggregateTableMetadataInfo.diskSizeInBytes +=
tableMetadataInfo.diskSizeInBytes;
+ aggregateTableMetadataInfo.numRows += tableMetadataInfo.numRows;
+ totalNumSegments += tableMetadataInfo.numSegments;
+ tableMetadataInfo.columnLengthMap
+ .forEach((k, v) ->
aggregateTableMetadataInfo.columnAvgLengthMap.merge(k, (double) v,
Double::sum));
+ tableMetadataInfo.columnCardinalityMap
+ .forEach((k, v) ->
aggregateTableMetadataInfo.columnAvgCardinalityMap.merge(k, (double) v,
Double::sum));
+ } catch (IOException e) {
+ failedParses++;
+ LOGGER.error("Unable to parse server {} response due to an error: ",
streamResponse.getKey(), e);
+ }
+ }
+
+ final int finalTotalNumSegments = totalNumSegments;
+ aggregateTableMetadataInfo.numSegments = finalTotalNumSegments;
+ aggregateTableMetadataInfo.columnAvgLengthMap.replaceAll((k, v) -> v * 1.0
/ finalTotalNumSegments);
+ aggregateTableMetadataInfo.columnAvgCardinalityMap.replaceAll((k, v) -> v
* 1.0 / finalTotalNumSegments);
+
+ // Since table segments may have multiple replicas, divide by numReplica
to avoid double counting.
+ aggregateTableMetadataInfo.diskSizeInBytes /= numReplica;
+ aggregateTableMetadataInfo.numSegments /= numReplica;
+ aggregateTableMetadataInfo.columnAvgLengthMap.replaceAll((k, v) -> v /
numReplica);
Review comment:
Remove lines 111 and 112 as discussed offline
##########
File path:
pinot-controller/src/main/java/org/apache/pinot/controller/util/ServerSegmentMetadataReader.java
##########
@@ -47,6 +51,73 @@ public ServerSegmentMetadataReader(Executor executor,
HttpConnectionManager conn
_connectionManager = connectionManager;
}
+ /**
+ * This method is called when the API request is to fetch aggregated segment
metadata for all segments of the table.
+ * This method makes a MultiGet call to all servers that host their
respective segments and gets the results.
+ * This method accept a list of column names as filter, and will return
column metadata for the column in the
+ * list.
+ * TODO Some performance improvement ideas to explore:
+ * - If table has replica groups, only send requests to one replica group.
+ * - If table does not have replica groups, send requests to a minimal set
of servers hosting all segments of the
+ * table.
+ */
+ public AggregateTableMetadataInfo
getAggregatedTableMetadataFromServer(String tableNameWithType,
+ BiMap<String, String> serverEndPoints, List<String> columns, int
numReplica, int timeoutMs) {
+ int numServers = serverEndPoints.size();
+ LOGGER.info("Reading aggregated segment metadata from {} servers for
table: {} with timeout: {}ms", numServers,
+ tableNameWithType, timeoutMs);
+
+ List<String> serverUrls = new ArrayList<>(numServers);
+ BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
+ for (String endpoint : endpointsToServers.keySet()) {
+ String serverUrl =
generateAggregateSegmentMetadataServerURL(tableNameWithType, columns, endpoint);
+ serverUrls.add(serverUrl);
+ }
+
+ // Helper service to run a http get call to the server
+ CompletionServiceHelper completionServiceHelper =
+ new CompletionServiceHelper(_executor, _connectionManager,
endpointsToServers);
+ CompletionServiceHelper.CompletionServiceResponse serviceResponse =
+ completionServiceHelper.doMultiGetRequest(serverUrls,
tableNameWithType, false, timeoutMs);
+
+ AggregateTableMetadataInfo aggregateTableMetadataInfo = new
AggregateTableMetadataInfo();
+ int totalNumSegments = 0;
+ int failedParses = 0;
+ for (Map.Entry<String, String> streamResponse :
serviceResponse._httpResponses.entrySet()) {
+ try {
+ TableMetadataInfo tableMetadataInfo =
+ JsonUtils.stringToObject(streamResponse.getValue(),
TableMetadataInfo.class);
+ aggregateTableMetadataInfo.diskSizeInBytes +=
tableMetadataInfo.diskSizeInBytes;
+ aggregateTableMetadataInfo.numRows += tableMetadataInfo.numRows;
+ totalNumSegments += tableMetadataInfo.numSegments;
+ tableMetadataInfo.columnLengthMap
+ .forEach((k, v) ->
aggregateTableMetadataInfo.columnAvgLengthMap.merge(k, (double) v,
Double::sum));
+ tableMetadataInfo.columnCardinalityMap
+ .forEach((k, v) ->
aggregateTableMetadataInfo.columnAvgCardinalityMap.merge(k, (double) v,
Double::sum));
+ } catch (IOException e) {
+ failedParses++;
+ LOGGER.error("Unable to parse server {} response due to an error: ",
streamResponse.getKey(), e);
+ }
+ }
+
+ final int finalTotalNumSegments = totalNumSegments;
Review comment:
(nit) we don't use final in our current coding guidelines so suggest
removing it
##########
File path:
pinot-common/src/main/java/org/apache/pinot/common/restlet/resources/TableMetadataInfo.java
##########
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.restlet.resources;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import java.util.HashMap;
+import java.util.Map;
+
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class TableMetadataInfo {
Review comment:
We can just keep this class and remove AggregateTableMetadataInfo class.
Please add javadocs indicating that server is returning total info and how
controller takes the average for length and cardinality, sum for rows, disk size
--
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]