Skip to content

[fix](profile) Fix execution profile leak when dispatch fails before profile registration - #68658

Merged
mrhhsg merged 7 commits into
apache:masterfrom
linrrzqqq:fix/cir-22040-profile-cleanup
Oct 12, 2026
Merged

mrhhsg merged 7 commits into
apache:masterfrom
linrrzqqq:fix/cir-22040-profile-cleanup

Conversation

@linrrzqqq

@linrrzqqq linrrzqqq commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary:

An ExecutionProfile is registered before query dispatch. If dispatch fails before the first updateProfile(false) call, the corresponding Profile has not been added to profileIdToProfileMap.

When cleanup is invoked, the previous removeProfile implementation removed execution profiles only after finding a historical Profile entry. If no such entry existed, the ExecutionProfile remained in queryIdToExecutionProfiles and continued to retain query state in FE memory. This was reproduced with a UDF JAR download failure: three failed queries left three ExecutionProfiles and no historical Profile entries.

Pass the current Profile to removeProfile and remove its ExecutionProfiles directly, regardless of whether a historical entry exists. Add tests covering a missing historical entry, an existing entry, and multiple ExecutionProfiles.

Release note

Fix FE memory growth caused by execution profiles retained when query dispatch fails before profile registration.

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot 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.

Static-only review complete for head c588e48817809f120a4296a2a6d5d32615df8729. Request changes: one new P1 inline finding. The new cleanup removes execution profiles for a single short query even when no historical summary was inserted, but a dispatch failure followed by a query retry can still retain the retry's execution profile. No existing P0/P1 inline comment was present or independently confirmed. Two review rounds converged, including normal whole-PR and focused lifecycle reviews; the final changed-file sweep found no other substantiated new issue.

Checkpoint conclusions:

  • Goal and proof: The direct absent-summary case is covered by a new unit test, but the intended memory-leak fix is incomplete for dispatch retries. The tests do not exercise failed dispatch followed by retry.
  • Scope and reuse: The map and API renames are otherwise behavior-preserving: Profile.getId() delegates to SummaryProfile.getProfileId(). The cleanup API change is focused; its caller's attempt lifecycle needs correction.
  • Concurrency and locking: The two manager maps are modified under the same write lock. BE profile reports run asynchronously and can hold a captured execution-profile object; no new lock-order issue, metadata-lock IO, or heavy work under a changed lock was found. The P1 is a sequential retry lifecycle failure.
  • Lifecycle: StmtExecutor reuses one Profile across attempts. Its first terminal update sets isQueryFinished; later attempts register new execution IDs but cannot reach terminal cleanup. Successful Broker Load finalization follows its task callbacks, with no additional add/remove race established.
  • Configuration: No new setting or dynamic-change obligation is introduced. The P1 occurs with a positive existing auto-profile threshold and the configured query retry path; max_query_retry_time defaults to 3.
  • Compatibility: No FE/BE wire value, storage format, function symbol, or rolling-upgrade behavior changed.
  • Parallel paths: Normal MySQL, collected internal-query, deferred Arrow Flight, and successful Broker Load paths were traced. The retry path is the one unresolved defect; cloud replan and insert retries share that root cause rather than requiring duplicate comments.
  • Conditional checks: The changed short-duration branch removes the caller's attached execution IDs. Its existing isQueryFinished guard prevents this on later attempts. Other renamed conditions retain their prior meaning.
  • Tests and results: New FE unit cases check absent/present summary entries and multiple execution IDs. They do not cover a real retry or Broker Load cancellation. No test result files changed. Builds and tests were prohibited by the review instructions and were not run; conclusions are static only.
  • Observability: Existing debug logs show missing/removed execution profiles. No distinct logging or metric defect was established; logging would not release the retained retry entry.
  • Transactions, persistence, and data writes: The PR changes no transaction, EditLog, table-data write, or persistent profile format path; existing profile storage and Broker Load commit ordering were checked without a new defect.
  • FE/BE variables and performance: No new transmitted variable exists. Cleanup is proportional to the attached execution profiles and no additional hot-path anti-pattern was substantiated.
  • Authorization and other issues: The REST call still applies the same non-admin profile owner check. No other candidate remains unresolved after duplicate and risk review.

User review focus: none was supplied. A separate pre-existing Broker Load cancellation retention path was noted during review; it does not arise from this query-dispatch change and is not duplicated as an inline finding.

