xiangfu0 commented on code in PR #20280:
URL: https://github.com/apache/pinot/pull/20280#discussion_r4605096334
##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/manager/BaseBrokerRoutingManager.java:
##########
@@ -1337,22 +1338,31 @@ public RoutingTable getRoutingTable(BrokerRequest
brokerRequest, String tableNam
String samplerName = extractSamplerName(brokerRequest);
InstanceSelector.SelectionResult selectionResult =
routingEntry.calculateRouting(brokerRequest, requestId, samplerName);
- return new RoutingTable(getServerInstanceToSegmentsMap(tableNameWithType,
selectionResult),
- selectionResult.getUnavailableSegments(),
selectionResult.getNumPrunedSegments());
+ return new RoutingTable(getServerInstanceToSegmentsMap(tableNameWithType,
selectionResult,
+ routesServersWithOnlyOptionalSegments(brokerRequest)),
selectionResult.getUnavailableSegments(),
+ selectionResult.getNumPrunedSegments());
+ }
+
+ private static boolean routesServersWithOnlyOptionalSegments(BrokerRequest
brokerRequest) {
+ PinotQuery pinotQuery = brokerRequest.getPinotQuery();
+ Map<String, String> queryOptions = pinotQuery != null ?
pinotQuery.getQueryOptions() : null;
+ return queryOptions != null
+ &&
Boolean.parseBoolean(queryOptions.get(RoutingManager.ROUTE_SERVERS_WITH_ONLY_OPTIONAL_SEGMENTS));
Review Comment:
**[P2] SQL callers can enable the time-series routing switch.** The shared
routing manager reads it from client-supplied `queryOptions`. The multi-stage
engine forwards those options, then discards the optional segment list and can
schedule an empty worker on a server that hasn’t loaded the table. Pass the
opt-in as an internal routing argument from the time-series planner.
##########
pinot-timeseries/pinot-timeseries-planner/src/main/java/org/apache/pinot/tsdb/planner/physical/TableScanVisitor.java:
##########
@@ -67,18 +71,69 @@ public void assignSegmentsToPlan(BaseTimeSeriesPlanNode
planNode, TimeBuckets ti
compileBrokerRequest(sfpNode.getTableName(), filterExpression),
context._requestId);
Preconditions.checkNotNull(routingTable, "Failed to get routing table
for table: " + sfpNode.getTableName());
+ routingTable = context._routingCustomizer.customize(sfpNode,
routingTable, context._routingContext);
+ Preconditions.checkNotNull(routingTable, "Routing customizer returned no
routing for table: "
+ + sfpNode.getTableName());
+ boolean routed = false;
for (var entry :
routingTable.getServerInstanceToSegmentsMap().entrySet()) {
ServerInstance serverInstance = entry.getKey();
- List<String> segments = entry.getValue().getSegments();
+ List<String> segments = entry.getValue().getSegments() == null ?
List.of() : entry.getValue().getSegments();
+ List<String> optionalSegments = entry.getValue().getOptionalSegments()
== null ? List.of()
+ : entry.getValue().getOptionalSegments();
+ // A server reads the leaf only if it has segments for it: it then
sends exactly one block for the leaf, which
+ // is what the leaf's exchange counts on.
+ if (segments.isEmpty() && optionalSegments.isEmpty()) {
+ continue;
+ }
+ routed = true;
context.getLeafIdToSegmentsByServer().computeIfAbsent(serverInstance,
(x) -> new HashMap<>())
.put(sfpNode.getId(), segments);
+ if (!optionalSegments.isEmpty()) {
+
context._leafIdToOptionalSegmentsByServer.computeIfAbsent(serverInstance, (x)
-> new HashMap<>())
+ .put(sfpNode.getId(), optionalSegments);
+ }
+ }
+ List<String> unavailableSegments = routingTable.getUnavailableSegments();
+ if (!routed && unavailableSegments != null &&
!unavailableSegments.isEmpty()) {
Review Comment:
**[P1] An optional assignment can hide a known outage.** If every required
segment is unavailable and the only optional segment is still loading, the
optional assignment sets `routed = true`. The server skips the unloaded
segment, and the broker can return empty success despite knowing required data
is missing. Preserve `SERVER_SEGMENT_MISSING` when no required segment can be
routed and the unavailable list is nonempty.
##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/manager/BaseBrokerRoutingManager.java:
##########
@@ -1337,22 +1338,31 @@ public RoutingTable getRoutingTable(BrokerRequest
brokerRequest, String tableNam
String samplerName = extractSamplerName(brokerRequest);
InstanceSelector.SelectionResult selectionResult =
routingEntry.calculateRouting(brokerRequest, requestId, samplerName);
- return new RoutingTable(getServerInstanceToSegmentsMap(tableNameWithType,
selectionResult),
- selectionResult.getUnavailableSegments(),
selectionResult.getNumPrunedSegments());
+ return new RoutingTable(getServerInstanceToSegmentsMap(tableNameWithType,
selectionResult,
+ routesServersWithOnlyOptionalSegments(brokerRequest)),
selectionResult.getUnavailableSegments(),
+ selectionResult.getNumPrunedSegments());
+ }
+
+ private static boolean routesServersWithOnlyOptionalSegments(BrokerRequest
brokerRequest) {
+ PinotQuery pinotQuery = brokerRequest.getPinotQuery();
+ Map<String, String> queryOptions = pinotQuery != null ?
pinotQuery.getQueryOptions() : null;
+ return queryOptions != null
+ &&
Boolean.parseBoolean(queryOptions.get(RoutingManager.ROUTE_SERVERS_WITH_ONLY_OPTIONAL_SEGMENTS));
}
private Map<ServerInstance, SegmentsToQuery>
getServerInstanceToSegmentsMap(String tableNameWithType,
- InstanceSelector.SelectionResult selectionResult) {
+ InstanceSelector.SelectionResult selectionResult, boolean
routeServersWithOnlyOptionalSegments) {
Map<String, SegmentsToQuery> instanceToSegmentsMap =
selectionResult.getInstanceToSegmentsMap();
Map<ServerInstance, SegmentsToQuery> serverInstanceToSegmentsMap =
Maps.newHashMapWithExpectedSize(instanceToSegmentsMap.size());
for (Map.Entry<String, SegmentsToQuery> entry :
instanceToSegmentsMap.entrySet()) {
SegmentsToQuery segmentsToQuery = entry.getValue();
int numSegments = segmentsToQuery.getSegments().size();
// Skip servers that don't have non-optional segments, so that servers
always get some non-optional segments
- // to process, to be backward compatible.
+ // to process, to be backward compatible, unless the request asks to
keep them.
// TODO: allow servers only with optional segments
- if (numSegments == 0) {
+ if (numSegments == 0 && (!routeServersWithOnlyOptionalSegments ||
segmentsToQuery.getOptionalSegments() == null
Review Comment:
**[P1] An optional-only server can fail a healthy query.** During a segment
push, the broker can route to a server before it creates the table’s data
manager. That server returns `SERVER_TABLE_MISSING`, and the Prometheus
endpoint returns an error even if other servers returned all required data.
Return an empty block when the local table is absent and the request contains
only optional segments. Preserve the error for requests with required segments.
--
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]