Skip to content

Support optional segments in the multi-stage query engine - #20313

Open
Jackie-Jiang wants to merge 1 commit into
apache:masterfrom
Jackie-Jiang:mse-optional-segments
Open

Jackie-Jiang wants to merge 1 commit into
apache:masterfrom
Jackie-Jiang:mse-optional-segments

Conversation

@Jackie-Jiang

@Jackie-Jiang Jackie-Jiang commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An optional segment is a new segment the broker has not seen online on a server yet. The server queries it if it has loaded it, and skips it without failing the query otherwise. The single-stage engine has routed optional segments since #11978. The multi-stage engine dropped them, so new data stayed invisible until the external view caught up, and a query on a replicated table failed when a server had not loaded a new segment yet.

The segments of a leaf worker are now carried as a SegmentsToQuery, the pair of segments and optional segments the routing table already returns, from routing through the planner and the wire to the server. No layer converts it back to a plain list, so an extension point such as WorkerManager#filterLeafStageSegments cannot drop the optional segments by accident.

Each kind of leaf gets its optional segments from where it already gets its segments:

  • Non-partitioned leaves, logical tables and the physical optimizer pass on the pair the routing table gives each server.
  • Partitioned leaves get the new segments a partition leaves out of its fully replicated segments. SegmentPartitionMetadataManager publishes them as the optional segments of the partition, and the worker of the partition queries them.
  • Replicated leaves ask the instance selector which of the table's segments are new and not online on every server, through the new RoutingManager#getSegmentsToQuery. They send these segments as optional only when the new broker config below is set. Every worker queries the other segments as before.

New broker config

pinot.broker.mse.enable.replicated.leaf.optional.segments, default false:

  • When set, a replicated leaf sends the new segments that are not online on every server as optional segments.
  • When not set, it sends them as regular segments, as it does today.
  • It ships disabled because a server that predates this change ignores optional segments. On a replicated leaf such a server would skip a new segment that it has loaded and scans today. Enable it once every server runs 1.7.0 or later.
  • It is read from the broker config, so a change takes effect after a broker restart.
  • It is temporary. A TODO marks it for removal after the 1.7.0 release, when replicated leaves always send these segments as optional.

Wire format and compatibility

  • The proto segment list gets an optionalSegment field.
  • The legacy JSON encoding sends the optional segments in a new optionalSegmentsMap custom property, because older servers parse the existing properties as maps of segment lists.
  • A server that predates this change ignores either one. On non-partitioned and partitioned leaves it keeps skipping these segments, as it does today. On replicated leaves the config above keeps them regular segments by default. So with the default config, a newer broker with older servers answers every query as it does today.

Behavior changes

  • Leaf workers query the optional segments their server has loaded, as the single-stage engine does.
  • With broker pruning, a partition whose only unpruned segment is optional keeps its worker.
  • On a replicated leaf, with the new config set, a new segment that is not online on every server is optional instead of required. The query no longer fails when a server has not loaded it, but until every server has, the segment is visible on some workers and not on others. This lasts at most the new segment expiration time (pinot.broker.new.segment.expiration.seconds, 5 minutes by default) after the segment is created. After that the segment is required again, also when the assignment of the table has not changed since. A table whose segments are all optional is still queried, which relies on Do not fail the query when the server has not set up the table and all segments are optional #20262 when a server has not set up the table yet.
  • NON_ACTIVE_WORKERS no longer counts a worker that only has optional segments.
  • RoutingManager#getSegments is removed. The replicated leaf was its only caller, and getSegmentsToQuery replaces it.
  • SegmentsToQuery treats a null list of optional segments as an empty list.

Not covered

Earlier takes on this: #19144, #19537, #20017.

🤖 Generated with Claude Code

@Jackie-Jiang Jackie-Jiang added enhancement Improvement to existing functionality release-notes Referenced by PRs that need attention when compiling the next release notes query Related to query processing backward-incompat Introduces a backward-incompatible API or behavior change multi-stage Related to the multi-stage query engine labels Nov 19, 2026
@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.16981% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.23%. Comparing base (38f0081) to head (26655f1).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
.../org/apache/pinot/query/routing/WorkerManager.java 90.74% 8 Missing and 2 partials ⚠️
...ry/runtime/plan/server/ServerPlanRequestUtils.java 50.00% 7 Missing and 3 partials ⚠️
...ot/query/planner/physical/DispatchableSubPlan.java 0.00% 6 Missing ⚠️
...org/apache/pinot/core/routing/SegmentsToQuery.java 66.66% 2 Missing and 2 partials ⚠️
...al/v2/opt/rules/LeafStageWorkerAssignmentRule.java 95.83% 0 Missing and 2 partials ⚠️
...uery/planner/physical/DispatchablePlanContext.java 75.00% 1 Missing ⚠️
...pache/pinot/query/routing/QueryPlanSerDeUtils.java 97.43% 0 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (38f0081) and HEAD (26655f1). Click for more details.

