Skip to content

[improvement](fe) Presize global cloud tablet route sets - #66447

Open
deardeng wants to merge 3 commits into
apache:masterfrom
deardeng:improve-cloud-rebalance-global-set-presizing
Open

[improvement](fe) Presize global cloud tablet route sets#66447
deardeng wants to merge 3 commits into
apache:masterfrom
deardeng:improve-cloud-rebalance-global-set-presizing

Conversation

@deardeng

@deardeng deardeng commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Related PR: #66378, #66389

Problem Summary: Cloud tablet route rebuilding creates new current and future global per-backend tablet sets on every statRouteInfo() round. Even when route cardinalities are stable, each ConcurrentHashMap-backed set starts without a sizing hint and repeatedly replaces its backing table while growing.

Use the corresponding previous-generation per-backend tablet count as the initial-capacity hint for each rebuilt global set. The previous maps already remain live until the temporary routes are complete, so the hint does not extend their lifetime. First-round and newly seen backends retain the default unsized newKeySet() behavior. Table- and partition-level indexes, routing contents, scheduling decisions, and incremental update semantics are unchanged.

A single-threaded JDK 17 multi-scale allocation model representing 4 million tablets across 4 clusters and both current/future global memberships estimates cumulative allocation on this path at 1.94 GiB before and 1.62 GiB after the change, a 16.14% reduction. Approximate post-GC retained heap is unchanged in the stable-cardinality model; these are path-level estimates, not production RSS measurements.

Release note

None

Check List (For Author)

  • Test: Unit Test
    • ./run-fe-ut.sh --run org.apache.doris.cloud.catalog.CloudTabletRebalancerTest (17 tests passed)
    • mvn checkstyle:check -pl fe-core (0 violations)
    • Single-threaded JDK 17 multi-scale allocation model
  • Behavior changed: No
  • Does this need documentation: No

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66378, apache#66389

Problem Summary: Cloud tablet route rebuilding creates new current and future global per-backend tablet sets on every `statRouteInfo()` round. Even when route cardinalities are stable, each `ConcurrentHashMap`-backed set starts without a sizing hint and repeatedly replaces its backing table while growing.

Use the corresponding previous-generation per-backend tablet count as the initial-capacity hint for each rebuilt global set. The previous maps already remain live until the temporary routes are complete, so the hint does not extend their lifetime. First-round and newly seen backends retain the default unsized `newKeySet()` behavior. Table- and partition-level indexes, routing contents, scheduling decisions, and incremental update semantics are unchanged.

A single-threaded JDK 17 multi-scale allocation model representing 4 million tablets across 4 clusters and both current/future global memberships estimates cumulative allocation on this path at 1.94 GiB before and 1.62 GiB after the change, a 16.14% reduction. Approximate post-GC retained heap is unchanged in the stable-cardinality model; these are path-level estimates, not production RSS measurements.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - `./run-fe-ut.sh --run org.apache.doris.cloud.catalog.CloudTabletRebalancerTest` (17 tests passed)
    - `mvn checkstyle:check -pl fe-core` (0 violations)
    - Single-threaded JDK 17 multi-scale allocation model
- Behavior changed: No
- Does this need documentation: No
@deardeng
deardeng requested a review from gavinchou as a code owner August 4, 2026 12:58
@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?

@deardeng

deardeng commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@deardeng

deardeng commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17708	3995	4009	3995
q2	2019	341	211	211
q3	10270	1402	805	805
q4	4677	478	343	343
q5	7495	848	547	547
q6	179	168	135	135
q7	736	781	598	598
q8	9335	1474	1548	1474
q9	5323	4055	4024	4024
q10	6711	1646	1351	1351
q11	509	347	333	333
q12	731	579	443	443
q13	18100	3256	2817	2817
q14	256	252	241	241
q15	q16	742	726	661	661
q17	969	910	1007	910
q18	6675	5626	5607	5607
q19	1182	1247	1058	1058
q20	829	675	588	588
q21	5702	2609	2380	2380
q22	437	356	307	307
Total cold run time: 100585 ms
Total hot run time: 28828 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4242	4166	4139	4139
q2	272	312	209	209
q3	4555	4946	4334	4334
q4	2154	2237	1435	1435
q5	4186	4092	4096	4092
q6	227	174	123	123
q7	1653	1576	1425	1425
q8	2380	2348	2154	2154
q9	7279	7400	7501	7400
q10	4319	4337	3870	3870
q11	554	415	390	390
q12	701	725	510	510
q13	3190	3444	2975	2975
q14	305	318	275	275
q15	q16	692	739	638	638
q17	1279	1281	1287	1281
q18	12188	11065	11800	11065
q19	1128	1141	1184	1141
q20	2231	2222	1936	1936
q21	5527	4905	4881	4881
q22	548	511	413	413
Total cold run time: 59610 ms
Total hot run time: 54686 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 166633 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 201163bf5c2aeab8eab68a3163381ea47f8cb1b2, data reload: false

