mrhhsg opened a new pull request, #71359:
URL: https://github.com/apache/doris/pull/71359

   ### Background
   
   Recursive CTE execution resets global runtime filters and rebuilds child 
fragments between iterations. Runtime filter messages carry a numeric data 
stage so receivers can discard messages from earlier iterations. A control 
request needs its own identity to distinguish a repeated operation from the 
next iteration.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #71289 (preserves its publish/reset synchronization)
   PR Type: Bugfix
   
   Problem Summary:
   
   Replaying a completed global runtime filter reset or fragment REBUILD can 
advance only one side's data stage, discard accumulated filter state, and 
repeat fragment preparation or execution accounting. This change identifies 
each control operation by controller plan node and query-scoped round, making 
completed identified operations no-ops on replay. Most added lines are tests; 
the production changes also handle failed preparation and cancellation without 
committing an incomplete rebuild.
   
   ### Details
   
   - **Change map:** Production/protocol code: +392/-79; tests: +902/-0; 
generated regression output: +6/-0. Tests and generated output account for 70% 
of additions. Production changes are grouped below in reading order.
   
     | Purpose | Main components | Lines |
     |---|---|---|
     | Stable control identity, source progress and error propagation | Round 
helper, protobuf, recursive source, QueryContext, service dispatch | +185/-13 |
     | Replay-safe filter reset with batch preparation | 
RuntimeFilterMergeControllerEntity and GlobalMergeContext | +80/-30 |
     | Rebuild admission, publication and cancellation accounting | FragmentMgr 
and saved fragment state | +127/-36 |
   
   - **Frequency:** Always under the controlled replay conditions. Duplicate 
delivery frequency during normal queries is not established.
   - **Root cause:** Reset and REBUILD requests have no logical round identity, 
while receivers unconditionally increment data stages. Reset replaces 
accumulated state; REBUILD advances saved state before preparation succeeds. 
The reset sender also reads the response without checking transport failure, so 
an empty response can look successful.
   - **Why existing tests missed it:** `RuntimeFilterMgrTest` covers 
initialization, and `RebuildRestoresFragmentExecutingCount` checks a single 
rebuild. The `recursive_cte/rf_merge_context_reuse` SQL suite exercises 
ordinary iterations without replaying control RPCs; neither layer covered 
duplicate delivery or failed reset acknowledgments.
   - **Fix:** Add optional controller/round identity and retain successful 
watermarks across source reconstruction. Resolve and deduplicate reset batches, 
prepare all replacement mergers before committing, and reserve rebuilds before 
preparing outside the saved-parameter lock. Commit rebuild stage and watermarks 
only after successful publication and cancellation checks. Propagate transport, 
missing-status and application errors before subsequent phases.
   - **Other paths and branches:** Both BE control RPC paths are covered; FE 
planning and runtime filter data-stage checks are unchanged. Local `branch-4.1` 
and `branch-4.2` snapshots contain the same control pattern; no backport or 
deployment test is included. `branch-3.1` and `branch-4.0` lack these messages 
in the inspected snapshots. The introducing PR was not established.
   - **Behavior change:** Completed identified operations preserve current 
state on replay; invalid or in-progress operations return errors. Requests 
without identity retain normal next-stage sequencing, not delayed-replay 
protection. Identified reset/REBUILD replay protection requires upgraded 
receivers.
   
   ### Testing
   
   All runs below were local:
   
   - `BUILD_TYPE=ASAN ./build.sh --be --fe -j 32`: passed, including Maven 
Checkstyle and packaging.
   - `BUILD_TYPE_UT=ASAN ./run-be-ut.sh --run 
--filter='RecursiveRoundControlTest.*:RuntimeFilterMgrTest.*:FragmentMgrCrossClusterCancelTest.*:RecursiveRebuildTest.*:RecursiveCteRoundRpcTest.*'
 -j 32`: 26/26 passed.
   - Three baseline replay/deduplication tests failed before the fix; the 
updated tests with explicit identity pass. Controlled cases cover overlapping 
controllers, invalid rounds, preparation/cancellation, reset errors and runtime 
filter stage agreement.
   - `./run-regression-test.sh --conf <local-conf> --run -d recursive_cte -s 
<suite>`: `rf_merge_context_reuse`, `shared_cte_reset_test`, 
`complex_rec_cte_test` and `rec_cte_parallel_targets` each passed. The 
RF-disabled output was generated with `-forceGenOut`, then verified by a normal 
run.
   - clang-format 16, format check, build hygiene and diff checks passed. 
Multi-BE and mixed-version deployments were not tested.
   
   ### Notes for Reviewers
   
   Control identity is separate from the target's data stage: overlapping 
controllers A1, B1, A2 advance a shared target to stages 1, 2, 3. WAIT, SUBMIT, 
FINAL_CLOSE and data delivery are not made replay-safe, and this is not an 
automatic retry or distributed rollback protocol.
   
   ### Release note
   
   Prevent repeated identified recursive CTE runtime filter resets and fragment 
rebuilds from advancing the active round or discarding accumulated filter 
state. Stop recursive execution on reset RPC failures instead of advancing to 
subsequent phases.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Partially verified: multi-BE and mixed-version 
deployments were not tested
   
   ### AI Disclosure
   
   - Tool: Codex (model not recorded)
   - Generated: Code, tests and this description
   - Human review: Not provided


-- 
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]

Reply via email to