HEAD has 24 uploads less than BASE
Flag BASE (38f0081) HEAD (26655f1)
unittests 3 2
java-25 7 2
temurin 7 2
lane-a 2 0
integration 4 0
integration1 2 0
lane-b 2 0
unittests2 1 0
integration2 2 0
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #20313       +/-   ##
=============================================
- Coverage     71.47%   61.23%   -10.24%     
+ Complexity     1639        1     -1638     
=============================================
  Files          3615     2793      -822     
  Lines        244521   180605    -63916     
  Branches      39767    30252     -9515     
=============================================
- Hits         174764   110602    -64162     
- Misses        56572    60664     +4092     
+ Partials      13185     9339     -3846     
Flag Coverage Δ
integration ?
integration1 ?
integration2 ?
java-25 61.23% <87.16%> (-10.24%) ⬇️
lane-a ?
lane-b ?
temurin 61.23% <87.16%> (-10.24%) ⬇️
unittests 61.23% <87.16%> (-10.23%) ⬇️
unittests1 61.23% <87.16%> (+0.01%) ⬆️
unittests2 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yashmayya yashmayya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Jackie-Jiang, I have two questions on the replicated leaf. The description covers both behaviors. I ask because the result changes with no error.

1. New broker with old servers. Today a new segment is a required segment on this leaf, and a server that loaded it scans it. After this change, an old server ignores the optional segments. Thus an old server skips the segment, also when it loaded the segment. A query that returns these rows today loses them during a rolling upgrade. Is a broker config necessary to gate this, as for the proto segment list?

2. Same version on all nodes. A worker whose server did not load the new segment joins without its rows. An inner join then drops the matching rows of the other table on that worker only. A lineage swap looks like the worst case: the old segments leave the selection when the new segments enter it. Is a partial join with no error acceptable for is_replicated tables, or is a failure better here?

@Jackie-Jiang Jackie-Jiang added the configuration Config changes (addition/deletion/change in behavior) label Nov 23, 2026
@Jackie-Jiang

Copy link
Copy Markdown
Contributor Author

@yashmayya, thanks. Both are addressed in the latest push.

1. New broker with old servers. Agreed, that loses rows a query returns today. The replicated leaf is now gated by a broker config, pinot.broker.mse.enable.replicated.leaf.optional.segments, which is off by default. When it is off, the leaf sends the new segments as regular segments, as it does today, so a new broker with old servers behaves as before. It can be turned on once every server runs 1.7.0, and a TODO marks it for removal after the 1.7.0 release. Unlike the proto segment list flag it is a static broker config, so changing it needs a broker restart.

2. Same version on all nodes. With the config off, a server that has not loaded a new segment fails the query, as today. With it on, the partial join is possible, but it is now bounded: selectOnAllInstances checks the creation time against the clock, so after the new segment expiration time (5 minutes by default) the segment is required again, and a server that has not loaded it fails the query. The lineage swap is the same case: the replacing segments are optional only while a replica has not loaded them, and for at most that window.

An optional segment is a new segment the broker has not seen online on a
server yet. The server queries it if it has loaded it, and skips it without
failing the query otherwise. The single-stage engine has routed them since
PR apache#11978. The multi-stage engine dropped them, so new data stayed invisible
until the external view caught up, and a replicated table failed the query on
a new segment a server had not loaded yet.

The segments of a leaf worker are now carried as a SegmentsToQuery, the pair
of segments and optional segments the routing table already returns, from
routing through the planner and the wire to the server:
- Non-partitioned leaves, logical tables and the physical optimizer pass on
  the pair the routing table gives each server
- Partitioned leaves get the new segments a partition leaves out of its fully
  replicated segments as the optional segments of the worker of the partition
- Replicated leaves ask the instance selector which segments are new and not
  online on every server, through RoutingManager#getSegmentsToQuery, which
  replaces getSegments. They send these segments as optional only when the
  broker config pinot.broker.mse.enable.replicated.leaf.optional.segments is
  set, and as regular segments otherwise, as before. The config is off by
  default, because a server that predates this change skips an optional
  segment even when it has loaded it. A segment stops being optional once the
  new segment expiration time has passed since its creation
- The proto segment list gets an optionalSegment field, and the legacy JSON
  encoding an optionalSegmentsMap custom property. A server that predates them
  ignores either one and keeps skipping these segments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backward-incompat Introduces a backward-incompatible API or behavior change configuration Config changes (addition/deletion/change in behavior) enhancement Improvement to existing functionality multi-stage Related to the multi-stage query engine query Related to query processing release-notes Referenced by PRs that need attention when compiling the next release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants