-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Handle unique query id on server #9648
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* 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.core.query.utils; | ||
|
||
import org.apache.pinot.spi.config.table.TableType; | ||
|
||
|
||
/** | ||
* Utils to generate and manage the unique query id within a cluster. | ||
* Request id might not be unique across brokers or for request hitting a hybrid table. To generate a unique query id | ||
* within a cluster, we want to combine the broker id, request id and table type. | ||
*/ | ||
public class QueryIdUtils { | ||
private QueryIdUtils() { | ||
} | ||
|
||
private static final String OFFLINE_SUFFIX = "_O"; | ||
private static final String REALTIME_SUFFIX = "_R"; | ||
|
||
public static String getQueryId(String brokerId, long requestId, TableType tableType) { | ||
return brokerId + "_" + requestId + (tableType == TableType.OFFLINE ? OFFLINE_SUFFIX : REALTIME_SUFFIX); | ||
} | ||
|
||
public static boolean hasTypeSuffix(String queryId) { | ||
return queryId.endsWith(OFFLINE_SUFFIX) || queryId.endsWith(REALTIME_SUFFIX); | ||
} | ||
|
||
public static String withOfflineSuffix(String queryId) { | ||
return queryId + OFFLINE_SUFFIX; | ||
} | ||
|
||
public static String withRealtimeSuffix(String queryId) { | ||
return queryId + REALTIME_SUFFIX; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ | |
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import org.apache.pinot.core.query.utils.QueryIdUtils; | ||
import org.apache.pinot.core.transport.InstanceRequestHandler; | ||
import org.apache.pinot.server.starter.ServerInstance; | ||
|
||
import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY; | ||
|
@@ -65,10 +67,20 @@ public class QueryResource { | |
@ApiResponse(code = 404, message = "Query not found running on the server") | ||
}) | ||
public String cancelQuery( | ||
@ApiParam(value = "QueryId as in the format of <brokerId>_<requestId>", required = true) @PathParam("queryId") | ||
String queryId) { | ||
@ApiParam(value = "QueryId as in the format of <brokerId>_<requestId> or <brokerId>_<requestId>_(O|R)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it might make more sense for consistency with other APIs to make the offline/realtime part another optional API param. The default behavior has always been to cancel both, so I don't think there's backwards compatibility to worry about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API is on the server side, which is meant to be called by the broker. We need the type suffix to separate the OFFLINE and REALTIME query on the server side. Since they are tracked as 2 separate queries, it is better to give finer control. |
||
required = true) | ||
@PathParam("queryId") String queryId) { | ||
try { | ||
if (_serverInstance.getInstanceRequestHandler().cancelQuery(queryId)) { | ||
InstanceRequestHandler requestHandler = _serverInstance.getInstanceRequestHandler(); | ||
boolean queryCancelled; | ||
if (QueryIdUtils.hasTypeSuffix(queryId)) { | ||
queryCancelled = requestHandler.cancelQuery(queryId); | ||
} else { | ||
boolean offlineQueryCancelled = requestHandler.cancelQuery(QueryIdUtils.withOfflineSuffix(queryId)); | ||
boolean realtimeQueryCancelled = requestHandler.cancelQuery(QueryIdUtils.withRealtimeSuffix(queryId)); | ||
queryCancelled = offlineQueryCancelled | realtimeQueryCancelled; | ||
} | ||
if (queryCancelled) { | ||
return "Cancelled query: " + queryId; | ||
} | ||
} catch (Exception e) { | ||
|
@@ -85,7 +97,7 @@ public String cancelQuery( | |
@Path("/queries/id") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@ApiOperation(value = "Get queryIds of running queries on the server", notes = "QueryIds are in the format of " | ||
+ "<brokerId>_<requestId>") | ||
+ "<brokerId>_<requestId>_(O|R)") | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error") | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to log different global query ids(or traceId as mentioned in this PR) for the same query in the broker log as well? That can help triage the queries in different components in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, we will always log the same request id on both broker and servers. Query id and trace id are only available within the server, so you won't find them on the broker.