if (this.queryFinishTimestamp != Long.MAX_VALUE && durationMs < durationThreshold) {
ProfileManager.getInstance().removeProfile(this.getId());
ProfileManager.getInstance().removeProfile(this);
if (LOG.isDebugEnabled()) {

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.

[P1] Clean execution profiles for every dispatch retry. handleQueryWithRetry calls finalizeQuery() after each attempt, but it reuses this Profile when an RpcException from coordBase.exec() triggers a retry with a new query ID. The first short attempt marks isQueryFinished and reaches this removal; the retry then registers another ExecutionProfile, while both later updateSummary calls return immediately at the finished guard. unregisterQuery only marks that second entry finished, so it remains in queryIdToExecutionProfiles until the size-triggered fallback GC. Make each attempt eligible for cleanup and cover a failed-dispatch-then-retry case that checks both IDs.

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.

Confirmed this retry cleanup gap locally on c588e48817809f120a4296a2a6d5d32615df8729.

The change correctly cleans up the first short failed attempt, but a subsequent attempt can still retain its ExecutionProfile:

  1. With profiling enabled and a positive auto-profile threshold, a fast retryable RPC failure during dispatch reaches finalizeQuery(). updateSummary(..., true, ...) sets isQueryFinished = true and removes the first execution profile.
  2. handleQueryWithRetry() reuses that same Profile, changes the query ID, and registers another execution profile.
  3. Both summary updates for the retry return immediately at the isQueryFinished guard, so this removal is never reached again. unregisterQuery() only marks the execution profile finished.

The fallback collector is size-triggered (size > 2 * max_query_profile_num, i.e. over 1000 entries by default), so a small number of retained entries will not simply disappear after five seconds. This is a pre-existing lifecycle gap left uncovered by this fix, rather than a new regression introduced by the diff.

Please cover failed dispatch followed by a retry, and ensure cleanup applies to the retry execution as well. The lifecycle needs to distinguish completion of one attempt from completion of the whole statement.

Validation: ran the repository's run-fe-ut.sh: ProfileTest (15), AutoProfileTest (1), and ProfileManagerTest (28) all passed. The additional test below failed on the final assertion: the first execution was removed, but the retry execution remained registered. It directly reproduces the Profile lifecycle; it does not inject an actual BE RPC failure.

Minimal reproducer: ReviewProfileRetryTest.java
package org.apache.doris.common.profile;

import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.thrift.TUniqueId;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@ResourceLock("global")
public class ReviewProfileRetryTest {
    @Test
    public void retryExecutionMustBeReleasedAfterFinalization() {
        ProfileManager manager = ProfileManager.getInstance();
        Profile profile = new Profile(true, 1, 60_000);
        profile.getSummaryProfile().setQueryBeginTime(System.currentTimeMillis());
        TUniqueId firstId = new TUniqueId(68658, 1);
        TUniqueId retryId = new TUniqueId(68658, 2);
        Map<String, String> summary = new HashMap<>();
        summary.put(SummaryProfile.PROFILE_ID, DebugUtil.printId(firstId));
        try {
            // registerQuery, dispatch failure, finalizeQuery: no running summary was pushed.
            ExecutionProfile first = new ExecutionProfile(firstId, Collections.emptyList());
            profile.addExecutionProfile(first);
            manager.addExecutionProfile(first);
            profile.updateSummary(summary, true, null);
            manager.markExecutionProfileFinished(firstId);
            Assertions.assertNull(manager.getExecutionProfile(firstId));
            Assertions.assertTrue(profile.isQueryFinished);

            // handleQueryWithRetry reuses Profile while replacing the query ID and Coordinator.
            ExecutionProfile retry = new ExecutionProfile(retryId, Collections.emptyList());
            profile.addExecutionProfile(retry);
            manager.addExecutionProfile(retry);
            summary.put(SummaryProfile.PROFILE_ID, DebugUtil.printId(retryId));
            profile.updateSummary(summary, false, null);
            profile.updateSummary(summary, true, null);
            manager.markExecutionProfileFinished(retryId);

            Assertions.assertNull(manager.getExecutionProfile(retryId),
                    "The retry execution remains registered after finalization");
        } finally {
            manager.removeProfile(profile);
        }
    }
}

Observed failure:

The retry execution remains registered after finalization
expected: <null> but was: <DetailProfile(10c32-2): ...>
Tests run: 45, Failures: 1, Errors: 0, Skipped: 0

…le registration

### What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary: When query dispatch fails before the first summary update, the execution profile is registered but the historical profile is not. Short-query cleanup previously removed execution profiles only when it found a historical profile, leaving the execution profile in FE memory. Use the current Profile to remove its execution profiles regardless of whether its summary was pushed. This also handles profiles containing multiple executions.

### Release note

Prevent FE profile memory growth when short profiled queries fail during dispatch.

### Check List (For Author)

- Test: Unit Test (ProfileTest and ProfileManagerTest, 43 passed); FE build and Checkstyle passed.
- Behavior changed: Yes. Short failed queries release their execution profiles.
- Does this need documentation: No.
@linrrzqqq
linrrzqqq force-pushed the fix/cir-22040-profile-cleanup branch 2 times, most recently from 1e943bb to fbb274b Compare September 30, 2026 08:21
@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot 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.

Complete static review

Reviewed PR #68658 at head fbb274bf92640a6757348741f72e4d876b906dc6 against base 3e3bacd60e1fca0aef2ce7a3c83516d45521973b. All eight changed files and related retry, profile-manager, Broker Load, REST, storage, and protocol paths were covered in three convergence rounds. The review found one P1 and five P2 issues, all reported inline. M5 and M6 are explicitly labeled pre-existing defects in touched or parallel paths.

The patch repairs the original short failed-dispatch cleanup gap when no history entry was published: removeProfile(Profile) now deletes attached execution IDs directly. It also prevents the earlier inner RpcException retry from finishing the shared Profile after its first attempt. Existing inline P1 comment 4140101788 described that inner retry and no longer applies to this head, so there is no still-applicable existing blocking comment ID. The separate outer cloud replan path remains affected (new P1 inline). There was no additional user-provided focus.

Critical checkpoints

  • Goal and tests: The new ProfileTest cases verify map cleanup with and without a history entry and with multiple execution IDs. The StmtExecutorTest cases manually finalize mocked attempts and use empty fragment lists; they do not prove real dispatch/replan behavior, nonempty-fragment completion, configured threshold retention, or rendered profile content. The goal is only partially achieved because the inline findings remain.
  • Scope and lifecycle: The ProfileManager map rename follows the same SummaryProfile ID; QueryProfileAction changes a method name only. The central lifecycle is registration before dispatch, running summary after dispatch, and terminal update before unregister. Inner retry now defers terminal update, but outer replan still finishes too early (P1), and abandoned attempts affect completion, retention, and rendering (P2 findings).
  • Concurrency and locking: ProfileManager map operations use its read/write lock; Profile.updateSummary is synchronized. Late BE reports can hold an already retrieved execution object after map removal, but no new lock-order or report-thread race was substantiated. No cross-translation-unit initialization is involved.
  • Configuration and parallel paths: No new configuration, transmitted FE/BE variable, protocol symbol, or format was added. The existing auto_profile_threshold_ms is applied incorrectly after a retry. MySQL local-result, Flight backend-result, outer replan, Broker Load, memory eviction, and storage paths were traced; the pre-existing Flight orphan registration and Broker Load retention defect are inline with their provenance stated.
  • Tests, results, and observability: No result file changed. The review was static only: no builds or tests were run, as required by the review prompt; author or prior-thread test claims were not treated as independent validation. Existing logging and profile status expose some failures, but a successful retry can show an incomplete profile or lose its merged runtime view and actual row counts.
  • Persistence, data, and performance: No EditLog, transaction, table-data write, or crash-recovery protocol changes were made. Profile file retention is covered by the Broker Load inline finding. The outer retry can retain execution state; abandoned attempts can delay spill and suppress a profile that exceeds its configured threshold. No other material hot-path cost was substantiated.

Disposition: Request changes for the P1 outer-replan lifecycle issue. The remaining accepted points are P2. No unresolved candidate remained after the final changed-file sweep.

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot 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.

Static review of PR #68658 at head 1f6e14eaab459f045d2f0cd552be98618e560472.

The change fixes the described pre-summary execution-profile leak by removing attached execution IDs even when no profile-history entry exists. The inner retry, outer replan, Flight cleanup, and Broker Load pruning paths were traced. Three distinct P2 profile-correctness issues remain in the inline comments: outer retry duration/retention, stale physical-relation statistics after a post-dispatch replan, and cross-attempt phase timing.

Review completion: The bounded three rounds were performed. A new valuable finding arose in round 3, so convergence is incomplete under this review's instruction set. Every discovered candidate was independently validated, deduplicated, and given a disposition. No still-applicable P0/P1 inline finding was confirmed; the earlier P1 retry comments are addressed on this head and are not reposted.

Critical checkpoints

  • Goal and proof: The direct cleanup and added FE unit tests cover a missing history entry, retained entry, multiple executions, inner retries, merged rendering, and mocked cloud outcomes. They do not cover the three inline scenarios; the cloud test uses a zero duration threshold and a generic mocked planner.
  • Scope: Production changes are confined to profile ownership, retry finalization, identity naming, and the REST auth method rename. The manager rename and tests remain related to that work.
  • Concurrency: BE reports and finish callbacks can run asynchronously. Manager map access uses its read/write lock; abandoned IDs are removed before the next attempt. No distinct lock-order or callback leak was substantiated. Profile lifecycle across query IDs is the material risk identified below.
  • Configuration: No new setting was added. The existing auto_profile_threshold_ms policy is misapplied after an outer replan as described inline; the separate per-attempt timeout clock should be preserved.
  • Compatibility and parallel paths: No FE/BE wire, storage-format, or rolling-upgrade change was found. MySQL, Flight, direct execution, inner retry, outer cloud retry, and Broker Load paths were checked. The REST ownership check still compares the indexed profile owner under the manager lock.
  • Conditions and errors: The inner retry gate and outer UserException replan gate were traced through terminal and successful outcomes. Profile-update errors retain the existing logged-and-suppressed boundary; no additional error propagation bug was substantiated.
  • Tests and results: The changed FE tests were inspected for their assertions, including archive/delete and merged-profile content. No build, test, or regression suite was run because this review is static-only.
  • Observability and performance: Existing logs identify failed profile updates. The inline issues affect the accuracy or retention of diagnostic profiles; no separate hot-path performance problem was substantiated.
  • Persistence, writes, and protocol state: Stored profiles reuse the same rendering path, so the stale relation appendix can persist. Broker Load cleanup now removes attached execution IDs. No transaction data-write path or new FE-to-BE variable is changed.
  • Other core invariants: Data visibility, partition versions, delete bitmaps, BE memory tracking, and static initialization are outside the changed path. No additional issue was substantiated.

No additional user review focus was supplied. This review used static code and test inspection only.

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 27915 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 1f6e14eaab459f045d2f0cd552be98618e560472, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17619	4023	4136	4023
q2	2112	350	306	306
q3	10122	1419	792	792
q4	4677	470	362	362
q5	7473	818	541	541
q6	169	167	133	133
q7	718	778	596	596
q8	9323	1362	1518	1362
q9	5391	4174	4182	4174
q10	6837	1300	1013	1013
q11	429	265	240	240
q12	631	416	314	314
q13	18047	2650	2024	2024
q14	259	259	235	235
q15	q16	737	706	658	658
q17	1783	1078	994	994
q18	6478	5554	5506	5506
q19	1178	1305	1064	1064
q20	473	400	262	262
q21	5425	3133	3008	3008
q22	461	358	308	308
Total cold run time: 100342 ms
Total hot run time: 27915 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4779	4822	4719	4719
q2	730	570	548	548
q3	4733	5378	4514	4514
q4	2206	2317	1439	1439
q5	4588	4390	4455	4390
q6	228	170	123	123
q7	1828	1718	1522	1522
q8	2347	2035	2070	2035
q9	7443	7107	6812	6812
q10	3621	3548	3101	3101
q11	511	372	351	351
q12	710	696	517	517
q13	2299	2611	2006	2006
q14	279	274	247	247
q15	q16	668	680	607	607
q17	7249	6693	6631	6631
q18	11876	11022	11755	11022
q19	1144	999	1026	999
q20	2216	2181	1901	1901
q21	4981	4171	4280	4171
q22	497	478	422	422
Total cold run time: 64933 ms
Total hot run time: 58077 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152323 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 1f6e14eaab459f045d2f0cd552be98618e560472, data reload: false

query5	4306	617	493	493
query6	422	206	195	195
query7	4853	549	295	295
query8	325	177	169	169
query9	8804	4001	3969	3969
query10	453	310	264	264
query11	5844	3565	3222	3222
query12	143	88	85	85
query13	1257	606	426	426
query14	6508	4489	4261	4261
query14_1	3970	3955	3933	3933
query15	198	215	180	180
query16	989	454	413	413
query17	898	662	560	560
query18	2490	474	335	335
query19	204	183	140	140
query20	83	79	79	79
query21	234	139	110	110
query22	12998	13139	12788	12788
query23	13866	12808	12425	12425
query23_1	12601	12527	12479	12479
query24	7383	1135	697	697
query24_1	730	681	692	681
query25	554	428	367	367
query26	1272	307	163	163
query27	2687	545	332	332
query28	4525	1990	1979	1979
query29	1658	722	528	528
query30	311	232	186	186
query31	871	764	632	632
query32	144	100	94	94
query33	536	310	259	259
query34	1179	1107	633	633
query35	744	759	640	640
query36	795	802	715	715
query37	148	103	93	93
query38	1823	1757	1733	1733
query39	685	719	667	667
query39_1	672	671	648	648
query40	226	125	101	101
query41	70	68	68	68
query42	100	98	96	96
query43	343	347	299	299
query44	1373	699	747	699
query45	181	176	169	169
query46	1064	1172	749	749
query47	1497	1487	1385	1385
query48	449	393	273	273
query49	578	400	299	299
query50	921	353	249	249
query51	10375	10022	10336	10022
query52	86	96	73	73
query53	244	265	192	192
query54	248	200	187	187
query55	78	74	73	73
query56	211	217	201	201
query57	1491	1426	1324	1324
query58	285	260	262	260
query59	1978	2074	1863	1863
query60	265	241	219	219
query61	144	142	140	140
query62	389	314	265	265
query63	214	178	178	178
query64	2744	1011	806	806
query65	3493	3426	3451	3426
query66	1796	433	306	306
query67	20047	20166	20059	20059
query68	3435	1604	887	887
query69	409	300	247	247
query70	917	808	859	808
query71	301	236	211	211
query72	2621	2546	2253	2253
query73	858	809	437	437
query74	4675	4534	4297	4297
query75	2322	2317	1983	1983
query76	2311	1141	801	801
query77	372	413	301	301
query78	9015	9103	8418	8418
query79	1323	1145	763	763
query80	579	484	370	370
query81	542	320	278	278
query82	623	171	127	127
query83	315	250	189	189
query84	322	147	113	113
query85	839	465	373	373
query86	343	236	215	215
query87	1988	1968	1828	1828
query88	3607	2707	2704	2704
query89	375	288	248	248
query90	1937	178	175	175
query91	165	157	125	125
query92	100	88	88	88
query93	1514	1608	869	869
query94	524	338	306	306
query95	664	382	412	382
query96	1081	763	345	345
query97	2421	2397	2318	2318
query98	164	150	143	143
query99	713	749	618	618
Total cold run time: 236108 ms
Total hot run time: 152323 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.13 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 1f6e14eaab459f045d2f0cd552be98618e560472, data reload: false

query1	0.01	0.01	0.01
query2	0.10	0.05	0.05
query3	0.26	0.14	0.14
query4	1.61	0.14	0.14
query5	0.24	0.22	0.21
query6	1.16	0.97	0.92
query7	0.04	0.01	0.01
query8	0.05	0.04	0.04
query9	0.39	0.35	0.35
query10	0.57	0.55	0.59
query11	0.21	0.14	0.14
query12	0.18	0.14	0.15
query13	0.47	0.46	0.47
query14	0.96	0.96	0.95
query15	0.60	0.58	0.58
query16	0.31	0.32	0.33
query17	1.10	1.06	1.07
query18	0.22	0.20	0.19
query19	1.96	1.96	1.97
query20	0.02	0.01	0.01
query21	15.47	0.24	0.15
query22	4.81	0.06	0.06
query23	16.15	0.31	0.12
query24	2.95	0.40	0.32
query25	0.12	0.06	0.04
query26	0.73	0.20	0.14
query27	0.04	0.04	0.03
query28	3.52	0.77	0.38
query29	12.46	4.10	3.31
query30	0.28	0.15	0.15
query31	2.78	0.57	0.31
query32	3.22	0.59	0.48
query33	3.16	3.17	3.13
query34	15.56	3.91	3.29
query35	3.21	3.21	3.21
query36	0.55	0.43	0.42
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.03	0.03	0.03
query40	0.17	0.14	0.14
query41	0.08	0.04	0.04
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 95.97 s
Total hot run time: 24.13 s

@linrrzqqq
linrrzqqq force-pushed the fix/cir-22040-profile-cleanup branch from 1f6e14e to a75c214 Compare October 4, 2026 09:28
@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@github-actions github-actions Bot 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.

Static review complete for head a75c214be3134f02c7a59097612976c639cf3345 across all eight changed files. One new P2 diagnostic correctness issue is inline: an inner retry can retain actual row counts from a failed execution.

Critical checkpoints

  • Goal and scope: Passing the current Profile to manager removal addresses the leak when dispatch fails before a history entry exists. The added tests inspect missing and present history entries, retries, merged profiles, Flight paths, and mixed query/Broker Load pruning. The manager's ID rename follows the same profile ID source; no unrelated product behavior was found.
  • Concurrency and lifecycle: Query registration and asynchronous BE reports use the manager's execution index; removal now clears attached execution IDs. The manager's read/write lock still protects its indexes, and no new lock-order inversion was found. A live profile read can, however, populate derived row counts before an inner retry; the inline finding covers their missing reset. Inner MySQL retry, outer cloud replan, Flight request close/deferred execution, and Broker Load paths were traced separately.
  • Conditions and parallel paths: The new retry flags preserve an open profile through a real retry and finalize terminal local attempts. The two previously reported P1 retry leaks (comments 4140101788 and 4143010094) are fixed on this head, so no existing blocking ID is carried. The existing P2 threads on outer statement duration (4174520825) and per-attempt phase times (4174520817) still apply and are not reposted. The outer plan-statistics, Flight abandoned-attempt, merged-profile, threshold, incomplete-profile, and Broker Load pruning threads are addressed by this diff.
  • Configuration, compatibility, and persistence: No new configuration, FE/BE variable, wire format, or persisted profile format was added. This change does not touch transaction or query-data writes. Profile file deletion/archiving now removes each attached execution by its own query ID, including decimal Broker Load profile IDs.
  • Tests, observability, and performance: The new unit tests cover several cleanup branches, but they do not render the failed inner attempt before retry, which is needed to catch the inline issue. Profile text remains the relevant diagnostic surface. No separate performance regression or additional observability gap was substantiated. Review was static only; builds, tests, and CI results were not executed or independently validated here.

User focus: no additional focus was provided. The review converged after two rounds of normal and risk-focused inspection; all candidates were accepted, dismissed with code evidence, or covered by existing threads.

if (willRetry) {
// Keep the statement open and its cumulative elapsed time, but discard the abandoned
// attempt so query retention and merged profiles only use the final execution profile.
profile.clearExecutionProfiles();

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.

[P2] Clear derived row counts when discarding an inner retry attempt. A live profile read after the first dispatch can populate rowsProducedMap and write actualRows into this same planner's physical plan. If a later getNext() RPC error triggers an inner retry, this call removes the failed execution but leaves those derived values. The next attempt reuses the plan, and merged rendering only putAlls new counters, so nodes without a new report still show the failed attempt's rows. Reset both the cached rows and the reused plan's actual-row statistics, and cover a retry after rendering the first attempt.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28009 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit a75c214be3134f02c7a59097612976c639cf3345, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17869	3954	3915	3915
q2	2183	365	310	310
q3	10073	1414	787	787
q4	4680	477	358	358
q5	7470	817	544	544
q6	181	179	143	143
q7	740	770	599	599
q8	9348	1546	1549	1546
q9	5340	4207	4228	4207
q10	6832	1333	1040	1040
q11	439	272	240	240
q12	635	418	288	288
q13	18086	2629	2028	2028
q14	258	251	230	230
q15	q16	731	725	655	655
q17	1735	1130	946	946
q18	6359	5583	5551	5551
q19	1201	1186	1072	1072
q20	493	382	261	261
q21	5445	3100	2972	2972
q22	439	366	317	317
Total cold run time: 100537 ms
Total hot run time: 28009 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4743	4686	4890	4686
q2	728	575	521	521
q3	4736	5220	4585	4585
q4	2187	2354	1456	1456
q5	4582	4462	4503	4462
q6	230	178	129	129
q7	1878	1683	1521	1521
q8	2279	2106	2152	2106
q9	7386	6825	6858	6825
q10	3619	3562	3058	3058
q11	520	374	344	344
q12	704	700	499	499
q13	2290	2579	2002	2002
q14	268	269	252	252
q15	q16	683	687	605	605
q17	7273	6758	6632	6632
q18	11878	11026	11827	11026
q19	1142	997	1017	997
q20	2209	2195	1902	1902
q21	5026	4197	4380	4197
q22	522	436	401	401
Total cold run time: 64883 ms
Total hot run time: 58206 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152209 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit a75c214be3134f02c7a59097612976c639cf3345, data reload: false

query5	4357	607	474	474
query6	420	211	192	192
query7	4820	528	292	292
query8	326	177	163	163
query9	8796	4000	3996	3996
query10	445	309	255	255
query11	5825	3522	3214	3214
query12	146	89	84	84
query13	1277	606	394	394
query14	6508	4558	4321	4321
query14_1	4021	4010	3958	3958
query15	203	200	179	179
query16	1006	468	403	403
query17	893	660	547	547
query18	2446	477	336	336
query19	201	177	141	141
query20	90	84	80	80
query21	219	132	112	112
query22	13206	13068	12857	12857
query23	13854	12921	12500	12500
query23_1	12406	12545	12513	12513
query24	7216	1120	644	644
query24_1	673	664	702	664
query25	568	433	361	361
query26	1298	305	171	171
query27	2690	570	329	329
query28	4590	1964	1973	1964
query29	1678	720	520	520
query30	299	224	185	185
query31	897	743	643	643
query32	153	95	93	93
query33	518	313	247	247
query34	1217	1092	591	591
query35	742	756	641	641
query36	788	782	717	717
query37	144	112	96	96
query38	1841	1769	1717	1717
query39	699	717	658	658
query39_1	646	660	640	640
query40	221	123	102	102
query41	72	71	68	68
query42	101	96	95	95
query43	338	369	304	304
query44	1352	715	709	709
query45	187	180	165	165
query46	1045	1214	759	759
query47	1516	1496	1392	1392
query48	386	461	277	277
query49	582	397	312	312
query50	961	339	249	249
query51	10614	10706	10424	10424
query52	94	87	74	74
query53	243	251	175	175
query54	237	200	184	184
query55	78	73	68	68
query56	247	208	220	208
query57	1531	1510	1450	1450
query58	291	259	253	253
query59	1989	2045	1852	1852
query60	268	237	225	225
query61	150	148	142	142
query62	401	318	262	262
query63	209	176	179	176
query64	2803	1010	798	798
query65	3481	3399	3430	3399
query66	1790	429	308	308
query67	20109	19770	19791	19770
query68	3258	1547	910	910
query69	434	314	260	260
query70	912	808	833	808
query71	293	235	202	202
query72	2631	2521	2183	2183
query73	826	821	409	409
query74	4615	4501	4271	4271
query75	2307	2307	1935	1935
query76	2305	1110	741	741
query77	374	403	304	304
query78	9066	9070	8370	8370
query79	1405	1231	757	757
query80	607	445	354	354
query81	538	318	281	281
query82	612	168	133	133
query83	346	225	190	190
query84	335	139	112	112
query85	840	454	372	372
query86	321	240	227	227
query87	1993	1984	1852	1852
query88	3622	2724	2721	2721
query89	355	285	248	248
query90	1957	180	179	179
query91	174	153	130	130
query92	106	89	91	89
query93	1467	1459	831	831
query94	528	338	281	281
query95	680	466	339	339
query96	1011	770	321	321
query97	2458	2427	2325	2325
query98	164	151	145	145
query99	716	718	608	608
Total cold run time: 236357 ms
Total hot run time: 152209 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 23.92 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit a75c214be3134f02c7a59097612976c639cf3345, data reload: false

query1	0.01	0.00	0.00
query2	0.09	0.05	0.05
query3	0.26	0.13	0.14
query4	1.62	0.14	0.14
query5	0.24	0.22	0.22
query6	1.16	0.91	0.91
query7	0.05	0.01	0.01
query8	0.06	0.04	0.04
query9	0.40	0.33	0.32
query10	0.59	0.53	0.54
query11	0.19	0.14	0.14
query12	0.18	0.15	0.15
query13	0.45	0.46	0.47
query14	0.95	0.94	0.94
query15	0.60	0.58	0.58
query16	0.31	0.30	0.33
query17	1.10	1.13	1.07
query18	0.21	0.20	0.19
query19	2.07	1.94	1.90
query20	0.02	0.01	0.01
query21	15.41	0.20	0.13
query22	4.88	0.05	0.05
query23	16.14	0.30	0.12
query24	3.06	0.42	0.30
query25	0.12	0.05	0.04
query26	0.72	0.21	0.16
query27	0.05	0.03	0.03
query28	3.53	0.73	0.36
query29	12.49	4.10	3.26
query30	0.28	0.14	0.14
query31	2.78	0.56	0.31
query32	3.24	0.60	0.48
query33	3.20	3.18	3.30
query34	15.62	3.90	3.26
query35	3.24	3.23	3.22
query36	0.56	0.45	0.43
query37	0.09	0.07	0.06
query38	0.05	0.05	0.05
query39	0.04	0.04	0.03
query40	0.18	0.14	0.14
query41	0.10	0.03	0.02
query42	0.03	0.02	0.02
query43	0.04	0.04	0.04
Total cold run time: 96.41 s
Total hot run time: 23.92 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 46.60% (48/103) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 76.70% (79/103) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq
linrrzqqq force-pushed the fix/cir-22040-profile-cleanup branch from a75c214 to c28bccc Compare October 4, 2026 16:52
@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot 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.

Complete static review of PR #68658 at c28bccc. The direct removeProfile(Profile) cleanup addresses the pre-registration ExecutionProfile leak, and retry cleanup now discards abandoned executions. Two distinct P2 diagnostic-profile defects remain and are reported inline.

Existing review context: r4174520825 (outer-retry statement duration) and r4174520817 (per-attempt phase times) still apply and are not reposted. The earlier P1 leak reports r4140101788 and r4143010094 are fixed at this head, so there are no still-applicable existing P0/P1 comments to carry. Other prior retry, Broker Load, merged-profile, Flight, and row-count threads were checked against this head and are either addressed or subsumed by the two inline findings.

Critical checkpoints:

  • Goal, scope, and tests: The core leak path is addressed; the source change is focused on profile ownership, retry finalization, and manager bookkeeping. Added mock-driven tests cover missing history, multiple execution profiles, Broker Load pruning, inner and outer retries, merged rendering, Flight, and stored output. They do not exercise the two inline failure conditions. No builds or tests were run under this review contract.
  • Concurrency and lifecycle: Query execution is serialized per connection, while backend reports and REST profile reads are asynchronous. Manager read/write locking fences live rendering against retry removal; late reports target the detached old execution object. Inner retry, outer replan, direct execute, local result, and Flight deferred finalization paths were traced. No separate lock-order or release defect was substantiated.
  • Conditions, compatibility, and parallel paths: The willRetry and outer handoff branches were checked against terminal and successful outcomes. No new configuration, FE/BE variable, wire or storage format, public REST behavior, or rolling-upgrade requirement was introduced. The REST authorization method rename preserves its lookup behavior.
  • Persistence, data writes, and errors: Profile spill and Broker Load ID pruning were reviewed; the attached execution IDs are removed by their own query IDs. There is no edit-log, transaction, committed-data, or FE/BE protocol change. Query failures still propagate; the inline findings concern incorrect retained diagnostics.
  • Performance and observability: The new plan-row reset runs only on retries and no material new hot-path cost was found. The inline findings and the two existing timing threads affect profile accuracy. No additional logging or metric defect was substantiated.

User focus: no additional focus was provided. Review convergence completed in three rounds; the final changed-file sweep found no unresolved candidate beyond the two inline findings and the already reported P2 timing issues. This is a complete static review.

@github-actions github-actions Bot 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.

Static review complete for PR #68658 at b730ef7. I found no new distinct inline issue. The stated FE leak path is addressed: removeProfile(Profile) removes attached execution IDs even when no history entry was published, and retry cleanup discards abandoned registrations before reusing the profile. The prior P1 inner retry and outer replan reports no longer apply to this head, so there are no existing blocking comment IDs to carry.

Two previously reported P2 issues still apply and are not reposted: an outer replan resets the profile's statement start, affecting total time and the retention threshold (duration thread); its shared SummaryProfile retains the first one-shot plan-finish timestamp across attempts, affecting schedule and fragment phase times (phase-time thread).

Review checkpoints:

  • Goal, scope, and tests: the cleanup targets registration before history publication and remains focused on FE profile/retry lifecycle. Added unit tests cover absent/present history, multiple execution IDs, Broker Load pruning, query/INSERT/MERGE retry cases, rendering, and Flight. This was static inspection only; no tests or builds were run, and the tests are not claimed as executed validation.
  • Concurrency and lifecycle: QeProcessor registration/reporting can overlap REST reads and background profile storage. Manager read/write locking fences manager-backed rendering against retry removal; Profile serializes its update/clear paths. The reviewed paths did not show a new lock-order cycle or blocking external I/O introduced under these locks. Inner and outer retries, terminal failures, empty commands, and Flight deferred close were traced; no new orphan was substantiated.
  • Configuration, compatibility, and parallel paths: no new configuration item, FE/BE variable, wire or storage format, or rolling-upgrade protocol change. Query, command, Flight, Broker Load, REST lookup, and archive/delete paths were checked. The changed Java manager method references have no stale in-repository callers.
  • Conditions, errors, and data safety: retry/finalization gates were traced through successful, cancelled, and planning-failure outcomes. This PR does not change transaction commit, data visibility, or EditLog behavior; profile storage pruning now removes each task's execution ID. No separate error-suppression or write-atomicity defect was substantiated.
  • Test results, observability, and performance: no result files were changed. Profile output is the affected observability surface; the two known timing inaccuracies are linked above. Cleanup adds work only on retry and traverses the current plan to clear derived row counts; no material new hot-path cost was identified. No further distinct issue remained after the final changed-file sweep.

User focus: none was supplied beyond a complete PR review.

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28972 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit b730ef741df0b142e7f943930d26feaac80a2ca8, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17606	5566	5491	5491
q2	2083	288	275	275
q3	10245	1369	822	822
q4	4678	470	361	361
q5	7433	787	534	534
q6	186	193	158	158
q7	758	792	599	599
q8	9253	1339	1094	1094
q9	5866	4442	4399	4399
q10	6826	1292	1030	1030
q11	436	260	235	235
q12	626	400	298	298
q13	18071	3054	2382	2382
q14	269	275	239	239
q15	q16	737	727	679	679
q17	1191	757	570	570
q18	7048	6240	6189	6189
q19	1229	962	607	607
q20	393	342	225	225
q21	5770	2513	2533	2513
q22	405	369	272	272
Total cold run time: 101109 ms
Total hot run time: 28972 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	6424	6455	6396	6396
q2	710	611	579	579
q3	5537	5686	5232	5232
q4	2008	2458	1593	1593
q5	5813	5546	5698	5546
q6	253	195	155	155
q7	2357	2022	1801	1801
q8	3109	2744	2679	2679
q9	8276	8076	7662	7662
q10	3663	3570	3235	3235
q11	589	428	384	384
q12	666	692	518	518
q13	2737	3059	2407	2407
q14	285	289	264	264
q15	q16	666	679	610	610
q17	7781	6913	6860	6860
q18	13087	12225	13076	12225
q19	907	777	770	770
q20	2216	2165	1927	1927
q21	5705	4712	4786	4712
q22	515	447	416	416
Total cold run time: 73304 ms
Total hot run time: 65971 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152108 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit b730ef741df0b142e7f943930d26feaac80a2ca8, data reload: false

query5	4308	597	456	456
query6	422	203	187	187
query7	4803	432	221	221
query8	322	186	168	168
query9	8796	3986	3972	3972
query10	448	308	252	252
query11	6032	3439	3201	3201
query12	146	87	84	84
query13	1249	446	323	323
query14	6511	4796	4482	4482
query14_1	4293	4362	4263	4263
query15	213	208	189	189
query16	959	438	413	413
query17	862	671	552	552
query18	2418	426	313	313
query19	193	162	140	140
query20	87	86	80	80
query21	209	140	121	121
query22	13107	13055	12837	12837
query23	13076	12401	12123	12123
query23_1	12259	12305	12345	12305
query24	7099	828	458	458
query24_1	458	471	472	471
query25	534	439	364	364
query26	1263	254	139	139
query27	2756	440	277	277
query28	4583	1924	1930	1924
query29	1559	585	463	463
query30	299	221	183	183
query31	880	766	653	653
query32	143	91	93	91
query33	510	311	250	250
query34	887	867	511	511
query35	759	766	665	665
query36	828	810	745	745
query37	125	103	94	94
query38	1826	1751	1720	1720
query39	727	733	676	676
query39_1	710	684	663	663
query40	225	117	99	99
query41	70	71	69	69
query42	90	88	85	85
query43	367	378	333	333
query44	1297	706	694	694
query45	180	176	162	162
query46	862	971	596	596
query47	3033	3046	2958	2958
query48	342	308	210	210
query49	577	417	295	295
query50	685	273	217	217
query51	10463	10253	10563	10253
query52	76	88	72	72
query53	184	207	152	152
query54	245	190	182	182
query55	70	69	67	67
query56	230	214	197	197
query57	1651	1581	1551	1551
query58	279	265	250	250
query59	2340	2388	2209	2209
query60	296	236	227	227
query61	148	149	146	146
query62	396	338	285	285
query63	189	157	179	157
query64	2634	976	772	772
query65	3493	3383	3418	3383
query66	1763	405	304	304
query67	20079	20045	20532	20045
query68	2990	1004	605	605
query69	377	281	246	246
query70	908	853	830	830
query71	299	227	208	208
query72	2772	2519	2263	2263
query73	516	535	296	296
query74	4613	4492	4323	4323
query75	2347	2310	1957	1957
query76	2292	1014	590	590
query77	353	406	302	302
query78	9053	9040	8387	8387
query79	980	894	521	521
query80	540	447	342	342
query81	533	321	276	276
query82	579	135	115	115
query83	299	193	183	183
query84	310	126	109	109
query85	802	415	358	358
query86	314	237	234	234
query87	2001	1942	1838	1838
query88	3579	2705	2668	2668
query89	341	304	266	266
query90	1944	183	181	181
query91	161	153	124	124
query92	95	84	88	84
query93	977	975	556	556
query94	461	311	265	265
query95	592	347	380	347
query96	663	518	236	236
query97	2458	2405	2295	2295
query98	160	151	149	149
query99	800	748	636	636
Total cold run time: 233794 ms
Total hot run time: 152108 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.52 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit b730ef741df0b142e7f943930d26feaac80a2ca8, data reload: false

query1	0.00	0.00	0.00
query2	0.10	0.05	0.05
query3	0.27	0.12	0.12
query4	1.60	0.12	0.12
query5	0.24	0.24	0.23
query6	1.17	0.68	0.68
query7	0.04	0.01	0.00
query8	0.05	0.04	0.04
query9	0.42	0.34	0.36
query10	0.57	0.62	0.61
query11	0.20	0.14	0.15
query12	0.18	0.15	0.14
query13	0.49	0.49	0.50
query14	0.98	0.98	0.95
query15	0.63	0.61	0.61
query16	0.33	0.34	0.37
query17	1.10	1.16	1.14
query18	0.22	0.20	0.21
query19	2.05	1.91	1.95
query20	0.02	0.02	0.02
query21	15.49	0.27	0.14
query22	4.38	0.05	0.05
query23	16.26	0.32	0.12
query24	3.12	0.63	0.41
query25	0.12	0.07	0.05
query26	1.30	0.24	0.15
query27	0.05	0.04	0.04
query28	1.83	0.60	0.40
query29	12.53	4.21	3.30
query30	0.29	0.14	0.14
query31	2.77	0.59	0.34
query32	3.22	0.61	0.53
query33	3.28	3.19	3.20
query34	15.47	3.97	3.41
query35	3.33	3.38	3.32
query36	0.55	0.45	0.47
query37	0.09	0.06	0.06
query38	0.04	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.14	0.14
query41	0.09	0.03	0.02
query42	0.03	0.03	0.04
query43	0.04	0.04	0.03
Total cold run time: 95.15 s
Total hot run time: 24.52 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 48.59% (69/142) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 83.80% (119/142) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 48.59% (69/142) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot 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.

Complete static review of PR #68658 at head 05808e3. All 12 changed files were covered, and the normal execution, normal profile, and separate risk-focused passes converged after one round with NO_NEW_VALUABLE_FINDINGS. No new inline findings remain.

Goal and tests: ProfileManager.removeProfile(Profile) now removes attached ExecutionProfiles even when no historical Profile entry was indexed, addressing the stated pre-dispatch leak. The added FE unit tests cover missing and existing summaries, retry cleanup, Broker Load pruning, phase resets, and rendered/stored profiles. This review inspected those tests but did not run builds or tests, as required by the review prompt.

Scope and correctness: The wider changes consistently clear abandoned retry execution/plan state and preserve the final attempt's summary. I traced direct queries, inner dispatch/fetch retries, outer cloud replans, INSERT/MERGE commands, Flight SQL, and Broker Load identity. The two existing P1 concerns (discussion IDs 4143010094 and 4140101788) are resolved by finalizing after retry decisions and removing attached execution IDs directly; neither remains a blocking comment on this head.

Concurrency and lifecycle: The executor, QeProcessor, profile manager GC/IO, and Flight request-close paths were checked. The examined manager-locked paths do not acquire the Profile monitor, and the Profile-to-manager cleanup has no inverse lock order in these paths. Flight terminal errors are finalized by FlightSqlConnectProcessor.close(); deferred Flight queries use their separate close path. No new registration, finalization, spill, or lock defect was substantiated.

Configuration, compatibility, and parallel paths: No new configuration or FE-BE wire variable was added. Retry fields are persisted with the existing Gson profile format, and old-profile field defaults remain available. Query, command, load, and REST lookup paths were checked; no transaction, EditLog, or user data-write behavior changed. The new conditions and retry-only resets have no substantiated performance regression.

Observability and remaining context: The added retry details and phase fields were checked against their producers and renderers. The QueryRetryTimes label counts failed attempts, including a first failure with no retry; the existing P2 thread at Profile.java:284 already asks for failed-attempt count to be distinguished from retry count, so this was not reposted. Other existing P2 concerns were checked against the current code and treated as duplicate context. There were no additional user focus points. This is a complete static review; executed validation is not claimed.

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29271 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 05808e3e07228f68dd2a5171bf05d9565dca3c5f, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17598	5681	5598	5598
q2	2138	303	250	250
q3	10252	1393	859	859
q4	4675	476	345	345
q5	7434	822	537	537
q6	187	187	158	158
q7	768	799	596	596
q8	9258	1309	1128	1128
q9	5701	4465	4468	4465
q10	6817	1298	1033	1033
q11	430	250	237	237
q12	627	396	282	282
q13	18075	3070	2398	2398
q14	276	272	245	245
q15	q16	742	728	694	694
q17	1206	735	567	567
q18	7111	6258	6200	6200
q19	1254	949	618	618
q20	387	341	231	231
q21	6001	2528	2679	2528
q22	416	359	302	302
Total cold run time: 101353 ms
Total hot run time: 29271 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	6671	6767	6834	6767
q2	759	616	534	534
q3	5579	5663	5274	5274
q4	2074	2209	1627	1627
q5	5713	5726	5877	5726
q6	248	190	145	145
q7	2281	2023	1833	1833
q8	3178	2718	2789	2718
q9	8258	8116	7924	7924
q10	3661	3611	3246	3246
q11	601	410	395	395
q12	667	708	498	498
q13	2767	3078	2404	2404
q14	280	284	258	258
q15	q16	663	718	617	617
q17	7863	6987	6809	6809
q18	13105	12263	13057	12263
q19	934	828	833	828
q20	2199	2186	1930	1930
q21	5926	4837	4873	4837
q22	512	464	402	402
Total cold run time: 73939 ms
Total hot run time: 67035 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152104 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 05808e3e07228f68dd2a5171bf05d9565dca3c5f, data reload: false

query5	4306	573	457	457
query6	427	211	192	192
query7	4801	452	223	223
query8	322	185	171	171
query9	8757	4057	4024	4024
query10	489	326	266	266
query11	5924	3417	3197	3197
query12	152	88	87	87
query13	1280	454	315	315
query14	6541	4838	4566	4566
query14_1	4302	4281	4280	4280
query15	208	205	187	187
query16	987	472	436	436
query17	852	668	558	558
query18	2424	423	311	311
query19	202	165	135	135
query20	84	79	79	79
query21	212	137	113	113
query22	13018	12964	12971	12964
query23	13249	12689	12082	12082
query23_1	12238	12194	12332	12194
query24	7088	835	474	474
query24_1	470	474	473	473
query25	534	426	366	366
query26	1262	267	139	139
query27	2783	449	281	281
query28	4588	1920	1940	1920
query29	1491	607	460	460
query30	312	226	189	189
query31	899	752	650	650
query32	134	107	100	100
query33	542	302	257	257
query34	914	855	496	496
query35	765	763	676	676
query36	813	811	728	728
query37	134	104	92	92
query38	1818	1779	1679	1679
query39	726	755	691	691
query39_1	672	697	719	697
query40	225	118	103	103
query41	74	70	71	70
query42	89	84	85	84
query43	374	389	327	327
query44	1315	699	699	699
query45	187	182	165	165
query46	833	997	556	556
query47	2813	2860	2853	2853
query48	305	308	217	217
query49	581	385	294	294
query50	667	272	213	213
query51	10210	10427	10343	10343
query52	85	80	72	72
query53	182	205	156	156
query54	254	191	175	175
query55	71	66	69	66
query56	220	211	218	211
query57	1624	1573	1598	1573
query58	273	256	245	245
query59	2346	2408	2152	2152
query60	281	237	227	227
query61	162	151	153	151
query62	392	349	289	289
query63	194	164	166	164
query64	2707	943	788	788
query65	3467	3374	3363	3363
query66	1771	417	302	302
query67	20277	20028	19845	19845
query68	3028	977	597	597
query69	386	294	238	238
query70	934	845	840	840
query71	298	220	212	212
query72	2706	2537	2195	2195
query73	515	529	307	307
query74	4592	4527	4290	4290
query75	2345	2299	1951	1951
query76	2287	1015	594	594
query77	369	404	304	304
query78	9145	9032	8504	8504
query79	963	901	525	525
query80	768	426	347	347
query81	556	324	271	271
query82	579	137	111	111
query83	302	208	181	181
query84	311	128	98	98
query85	969	430	401	401
query86	346	235	230	230
query87	2002	1952	1865	1865
query88	3615	2689	2658	2658
query89	341	295	264	264
query90	1725	181	177	177
query91	177	152	128	128
query92	99	78	90	78
query93	992	1003	551	551
query94	515	290	275	275
query95	594	412	326	326
query96	661	518	229	229
query97	2452	2424	2312	2312
query98	160	149	142	142
query99	775	763	648	648
Total cold run time: 233925 ms
Total hot run time: 152104 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.74 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 05808e3e07228f68dd2a5171bf05d9565dca3c5f, data reload: false

query1	0.01	0.01	0.00
query2	0.10	0.05	0.04
query3	0.27	0.12	0.11
query4	1.61	0.13	0.12
query5	0.29	0.26	0.26
query6	1.17	0.71	0.70
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.46	0.39	0.37
query10	0.59	0.64	0.60
query11	0.21	0.15	0.15
query12	0.18	0.15	0.15
query13	0.49	0.50	0.51
query14	0.99	0.98	0.97
query15	0.64	0.61	0.61
query16	0.37	0.37	0.37
query17	1.14	1.14	1.15
query18	0.26	0.24	0.25
query19	2.14	1.95	2.03
query20	0.02	0.01	0.02
query21	15.48	0.26	0.15
query22	4.39	0.05	0.05
query23	16.25	0.31	0.13
query24	3.00	0.72	0.45
query25	0.13	0.07	0.04
query26	1.70	0.27	0.15
query27	0.05	0.04	0.03
query28	2.09	0.63	0.44
query29	12.49	4.06	3.25
query30	0.29	0.14	0.13
query31	2.77	0.61	0.35
query32	3.22	0.64	0.54
query33	3.17	3.24	3.18
query34	15.62	4.01	3.38
query35	3.38	3.34	3.38
query36	0.56	0.46	0.45
query37	0.10	0.06	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.14	0.14
query41	0.09	0.03	0.02
query42	0.03	0.02	0.02
query43	0.04	0.03	0.04
Total cold run time: 96.15 s
Total hot run time: 24.74 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 46.39% (154/332) 🎉
Increment coverage report
Complete coverage report

@HappenLee HappenLee 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.

LGTM. This correctly fixes the execution profile leak that occurs when dispatch fails before profile registration, preventing orphaned profile objects. The fix is clean and well-scoped.

@924060929 924060929 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.

LGTM at 05808e3. Rechecked both correctness and fix placement: ProfileManager removes attached execution IDs independently of history publication, while StmtExecutor distinguishes an abandoned attempt from statement completion. Keeping normal unregister separate preserves asynchronous BE profile reporting, and retry cleanup preserves Broker Load aggregation. No blocking correctness or architecture issue found. Validation: static review only; tests were inspected, not run locally.

@mrhhsg
mrhhsg merged commit 04da0ca into apache:master Oct 12, 2026
38 checks passed
@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@linrrzqqq
linrrzqqq deleted the fix/cir-22040-profile-cleanup branch October 12, 2026 03:30
924060929 pushed a commit that referenced this pull request Oct 14, 2026
### What problem does this PR solve?

Related PR: #68658 

Problem Summary:

CloudInsertProfileRetryTest uses the ProfileManager singleton, which
starts a periodic storage thread. After an INSERT retry succeeds, this
thread can persist the finished profile and clear its execution profiles
before the test assertions run, causing intermittent failures.

Use a dedicated ProfileManager without starting its periodic thread and
redirect singleton access through a scoped static mock. Preserve the
explicit background storage probe to verify that profiles remain
ineligible for storage while the outer retry decision is pending.
CalvinKirs pushed a commit that referenced this pull request Nov 2, 2026
…69894)

### What problem does this PR solve?

Issue Number: N/A

Problem Summary:

Two FE unit tests depend on asynchronous work without owning its
complete lifecycle:

-
`SplitProducerTest.readThatOutlivesItsStatementLoadsNothingIntoTheClosedScope`
waits for the source-close signal and immediately checks the producer
completion count. `SplitProducer.finish` invokes the completion callback
after closing the source, so the assertion can run before that callback.
Wait for the assignment termination future, which completes after both
cleanup and the callback.
-
`StmtExecutorTest.testSuccessfulRetryRendersMergedProfileAndActualRows`
registers its profile with the global background `ProfileManager` while
also writing and reading the profile synchronously. Use a real manager
whose daemon is not started, scoped to this test, so automatic spill,
memory release and archival cannot interfere with the temporary storage
lifecycle. Preserve the real persistence path and all merged-profile and
actual-row assertions, and include the readback content in the failing
assertion.

The tests originated in #69718 and #68658 respectively. These test-only
changes are independent of the Coordinator refactoring in #69830. The
exact CI interleaving was not reproduced locally; both original tests
also passed local repeated execution. No production behavior changes.

### Release note

None

### Check List (For Author)

- Test: On this independent master-based branch, `./run-fe-ut.sh --run
'SplitProducerTest,StmtExecutorTest'` passed all 81 cases (26 + 55).
Before extraction, both target cases also passed 50 repetitions each
(179 executions across both classes); FE Checkstyle passed with 0
violations.
- Behavior changed: No
- Does this need documentation: No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.1.x dev/4.1.x-conflict dev/4.2.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants