Skip to content

Commit

Permalink
handle table name translation on missed api resources
Browse files Browse the repository at this point in the history
  • Loading branch information
shounakmk219 committed Apr 4, 2024
1 parent 4306a6f commit 1973cdf
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.pinot.broker.broker.AccessControlFactory;
import org.apache.pinot.broker.routing.BrokerRoutingManager;
import org.apache.pinot.common.request.BrokerRequest;
import org.apache.pinot.common.utils.DatabaseUtils;
import org.apache.pinot.core.auth.Actions;
import org.apache.pinot.core.auth.Authorize;
import org.apache.pinot.core.auth.ManualAuthorization;
Expand All @@ -60,12 +61,18 @@
import org.apache.pinot.spi.utils.builder.TableNameBuilder;
import org.apache.pinot.sql.parsers.CalciteSqlCompiler;

import static org.apache.pinot.spi.utils.CommonConstants.DATABASE;
import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY;


@Api(tags = "Debug", authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = @ApiKeyAuthDefinition(name =
HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = SWAGGER_AUTHORIZATION_KEY)))
@Api(tags = "Debug", authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY),
@Authorization(value = DATABASE)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = {
@ApiKeyAuthDefinition(name = HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER,
key = SWAGGER_AUTHORIZATION_KEY),
@ApiKeyAuthDefinition(name = DATABASE, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = DATABASE,
description = "Database context passed through http header. If no context is provided 'default' database "
+ "context will be considered.")}))
@Path("/")
// TODO: Add APIs to return the RoutingTable (with unavailable segments)
public class PinotBrokerDebug {
Expand Down Expand Up @@ -93,7 +100,9 @@ public class PinotBrokerDebug {
@ApiResponse(code = 500, message = "Internal server error")
})
public TimeBoundaryInfo getTimeBoundary(
@ApiParam(value = "Name of the table") @PathParam("tableName") String tableName) {
@ApiParam(value = "Name of the table") @PathParam("tableName") String tableName,
@Context HttpHeaders headers) {
tableName = DatabaseUtils.translateTableName(tableName, headers);
String offlineTableName =
TableNameBuilder.OFFLINE.tableNameWithType(TableNameBuilder.extractRawTableName(tableName));
TimeBoundaryInfo timeBoundaryInfo = _routingManager.getTimeBoundaryInfo(offlineTableName);
Expand All @@ -115,7 +124,9 @@ public TimeBoundaryInfo getTimeBoundary(
@ApiResponse(code = 500, message = "Internal server error")
})
public Map<String, Map<ServerInstance, List<String>>> getRoutingTable(
@ApiParam(value = "Name of the table") @PathParam("tableName") String tableName) {
@ApiParam(value = "Name of the table") @PathParam("tableName") String tableName,
@Context HttpHeaders headers) {
tableName = DatabaseUtils.translateTableName(tableName, headers);
Map<String, Map<ServerInstance, List<String>>> result = new TreeMap<>();
getRoutingTable(tableName, (tableNameWithType, routingTable) -> result.put(tableNameWithType,
removeOptionalSegments(routingTable.getServerInstanceToSegmentsMap())));
Expand All @@ -137,7 +148,9 @@ public Map<String, Map<ServerInstance, List<String>>> getRoutingTable(
@ApiResponse(code = 500, message = "Internal server error")
})
public Map<String, Map<ServerInstance, Pair<List<String>, List<String>>>> getRoutingTableWithOptionalSegments(
@ApiParam(value = "Name of the table") @PathParam("tableName") String tableName) {
@ApiParam(value = "Name of the table") @PathParam("tableName") String tableName,
@Context HttpHeaders headers) {
tableName = DatabaseUtils.translateTableName(tableName, headers);
Map<String, Map<ServerInstance, Pair<List<String>, List<String>>>> result = new TreeMap<>();
getRoutingTable(tableName, (tableNameWithType, routingTable) -> result.put(tableNameWithType,
routingTable.getServerInstanceToSegmentsMap()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.pinot.common.metrics.ControllerMetrics;
import org.apache.pinot.common.utils.DatabaseUtils;
import org.apache.pinot.controller.ControllerConf;
import org.apache.pinot.controller.api.exception.ControllerApplicationException;
import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
Expand All @@ -48,12 +50,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.pinot.spi.utils.CommonConstants.DATABASE;
import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY;


@Api(tags = Constants.TABLE_TAG, authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = @ApiKeyAuthDefinition(name =
HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = SWAGGER_AUTHORIZATION_KEY)))
@Api(tags = Constants.TABLE_TAG, authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY),
@Authorization(value = DATABASE)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = {
@ApiKeyAuthDefinition(name = HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER,
key = SWAGGER_AUTHORIZATION_KEY),
@ApiKeyAuthDefinition(name = DATABASE, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = DATABASE,
description = "Database context passed through http header. If no context is provided 'default' database "
+ "context will be considered.")}))
@Path("/")
public class TableSize {
private static final Logger LOGGER = LoggerFactory.getLogger(TableSize.class);
Expand Down Expand Up @@ -82,7 +90,8 @@ public class TableSize {
})
public TableSizeReader.TableSizeDetails getTableSize(
@ApiParam(value = "Table name without type", required = true, example = "myTable | myTable_OFFLINE")
@PathParam("tableName") String tableName) {
@PathParam("tableName") String tableName, @Context HttpHeaders headers) {
tableName = DatabaseUtils.translateTableName(tableName, headers);
TableSizeReader tableSizeReader =
new TableSizeReader(_executor, _connectionManager, _controllerMetrics, _pinotHelixResourceManager);
TableSizeReader.TableSizeDetails tableSizeDetails = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.pinot.common.utils.DatabaseUtils;
import org.apache.pinot.controller.api.exception.ControllerApplicationException;
import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
import org.apache.pinot.core.auth.Actions;
Expand All @@ -50,12 +52,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.pinot.spi.utils.CommonConstants.DATABASE;
import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY;


@Api(tags = Constants.TABLE_TAG, authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = @ApiKeyAuthDefinition(name =
HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = SWAGGER_AUTHORIZATION_KEY)))
@Api(tags = Constants.TABLE_TAG, authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY),
@Authorization(value = DATABASE)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = {
@ApiKeyAuthDefinition(name = HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER,
key = SWAGGER_AUTHORIZATION_KEY),
@ApiKeyAuthDefinition(name = DATABASE, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = DATABASE,
description = "Database context passed through http header. If no context is provided 'default' database "
+ "context will be considered.")}))
@Path("/")
public class TableViews {

Expand All @@ -80,7 +88,9 @@ public static class TableView {
@ApiOperation(value = "Get table ideal state", notes = "Get table ideal state")
public TableView getIdealState(
@ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName,
@ApiParam(value = "realtime|offline", required = false) @QueryParam("tableType") String tableTypeStr) {
@ApiParam(value = "realtime|offline", required = false) @QueryParam("tableType") String tableTypeStr,
@Context HttpHeaders headers) {
tableName = DatabaseUtils.translateTableName(tableName, headers);
TableType tableType = validateTableType(tableTypeStr);
return getTableState(tableName, IDEALSTATE, tableType);
}
Expand All @@ -92,7 +102,9 @@ public TableView getIdealState(
@ApiOperation(value = "Get table external view", notes = "Get table external view")
public TableView getExternalView(
@ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName,
@ApiParam(value = "realtime|offline", required = false) @QueryParam("tableType") String tableTypeStr) {
@ApiParam(value = "realtime|offline", required = false) @QueryParam("tableType") String tableTypeStr,
@Context HttpHeaders headers) {
tableName = DatabaseUtils.translateTableName(tableName, headers);
TableType tableType = validateTableType(tableTypeStr);
return getTableState(tableName, EXTERNALVIEW, tableType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.apache.pinot.common.utils.DatabaseUtils;
import org.apache.pinot.segment.local.data.manager.SegmentDataManager;
import org.apache.pinot.segment.local.data.manager.TableDataManager;
import org.apache.pinot.server.starter.ServerInstance;
Expand All @@ -48,8 +51,10 @@ public class ControllerJobStatusResource {
@ApiOperation(value = "Task status", notes = "Return the status of a given reload job")
public String reloadJobStatus(@PathParam("tableNameWithType") String tableNameWithType,
@QueryParam("reloadJobTimestamp") long reloadJobSubmissionTimestamp,
@QueryParam("segmentName") String segmentName)
@QueryParam("segmentName") String segmentName,
@Context HttpHeaders headers)
throws Exception {
tableNameWithType = DatabaseUtils.translateTableName(tableNameWithType, headers);
TableDataManager tableDataManager =
ServerResourceUtils.checkGetTableDataManager(_serverInstance, tableNameWithType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.apache.commons.io.FileUtils;
import org.apache.pinot.common.restlet.resources.SegmentConsumerInfo;
import org.apache.pinot.common.restlet.resources.SegmentErrorInfo;
import org.apache.pinot.common.restlet.resources.SegmentServerDebugInfo;
import org.apache.pinot.common.utils.DatabaseUtils;
import org.apache.pinot.core.data.manager.offline.ImmutableSegmentDataManager;
import org.apache.pinot.core.data.manager.realtime.RealtimeSegmentDataManager;
import org.apache.pinot.segment.local.data.manager.SegmentDataManager;
Expand All @@ -54,15 +56,21 @@
import org.apache.pinot.spi.stream.ConsumerPartitionState;
import org.apache.pinot.spi.utils.builder.TableNameBuilder;

import static org.apache.pinot.spi.utils.CommonConstants.DATABASE;
import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY;


/**
* Debug resource for Pinot Server.
*/
@Api(tags = "Debug", authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = @ApiKeyAuthDefinition(name =
HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = SWAGGER_AUTHORIZATION_KEY)))
@Api(tags = "Debug", authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY),
@Authorization(value = DATABASE)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = {
@ApiKeyAuthDefinition(name = HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER,
key = SWAGGER_AUTHORIZATION_KEY),
@ApiKeyAuthDefinition(name = DATABASE, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = DATABASE,
description = "Database context passed through http header. If no context is provided 'default' database "
+ "context will be considered.")}))
@Path("/debug/")
public class DebugResource {

Expand All @@ -76,7 +84,8 @@ public class DebugResource {
notes = "This is a debug endpoint, and won't maintain backward compatibility")
public List<SegmentServerDebugInfo> getSegmentsDebugInfo(
@ApiParam(value = "Name of the table (with type)", required = true) @PathParam("tableName")
String tableNameWithType) {
String tableNameWithType, @Context HttpHeaders headers) {
tableNameWithType = DatabaseUtils.translateTableName(tableNameWithType, headers);
TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableNameWithType);
return getSegmentServerDebugInfo(tableNameWithType, tableType);
}
Expand All @@ -89,7 +98,9 @@ public List<SegmentServerDebugInfo> getSegmentsDebugInfo(
public SegmentServerDebugInfo getSegmentDebugInfo(
@ApiParam(value = "Name of the table (with type)", required = true) @PathParam("tableName")
String tableNameWithType,
@ApiParam(value = "Name of the segment", required = true) @PathParam("segmentName") String segmentName) {
@ApiParam(value = "Name of the segment", required = true) @PathParam("segmentName") String segmentName,
@Context HttpHeaders headers) {
tableNameWithType = DatabaseUtils.translateTableName(tableNameWithType, headers);
TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableNameWithType);
TableDataManager tableDataManager =
ServerResourceUtils.checkGetTableDataManager(_serverInstance, tableNameWithType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,35 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.pinot.common.restlet.resources.ResourceUtils;
import org.apache.pinot.common.utils.DatabaseUtils;
import org.apache.pinot.core.data.manager.InstanceDataManager;
import org.apache.pinot.core.data.manager.realtime.RealtimeTableDataManager;
import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
import org.apache.pinot.server.starter.ServerInstance;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.utils.builder.TableNameBuilder;

import static org.apache.pinot.spi.utils.CommonConstants.DATABASE;
import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY;


/**
* Debug endpoint to check memory allocation.
*/
@Api(value = "debug", description = "Debug information", tags = "Debug",
authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = @ApiKeyAuthDefinition(name =
HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = SWAGGER_AUTHORIZATION_KEY)))
authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY),
@Authorization(value = DATABASE)})
@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = {
@ApiKeyAuthDefinition(name = HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER,
key = SWAGGER_AUTHORIZATION_KEY),
@ApiKeyAuthDefinition(name = DATABASE, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = DATABASE,
description = "Database context passed through http header. If no context is provided 'default' database "
+ "context will be considered.")}))
@Path("debug")
public class MmapDebugResource {

Expand Down Expand Up @@ -83,8 +91,10 @@ public List<String> getOffHeapSizes() {
@ApiResponse(code = 404, message = "Table not found")
})
public String getTableSize(
@ApiParam(value = "Table Name with type", required = true) @PathParam("tableName") String tableName)
@ApiParam(value = "Table Name with type", required = true) @PathParam("tableName") String tableName,
@Context HttpHeaders headers)
throws WebApplicationException {
tableName = DatabaseUtils.translateTableName(tableName, headers);
TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableName);
if (tableType != TableType.REALTIME) {
throw new WebApplicationException("This api cannot be used with non real-time table: " + tableName,
Expand Down
Loading

0 comments on commit 1973cdf

Please sign in to comment.