query5	4293	582	461	461
query6	459	209	193	193
query7	4838	616	356	356
query8	321	157	145	145
query9	8742	4067	4062	4062
query10	443	363	301	301
query11	5823	2176	1995	1995
query12	167	98	101	98
query13	1271	653	451	451
query14	6177	4266	4027	4027
query14_1	3798	3781	3806	3781
query15	209	188	186	186
query16	980	475	476	475
query17	935	730	561	561
query18	2429	468	355	355
query19	205	193	150	150
query20	108	102	102	102
query21	233	159	140	140
query22	13087	13005	13584	13005
query23	16290	15665	14839	14839
query23_1	14989	14649	14796	14649
query24	7475	1695	1222	1222
query24_1	1247	1246	1273	1246
query25	590	415	361	361
query26	1304	350	201	201
query27	2643	597	386	386
query28	4552	2048	2003	2003
query29	1043	608	475	475
query30	333	257	220	220
query31	1181	1120	1040	1040
query32	110	95	57	57
query33	521	299	227	227
query34	1177	1170	629	629
query35	732	736	628	628
query36	763	770	726	726
query37	151	106	91	91
query38	1835	1752	1689	1689
query39	823	839	784	784
query39_1	797	790	781	781
query40	254	169	137	137
query41	62	61	60	60
query42	90	90	90	90
query43	310	309	280	280
query44	1446	781	772	772
query45	182	169	159	159
query46	1020	1181	743	743
query47	1532	1547	1451	1451
query48	398	413	309	309
query49	611	397	287	287
query50	1031	447	324	324
query51	10422	10384	10399	10384
query52	86	89	74	74
query53	259	278	201	201
query54	305	225	213	213
query55	73	72	67	67
query56	328	305	323	305
query57	1025	979	918	918
query58	288	261	260	260
query59	1580	1657	1454	1454
query60	310	290	270	270
query61	154	146	147	146
query62	402	328	265	265
query63	237	194	197	194
query64	2849	1018	831	831
query65	3906	3818	3815	3815
query66	1828	464	358	358
query67	28073	28044	27942	27942
query68	3187	1589	1052	1052
query69	410	310	250	250
query70	863	796	782	782
query71	357	337	308	308
query72	2982	2807	2272	2272
query73	871	811	403	403
query74	4638	4489	4302	4302
query75	2379	2334	1974	1974
query76	2304	1161	759	759
query77	351	368	285	285
query78	11220	11129	10581	10581
query79	1364	1129	762	762
query80	939	543	479	479
query81	529	319	277	277
query82	619	169	140	140
query83	396	325	297	297
query84	321	167	130	130
query85	962	627	510	510
query86	367	240	216	216
query87	1989	1959	1832	1832
query88	3729	2857	2785	2785
query89	391	315	289	289
query90	1853	197	190	190
query91	196	187	159	159
query92	63	57	55	55
query93	1530	1577	943	943
query94	621	327	323	323
query95	775	505	538	505
query96	1073	826	343	343
query97	2455	2444	2346	2346
query98	192	190	184	184
query99	734	731	609	609
Total cold run time: 252999 ms
Total hot run time: 166633 ms

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

Review status: changes requested. The review converged after two rounds: all normal full-coverage and risk-focused reviewers returned NO_NEW_VALUABLE_FINDINGS against the same frozen ledger, inline wording, and anchor. One P2 issue is reported inline: an unbounded previous-generation size hint can turn an abrupt route shrink into obsolete large allocations and repeated rebalancer OOME retries.

