Skip to content

[fix](fe) Avoid eager allocations in cloud tablet indexes - #66378

Open
deardeng wants to merge 1 commit into
apache:masterfrom
deardeng:fix-cloud-reblance-mem
Open

[fix](fe) Avoid eager allocations in cloud tablet indexes#66378
deardeng wants to merge 1 commit into
apache:masterfrom
deardeng:fix-cloud-reblance-mem

Conversation

@deardeng

@deardeng deardeng commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem Summary: Cloud tablet route-cache rebuilding calls fillBeToTablets for current and future placements. The previous putIfAbsent calls eagerly constructed up to six candidate maps and sets for every placement even when the keys already existed, and then performed separate lookups. Use the containers returned by computeIfAbsent at every level and add a focused unit test that verifies all six container paths while preserving the global, table, and partition index contents.

An isomorphic multi-scale JVM allocation model with 2 million entities, four-route fan-out, current/future passes, and three index scopes estimated cumulative allocation per modeled rebuild at 12.52 GiB before and 8.59 GiB after the change, saving 3.93 GiB (31.4%). For 4 million tablets, the fill-path cumulative-allocation reduction is expected to remain about 31% under comparable topology, while the absolute GiB saving depends on cluster and replica fan-out. The retained graph remained about 3.76 GiB and the peak proxy about 966 MiB, so this change does not claim a comparable steady-state heap or process-wide reduction. Timing samples were noisy, so no throughput improvement is claimed.

Release note

None

Check List (For Author)

  • Test: Unit Test / Manual benchmark
    • ./run-fe-ut.sh --run org.apache.doris.cloud.catalog.CloudTabletRebalancerTest#testFillBeToTabletsUsesComputedContainers
    • cd fe && mvn checkstyle:check -pl fe-core
    • Multi-scale isomorphic JVM allocation model: 12.52 GiB to 8.59 GiB cumulative allocation per modeled rebuild
  • 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#61318

Problem Summary: Cloud tablet route-cache rebuilding calls fillBeToTablets for current and future placements. The previous putIfAbsent calls eagerly constructed up to six candidate maps and sets for every placement even when the keys already existed, and then performed separate lookups. Use the containers returned by computeIfAbsent at every level and add a focused unit test that verifies all six container paths while preserving the global, table, and partition index contents.

An isomorphic multi-scale JVM allocation model with 2 million entities, four-route fan-out, current/future passes, and three index scopes estimated cumulative allocation per modeled rebuild at 12.52 GiB before and 8.59 GiB after the change, saving 3.93 GiB (31.4%). For 4 million tablets, the fill-path cumulative-allocation reduction is expected to remain about 31% under comparable topology, while the absolute GiB saving depends on cluster and replica fan-out. The retained graph remained about 3.76 GiB and the peak proxy about 966 MiB, so this change does not claim a comparable steady-state heap or process-wide reduction. Timing samples were noisy, so no throughput improvement is claimed.

### Release note

None

### Check List (For Author)

- Test: Unit Test / Manual benchmark
    - ./run-fe-ut.sh --run org.apache.doris.cloud.catalog.CloudTabletRebalancerTest#testFillBeToTabletsUsesComputedContainers
    - cd fe && mvn checkstyle:check -pl fe-core
    - Multi-scale isomorphic JVM allocation model: 12.52 GiB to 8.59 GiB cumulative allocation per modeled rebuild
- Behavior changed: No
- Does this need documentation: No
@deardeng
deardeng requested a review from gavinchou as a code owner August 3, 2026 08:35
@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 3, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

1 similar comment
@deardeng

deardeng commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@deardeng

deardeng commented Aug 3, 2026

Copy link
Copy Markdown
Contributor 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.

Review opinion: looks good. I found no blocking issue or substantiated inline finding.

Critical checkpoint conclusions:

  • Goal and proof: the change replaces all six eager candidate-container allocations and follow-up lookups in fillBeToTablets with the installed values returned by computeIfAbsent. The focused unit test distinguishes the old implementation at all six levels and verifies the global, table, and partition/index tablet contents.
  • Scope and clarity: the production change is small, focused, and reuses one existing helper for current and future route-cache rebuilds, direct balance moves, and warmup rollback. No parallel fill path was missed.
  • Concurrency: route-map writes occur in the single CloudTabletRebalancer master-daemon flow; warmup workers enqueue failures for that daemon rather than mutating these maps directly. The mapping functions are short, non-null, and non-reentrant, and computeIfAbsent returns the installed container identity before the nested mutation. No outer-entry removal or replacement can detach that identity.
  • Lifecycle: per-cycle maps are built and then published as before; later move/rollback operations mutate the same installed concurrent sets. No initialization, ownership, cleanup, or release behavior changes.
  • Conditions, configuration, compatibility, and persistence: no new condition, configuration, protocol, symbol, storage format, FE/BE variable, EditLog, transaction, or data-write behavior is introduced. Error handling and rolling-upgrade behavior are unchanged.
  • Performance: present keys no longer allocate discarded maps/sets or require a separate explicit lookup. The change adds no scan, retained state, or heavy work under a lock, and it appropriately makes no throughput claim.
  • Tests and result review: the new single-threaded counter test is deterministic, fails the prior putIfAbsent/get implementation, exercises absent and present backend-set keys plus present nested containers, and checks all three result scopes. The live CheckStyle check is green. The FE unit-test job is still pending; no local build or test was run because this review runner explicitly prohibits builds.
  • Observability: this is a behavior-preserving local allocation refactor with existing operational paths unchanged, so no new log or metric is warranted.
  • User focus: no additional focus was provided; the complete PR was reviewed.

Review completion: Round 1 included a complete-review subagent and a separate risk-focused concurrency/test-oracle subagent. Both returned NO_NEW_VALUABLE_FINDINGS; the final changed-file, candidate, live-thread, and head/base sweeps found no unresolved point. Inline comments: zero.

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 66.67% (6/9) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17622	4303	3939	3939
q2	2055	321	213	213
q3	10229	1408	809	809
q4	4680	467	339	339
q5	7540	861	574	574
q6	186	169	143	143
q7	744	826	594	594
q8	9317	1508	1426	1426
q9	5300	4075	4051	4051
q10	6771	1628	1380	1380
q11	500	369	332	332
q12	750	585	459	459
q13	18142	3310	2748	2748
q14	261	259	238	238
q15	q16	747	732	666	666
q17	934	948	997	948
q18	6931	5617	5568	5568
q19	1317	1300	1051	1051
q20	789	666	532	532
q21	5834	2687	2390	2390
q22	439	361	310	310
Total cold run time: 101088 ms
Total hot run time: 28710 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4258	4185	4166	4166
q2	289	316	214	214
q3	4571	4896	4331	4331
q4	2191	2256	1401	1401
q5	4255	4121	4185	4121
q6	225	170	132	132
q7	1718	1611	1426	1426
q8	2882	2246	2176	2176
q9	7516	7479	7549	7479
q10	4302	4292	3906	3906
q11	564	410	376	376
q12	715	734	504	504
q13	3233	3565	2962	2962
q14	293	301	283	283
q15	q16	697	714	644	644
q17	1356	1294	1320	1294
q18	8176	7192	7246	7192
q19	1126	1154	1133	1133
q20	2228	2213	1949	1949
q21	5482	4674	4439	4439
q22	510	455	403	403
Total cold run time: 56587 ms
Total hot run time: 50531 ms

@hello-stephen

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

query5	4344	618	483	483
query6	467	242	204	204
query7	4908	617	358	358
query8	332	187	175	175
query9	8754	4078	4080	4078
query10	462	350	314	314
query11	5907	2215	2021	2021
query12	156	100	94	94
query13	1251	604	427	427
query14	6141	4734	4452	4452
query14_1	3892	3886	3860	3860
query15	222	204	177	177
query16	1016	490	470	470
query17	1119	723	547	547
query18	2472	540	348	348
query19	202	179	144	144
query20	102	98	99	98
query21	226	159	137	137
query22	13147	13067	12936	12936
query23	17344	16451	16142	16142
query23_1	16176	16128	16162	16128
query24	7522	1691	1281	1281
query24_1	1277	1257	1281	1257
query25	530	441	347	347
query26	1341	347	211	211
query27	2587	616	380	380
query28	4468	2028	2003	2003
query29	1060	605	476	476
query30	343	268	220	220
query31	1103	1082	949	949
query32	108	63	59	59
query33	524	312	243	243
query34	1169	1167	643	643
query35	719	762	624	624
query36	789	808	709	709
query37	149	101	93	93
query38	1900	1655	1587	1587
query39	832	821	804	804
query39_1	799	787	795	787
query40	243	161	142	142
query41	65	66	66	66
query42	96	91	92	91
query43	326	318	283	283
query44	1417	794	784	784
query45	188	181	165	165
query46	1097	1162	749	749
query47	1561	1547	1382	1382
query48	417	413	304	304
query49	601	411	319	319
query50	1048	445	354	354
query51	10553	10690	10265	10265
query52	89	91	77	77
query53	250	274	197	197
query54	301	280	244	244
query55	78	76	71	71
query56	322	304	320	304
query57	1026	987	941	941
query58	299	285	273	273
query59	1571	1584	1449	1449
query60	322	288	263	263
query61	184	173	180	173
query62	405	322	276	276
query63	247	193	204	193
query64	2991	1176	996	996
query65	3909	3838	3841	3838
query66	1833	479	377	377
query67	28356	28246	28067	28067
query68	3176	1594	1061	1061
query69	421	330	281	281
query70	908	811	825	811
query71	381	345	341	341
query72	3079	2639	2289	2289
query73	843	767	474	474
query74	4595	4482	4352	4352
query75	2354	2340	2007	2007
query76	2292	1147	768	768
query77	346	384	285	285
query78	11074	11115	10694	10694
query79	1360	1196	730	730
query80	1149	547	492	492
query81	522	330	287	287
query82	556	149	117	117
query83	390	328	299	299
query84	282	161	128	128
query85	973	617	543	543
query86	368	242	236	236
query87	1809	1791	1705	1705
query88	3794	2847	2839	2839
query89	407	326	296	296
query90	1860	217	208	208
query91	207	192	170	170
query92	61	63	52	52
query93	1599	1603	987	987
query94	638	373	305	305
query95	791	506	479	479
query96	1072	813	368	368
query97	2458	2496	2335	2335
query98	199	198	195	195
query99	722	737	619	619
Total cold run time: 256473 ms
Total hot run time: 170674 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.05	0.05
query3	0.25	0.13	0.13
query4	1.61	0.14	0.14
query5	0.25	0.23	0.21
query6	1.15	0.83	0.79
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.36	0.31	0.30
query10	0.59	0.57	0.59
query11	0.18	0.13	0.14
query12	0.17	0.14	0.14
query13	0.46	0.46	0.46
query14	1.02	0.99	1.00
query15	0.60	0.59	0.61
query16	0.32	0.34	0.32
query17	1.12	1.07	1.09
query18	0.21	0.20	0.20
query19	2.00	1.94	1.93
query20	0.02	0.01	0.02
query21	15.43	0.19	0.13
query22	5.01	0.05	0.06
query23	16.12	0.30	0.13
query24	2.91	0.43	0.32
query25	0.11	0.05	0.05
query26	0.73	0.22	0.15
query27	0.05	0.04	0.04
query28	3.54	0.73	0.32
query29	12.56	4.07	3.22
query30	0.28	0.15	0.15
query31	2.77	0.59	0.36
query32	3.23	0.58	0.50
query33	3.12	3.26	3.20
query34	15.61	3.90	3.29
query35	3.19	3.25	3.26
query36	0.58	0.44	0.42
query37	0.08	0.06	0.07
query38	0.04	0.04	0.03
query39	0.04	0.03	0.03
query40	0.17	0.15	0.14
query41	0.09	0.03	0.02
query42	0.04	0.03	0.03
query43	0.05	0.03	0.04
Total cold run time: 96.27 s
Total hot run time: 24 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 90.00% (9/10) 🎉
Increment coverage report
Complete coverage report

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

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/3.1.x dev/4.0.x dev/4.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants