Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show table metadata info in aggregate index size form #9733

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ public class TableMetadataInfo {
private final Map<String, Double> _columnLengthMap;
private final Map<String, Double> _columnCardinalityMap;
private final Map<String, Double> _maxNumMultiValuesMap;
private final Map<String, Map<String, Double>> _columnIndexSizeMap;

@JsonCreator
public TableMetadataInfo(@JsonProperty("tableName") String tableName,
@JsonProperty("diskSizeInBytes") long sizeInBytes, @JsonProperty("numSegments") long numSegments,
@JsonProperty("numRows") long numRows, @JsonProperty("columnLengthMap") Map<String, Double> columnLengthMap,
@JsonProperty("columnCardinalityMap") Map<String, Double> columnCardinalityMap,
@JsonProperty("maxNumMultiValuesMap") Map<String, Double> maxNumMultiValuesMap) {
@JsonProperty("maxNumMultiValuesMap") Map<String, Double> maxNumMultiValuesMap,
@JsonProperty("columnIndexSizeMap") Map<String, Map<String, Double>> columnIndexSizeMap) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this Nullable property?

Copy link
Contributor Author

@walterddr walterddr Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columnIndexSize map will not be null. it will be empty if there's no index scheme. but unless a pinot table contains all non-dictionary columns, at least it will show the forward index size and dictionary size for some columns

_tableName = tableName;
_diskSizeInBytes = sizeInBytes;
_numSegments = numSegments;
_numRows = numRows;
_columnLengthMap = columnLengthMap;
_columnCardinalityMap = columnCardinalityMap;
_maxNumMultiValuesMap = maxNumMultiValuesMap;
_columnIndexSizeMap = columnIndexSizeMap;
}

public String getTableName() {
Expand Down Expand Up @@ -85,4 +88,8 @@ public Map<String, Double> getColumnCardinalityMap() {
public Map<String, Double> getMaxNumMultiValuesMap() {
return _maxNumMultiValuesMap;
}

public Map<String, Map<String, Double>> getColumnIndexSizeMap() {
return _columnIndexSizeMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public TableMetadataInfo getAggregatedTableMetadataFromServer(String tableNameWi
final Map<String, Double> columnLengthMap = new HashMap<>();
final Map<String, Double> columnCardinalityMap = new HashMap<>();
final Map<String, Double> maxNumMultiValuesMap = new HashMap<>();
final Map<String, Map<String, Double>> columnIndexSizeMap = new HashMap<>();
for (Map.Entry<String, String> streamResponse : serviceResponse._httpResponses.entrySet()) {
try {
TableMetadataInfo tableMetadataInfo =
Expand All @@ -98,6 +99,12 @@ public TableMetadataInfo getAggregatedTableMetadataFromServer(String tableNameWi
tableMetadataInfo.getColumnLengthMap().forEach((k, v) -> columnLengthMap.merge(k, v, Double::sum));
tableMetadataInfo.getColumnCardinalityMap().forEach((k, v) -> columnCardinalityMap.merge(k, v, Double::sum));
tableMetadataInfo.getMaxNumMultiValuesMap().forEach((k, v) -> maxNumMultiValuesMap.merge(k, v, Double::sum));
tableMetadataInfo.getColumnIndexSizeMap().forEach((k, v) -> columnIndexSizeMap.merge(k, v, (l, r) -> {
for (Map.Entry<String, Double> e : r.entrySet()) {
l.put(e.getKey(), l.getOrDefault(e.getKey(), 0d) + e.getValue());
}
return l;
}));
} catch (IOException e) {
failedParses++;
LOGGER.error("Unable to parse server {} response due to an error: ", streamResponse.getKey(), e);
Expand All @@ -107,6 +114,10 @@ public TableMetadataInfo getAggregatedTableMetadataFromServer(String tableNameWi
columnLengthMap.replaceAll((k, v) -> v / finalTotalNumSegments);
columnCardinalityMap.replaceAll((k, v) -> v / finalTotalNumSegments);
maxNumMultiValuesMap.replaceAll((k, v) -> v / finalTotalNumSegments);
columnIndexSizeMap.replaceAll((k, v) -> {
v.replaceAll((key, value) -> v.get(key) / finalTotalNumSegments);
return v;
});

// Since table segments may have multiple replicas, divide diskSizeInBytes, numRows and numSegments by numReplica
// to avoid double counting, for columnAvgLengthMap, columnAvgCardinalityMap and maxNumMultiValuesMap, dividing by
Expand All @@ -117,7 +128,7 @@ public TableMetadataInfo getAggregatedTableMetadataFromServer(String tableNameWi

TableMetadataInfo aggregateTableMetadataInfo =
new TableMetadataInfo(tableNameWithType, totalDiskSizeInBytes, totalNumSegments, totalNumRows, columnLengthMap,
columnCardinalityMap, maxNumMultiValuesMap);
columnCardinalityMap, maxNumMultiValuesMap, columnIndexSizeMap);
if (failedParses != 0) {
LOGGER.warn("Failed to parse {} / {} aggregated segment metadata responses from servers.", failedParses,
serverUrls.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.ImmutableSegment;
import org.apache.pinot.segment.spi.index.metadata.SegmentMetadataImpl;
import org.apache.pinot.segment.spi.store.ColumnIndexType;
import org.apache.pinot.server.access.AccessControl;
import org.apache.pinot.server.access.AccessControlFactory;
import org.apache.pinot.server.access.HttpRequesterIdentity;
Expand Down Expand Up @@ -210,6 +211,7 @@ public String getSegmentMetadata(
Map<String, Double> columnLengthMap = new HashMap<>();
Map<String, Double> columnCardinalityMap = new HashMap<>();
Map<String, Double> maxNumMultiValuesMap = new HashMap<>();
Map<String, Map<String, Double>> columnIndexSizesMap = new HashMap<>();
try {
for (SegmentDataManager segmentDataManager : segmentDataManagers) {
if (segmentDataManager instanceof ImmutableSegmentDataManager) {
Expand Down Expand Up @@ -256,6 +258,13 @@ public String getSegmentMetadata(
int maxNumMultiValues = columnMetadata.getMaxNumberOfMultiValues();
maxNumMultiValuesMap.merge(column, (double) maxNumMultiValues, Double::sum);
}
for (Map.Entry<ColumnIndexType, Long> entry : columnMetadata.getIndexSizeMap().entrySet()) {
String indexName = entry.getKey().getIndexName();
Map<String, Double> columnIndexSizes = columnIndexSizesMap.getOrDefault(column, new HashMap<>());
Double indexSize = columnIndexSizes.getOrDefault(indexName, 0d) + entry.getValue();
columnIndexSizes.put(indexName, indexSize);
columnIndexSizesMap.put(column, columnIndexSizes);
}
}
}
}
Expand All @@ -270,7 +279,7 @@ public String getSegmentMetadata(

TableMetadataInfo tableMetadataInfo =
new TableMetadataInfo(tableDataManager.getTableName(), totalSegmentSizeBytes, segmentDataManagers.size(),
totalNumRows, columnLengthMap, columnCardinalityMap, maxNumMultiValuesMap);
totalNumRows, columnLengthMap, columnCardinalityMap, maxNumMultiValuesMap, columnIndexSizesMap);
return ResourceUtils.convertToJsonString(tableMetadataInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.commons.io.FileUtils;
import org.apache.pinot.common.restlet.resources.TableMetadataInfo;
import org.apache.pinot.common.restlet.resources.TableSegments;
import org.apache.pinot.common.restlet.resources.TablesList;
import org.apache.pinot.common.utils.TarGzCompressionUtils;
Expand All @@ -32,6 +33,7 @@
import org.apache.pinot.segment.spi.SegmentMetadata;
import org.apache.pinot.segment.spi.V1Constants;
import org.apache.pinot.segment.spi.index.metadata.SegmentMetadataImpl;
import org.apache.pinot.segment.spi.store.ColumnIndexType;
import org.apache.pinot.spi.utils.JsonUtils;
import org.apache.pinot.spi.utils.builder.TableNameBuilder;
import org.testng.Assert;
Expand Down Expand Up @@ -99,6 +101,38 @@ public void getSegments()
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}

@Test
public void getTableMetadata()
throws Exception {
String tableMetadataPath = "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/metadata";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this API for both REALTIME and OFFLINE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wilco


JsonNode jsonResponse =
JsonUtils.stringToJsonNode(_webTarget.path(tableMetadataPath).request().get(String.class));
TableMetadataInfo metadataInfo = JsonUtils.jsonNodeToObject(jsonResponse, TableMetadataInfo.class);
Assert.assertNotNull(metadataInfo);
Assert.assertEquals(metadataInfo.getNumSegments(), 2);
Assert.assertEquals(metadataInfo.getTableName(), TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME));
Assert.assertEquals(metadataInfo.getColumnLengthMap().size(), 0);
Assert.assertEquals(metadataInfo.getColumnCardinalityMap().size(), 0);
Assert.assertEquals(metadataInfo.getColumnIndexSizeMap().size(), 0);

jsonResponse = JsonUtils.stringToJsonNode(_webTarget.path(tableMetadataPath)
.queryParam("columns", "column1").queryParam("columns", "column2").request().get(String.class));
metadataInfo = JsonUtils.jsonNodeToObject(jsonResponse, TableMetadataInfo.class);
Assert.assertEquals(metadataInfo.getColumnLengthMap().size(), 2);
Assert.assertEquals(metadataInfo.getColumnCardinalityMap().size(), 2);
Assert.assertEquals(metadataInfo.getColumnIndexSizeMap().size(), 2);
Assert.assertTrue(metadataInfo.getColumnIndexSizeMap().get("column1")
.containsKey(ColumnIndexType.DICTIONARY.getIndexName()));
Assert.assertTrue(metadataInfo.getColumnIndexSizeMap().get("column2")
.containsKey(ColumnIndexType.FORWARD_INDEX.getIndexName()));

// No such table
Response response = _webTarget.path("/tables/noSuchTable/metadata").request().get(Response.class);
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}

@Test
public void testSegmentMetadata()
throws Exception {
Expand All @@ -124,6 +158,8 @@ public void testSegmentMetadata()
.get(String.class));
Assert.assertEquals(jsonResponse.get("columns").size(), 2);
Assert.assertEquals(jsonResponse.get("indexes").size(), 2);
Assert.assertNotNull(jsonResponse.get("columns").get(0).get("indexSizeMap"));
Assert.assertNotNull(jsonResponse.get("columns").get(1).get("indexSizeMap"));

jsonResponse = JsonUtils.stringToJsonNode(
(_webTarget.path(segmentMetadataPath).queryParam("columns", "*").request().get(String.class)));
Expand Down