Critical checkpoint conclusions:

  • Goal, correctness, and proof: Reusing prior cardinality does avoid resize churn when cardinality is stable, and the tests verify current/future hint selection plus unchanged memberships. The implementation does not safely accomplish that goal across a normal large-to-small catalog transition; the missing sharp-shrink oracle is the inline blocker.
  • Scope and clarity: The production change is otherwise focused on the two global route sets. The helper split is clear and table/partition allocation behavior remains untouched.
  • Concurrency: Route-set rebuild, transfer, preheat, and failed-task rollback mutations run on the rebalancer daemon thread. Warmup RPC workers only enqueue failures, while the checker updates inflight/replica state rather than the captured route maps. No new race, lock-order issue, or heavy operation under a new lock was found.
  • Lifecycle: The two factories retain the matching prior current/future generation only for the synchronous rebuild and are not retained by computeIfAbsent. No reference leak or circular/static-initialization issue was found. The stale-capacity failure/retry lifecycle is covered by the inline issue.
  • Configuration and compatibility: No configuration, persistence format, FE-BE protocol, function symbol, or rolling-upgrade contract changes are introduced.
  • Parallel paths and conditions: Only full rebuilds use the sizing factories; direct transfer, preheat, rollback, and public/package helper paths preserve the default allocator. Null, first-round, absent-BE, and zero-size cases remain safe. The unbounded positive-size branch is the reported defect.
  • Tests and results: The new unit tests are deterministic and their membership/capacity assertions are correct, but the tracking override bypasses the production allocator and therefore masks the shrink hazard. Per the runner contract, I performed a static-only review and did not run builds or tests; the author reports the targeted FE unit test and Checkstyle pass.
  • Observability: No new steady-state metric or log requirement was identified. Existing daemon exception logging does not prevent the repeated allocation failure, so observability is not a substitute for the requested fix.
  • Transactions, persistence, and data writes: This patch changes only in-memory scheduling indexes; it adds no EditLog path, transaction boundary, metadata persistence, or user-data write.
  • Performance: Stable-cardinality allocation reduction is plausible, but the unbounded stale hint creates a material peak-memory/liveness regression during sharp shrink. No other hot-path allocation, repeated lookup, or route-content regression was found.
  • Other issues: No additional substantiated correctness, lifecycle, compatibility, error-handling, or test-result issue remains after duplicate suppression and final sweep.

User focus: .code-review.Bbg2kk/review_focus.txt contains no additional focus, so the full PR was reviewed without narrowing scope.

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.09	0.05	0.05
query3	0.24	0.14	0.13
query4	1.61	0.14	0.14
query5	0.24	0.22	0.22
query6	1.15	0.82	0.82
query7	0.03	0.01	0.01
query8	0.06	0.04	0.04
query9	0.40	0.30	0.33
query10	0.55	0.59	0.53
query11	0.18	0.15	0.14
query12	0.18	0.15	0.14
query13	0.46	0.47	0.46
query14	1.01	1.00	1.00
query15	0.61	0.58	0.60
query16	0.32	0.35	0.30
query17	1.09	1.08	1.07
query18	0.21	0.21	0.20
query19	2.05	1.99	1.91
query20	0.02	0.01	0.01
query21	15.45	0.21	0.14
query22	4.64	0.05	0.05
query23	16.13	0.30	0.13
query24	2.99	0.44	0.33
query25	0.11	0.06	0.04
query26	0.73	0.20	0.14
query27	0.04	0.04	0.02
query28	3.58	0.76	0.33
query29	12.47	4.05	3.20
query30	0.28	0.15	0.14
query31	2.78	0.55	0.32
query32	3.24	0.59	0.49
query33	3.18	3.15	3.25
query34	15.45	3.93	3.25
query35	3.23	3.20	3.20
query36	0.55	0.44	0.44
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.04	0.02	0.02
query40	0.18	0.15	0.15
query41	0.08	0.03	0.02
query42	0.03	0.03	0.02
query43	0.04	0.04	0.03
Total cold run time: 95.87 s
Total hot run time: 23.75 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 35.00% (14/40) 🎉
Increment coverage report
Complete coverage report

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66447

Problem Summary: Global cloud tablet route rebuilding uses the previous per-backend tablet count as an allocation hint. Add a focused unit-test reproducer showing that a stale count of two million is currently forwarded unchanged even when the rebuilt current and future routes each contain only one tablet. The test expects the hint to be bounded at 1,048,576 while preserving the rebuilt memberships.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - `./run-fe-ut.sh --run org.apache.doris.cloud.catalog.CloudTabletRebalancerTest` (expected RED: 18 tests run, the new sharp-shrink assertion is the only failure)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66447

Problem Summary: Cloud tablet route rebuilding uses the previous generation per-backend tablet count to presize current and future global route sets. After a sharp catalog shrink, an obsolete multi-million-tablet count could force both replacement sets to allocate oversized ConcurrentHashMap backing tables even when they retain only a few tablets. Bound the previous-generation hint at 1,048,576 entries while preserving exact hints below that threshold and unchanged route memberships. A single-threaded JDK 17 model matching the production uncompressed-oops mode estimates that rebuilding two one-tablet sets from a four-million-tablet previous count reduces allocation from 128.01 MiB to 32.01 MiB (75.00%) and approximate post-full-GC retained heap from 130.00 MiB to 34.00 MiB (73.85%); these are path-level model estimates, not production RSS measurements.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.cloud.catalog.CloudTabletRebalancerTest (18 tests passed)
    - cd fe && mvn checkstyle:check -pl fe-core (pass)
    - Single-threaded JDK 17 allocation model with compressed and uncompressed object pointers
- Behavior changed: No
- Does this need documentation: No
@deardeng

deardeng commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/30980454472

Please trigger /review again after that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants