Skip to content

[improvement](be) Support dynamic file cache capacity#65477

Open
gavinchou wants to merge 1 commit into
apache:masterfrom
gavinchou:gavin-file-cache-dynamic-resize
Open

[improvement](be) Support dynamic file cache capacity#65477
gavinchou wants to merge 1 commit into
apache:masterfrom
gavinchou:gavin-file-cache-dynamic-resize

Conversation

@gavinchou

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary:

File cache paths configured with zero capacity only resolved the disk size at startup. Runtime disk expansion or shrink did not update the effective capacity or the four queue limits. Manual reset returned free-form text, and shrinking synchronously could hold the cache lock while deleting many blocks.

This PR adds:

  • Explicit per-path AUTO/MANUAL capacity policy and generation tracking.
  • One disk snapshot per BlockFileCache monitor tick, shared by resize and disk-watermark checks.
  • A common capacity planner plus atomic BlockFileCache apply for total and queue limits.
  • Batched asynchronous eviction after shrink.
  • Factory prepare-all/apply-all orchestration and on-demand capacity aggregation.
  • Structured reset responses and an op=info endpoint.
  • SyncPoint-based unit tests for disk expansion, shrink, failure, and stale-plan races.

Release note

Support automatic runtime file cache capacity updates for disk-backed paths configured with zero capacity. The file cache reset API now accepts zero to restore AUTO mode and returns structured capacity details. op=info exposes per-path capacity, disk, queue, and resize state.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
      • BlockFileCacheTest.*:FileCacheActionTest.*: 141 tests, 138 passed, 3 disabled.
      • New capacity and HTTP smoke set: 16/16 passed.
      • Full BE UT: 9495 tests, 9438 passed, 57 skipped.
      • Release BE build: source custom_env.sh && sh build.sh --be -j 16.
      • Format: build-support/check-format.sh.
    • 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. Disk cache capacity 0 is a persistent AUTO mode; reset capacity 0 restores AUTO mode; queue quotas update with capacity; shrink converges asynchronously.
  • Does this need documentation?

    • No.
    • Yes. File Cache operations documentation should describe AUTO mode, the structured reset response, and op=info.

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: N/A

Related PR: N/A

Problem Summary: File cache paths configured with zero capacity only resolved the disk size at startup. Runtime disk expansion or shrink did not update the effective capacity or queue limits, manual reset returned free-form text, and synchronous shrink could hold the cache lock while deleting many blocks. This change adds explicit AUTO/MANUAL capacity policy, a shared disk snapshot and resize planner, atomic BlockFileCache quota publication, generation checks for automatic refresh, batched asynchronous shrink, on-demand Factory aggregation, and structured reset/info HTTP responses.

### Release note

Support automatic runtime file cache capacity updates for disk-backed paths configured with zero capacity. The file cache reset API now accepts zero to restore AUTO mode and returns structured capacity details, and op=info exposes per-path capacity, disk, queue, and resize state.

### Check List (For Author)

- Test:
    - Build: source custom_env.sh && sh build.sh --be -j 16
    - Unit Test: BlockFileCacheTest.* and FileCacheActionTest.* (141 tests, 138 passed, 3 disabled)
    - New Unit Test smoke: capacity policy, SyncPoint disk resize, Factory preflight, and FileCacheActionTest.* (16 passed)
    - Full BE Unit Test: 9495 tests, 9438 passed, 57 skipped
    - Format: build-support/check-format.sh
- Behavior changed: Yes. Disk cache capacity 0 is a persistent AUTO mode, reset capacity 0 restores AUTO mode, queue quotas update with capacity, and shrink converges asynchronously.
- Does this need documentation: Yes. File Cache operations documentation should describe AUTO mode, structured reset output, and op=info.
@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?

@gavinchou

Copy link
Copy Markdown
Contributor Author

run buildall

@gavinchou

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.

Reviewed PR #65477 for dynamic file cache capacity. I did not find a blocking correctness issue or any substantiated inline finding to raise.

Critical checkpoint conclusions:

  • Goal and scope: The PR implements AUTO/MANUAL file cache capacity policy, runtime disk refresh, structured reset/info responses, and asynchronous over-capacity shrink. The implementation is focused on BE file-cache capacity handling.
  • Data correctness: Capacity, policy, queue quotas, generation, and pending-eviction state are published under the cache mutex; stale auto-refresh plans are guarded by generation checks. I did not find a path where a stale auto refresh overwrites a later manual reset.
  • Concurrency and lifecycle: Factory reset/reload/create are serialized with _reset_mtx, per-cache mutation uses BlockFileCache::_mutex, and shrink work is handled by the existing background eviction thread. No concrete lock-order or publication-order bug was substantiated.
  • Configuration and compatibility: CachePath::init_settings() preserves zero disk capacity as AUTO mode, manual disk capacities are clamped by observed disk size, and memory AUTO is rejected. I did not find persisted-format or FE/BE protocol compatibility concerns.
  • Parallel paths: Startup create, reload, HTTP reset, background monitor refresh, info reporting, and multi-cache aggregation were checked. Multi-cache reset preflights plans before applying them.
  • Tests: New BE unit and HTTP action tests cover capacity policy building, auto refresh, stale generation skipping, factory aggregation/preflight, and structured HTTP reset/info output. I could not run BE tests in this runner because .worktree_initialized and thirdparty/installed are absent, so validation was static-only; git diff --check passed.
  • Observability: The PR adds runtime info fields and bvar metrics for capacity mode, disk capacity, pending eviction, and auto-resize success/failure; I did not find a missing-observability issue for this change.
  • User focus: No additional user-provided review focus was supplied.

Subagent conclusions: optimizer-rewrite appended no candidate findings, and tests-session-config appended no candidate findings. In convergence round 1, both subagents reviewed the same ledger and empty proposed final comment set and returned NO_NEW_VALUABLE_FINDINGS; no inline comments were submitted.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17597	4281	4205	4205
q2	2003	329	204	204
q3	10280	1481	833	833
q4	4734	469	335	335
q5	7891	856	587	587
q6	241	178	140	140
q7	816	849	628	628
q8	10561	1768	1698	1698
q9	5906	4442	4456	4442
q10	6781	1841	1533	1533
q11	507	357	317	317
q12	714	543	433	433
q13	18114	3401	2747	2747
q14	267	257	242	242
q15	q16	783	778	711	711
q17	1046	1009	948	948
q18	7021	5782	5579	5579
q19	1223	1311	1011	1011
q20	765	641	578	578
q21	5582	2639	2548	2548
q22	438	365	300	300
Total cold run time: 103270 ms
Total hot run time: 30019 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4476	4479	4457	4457
q2	312	321	216	216
q3	4614	5003	4440	4440
q4	2101	2209	1372	1372
q5	4575	4408	4465	4408
q6	373	219	163	163
q7	1950	1841	1668	1668
q8	2614	2249	2301	2249
q9	7958	7932	7938	7932
q10	4729	4718	4505	4505
q11	624	449	382	382
q12	749	748	534	534
q13	3294	3755	2951	2951
q14	302	300	283	283
q15	q16	717	738	657	657
q17	1458	1386	1378	1378
q18	8161	7645	6997	6997
q19	1099	1071	1106	1071
q20	2225	2206	1933	1933
q21	5367	4650	4614	4614
q22	524	471	405	405
Total cold run time: 58222 ms
Total hot run time: 52615 ms

@hello-stephen

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

query5	4312	645	502	502
query6	456	222	200	200
query7	4850	584	338	338
query8	336	190	170	170
query9	8758	4147	4117	4117
query10	488	367	304	304
query11	5874	2353	2160	2160
query12	157	104	100	100
query13	1306	582	435	435
query14	6296	5323	4956	4956
query14_1	4298	4301	4278	4278
query15	214	207	184	184
query16	1016	472	462	462
query17	1132	736	596	596
query18	2430	468	353	353
query19	206	194	178	178
query20	114	110	115	110
query21	234	160	135	135
query22	13756	13596	13406	13406
query23	17416	16591	16226	16226
query23_1	16336	16384	16379	16379
query24	7445	1756	1324	1324
query24_1	1339	1355	1357	1355
query25	579	470	404	404
query26	1351	360	224	224
query27	2598	599	392	392
query28	4466	2029	2020	2020
query29	1108	632	513	513
query30	345	276	226	226
query31	1126	1091	989	989
query32	115	65	67	65
query33	550	330	260	260
query34	1174	1144	646	646
query35	784	789	700	700
query36	1434	1405	1250	1250
query37	158	111	99	99
query38	1892	1706	1658	1658
query39	931	925	896	896
query39_1	876	909	891	891
query40	264	156	143	143
query41	70	62	63	62
query42	102	95	98	95
query43	336	335	294	294
query44	1394	786	785	785
query45	200	194	182	182
query46	1075	1162	755	755
query47	2390	2366	2253	2253
query48	412	373	297	297
query49	583	438	315	315
query50	1046	424	329	329
query51	10605	10788	10549	10549
query52	96	87	79	79
query53	270	273	202	202
query54	276	235	229	229
query55	75	72	67	67
query56	287	292	287	287
query57	1433	1411	1327	1327
query58	279	243	254	243
query59	1577	1602	1463	1463
query60	299	275	260	260
query61	156	148	151	148
query62	721	652	581	581
query63	244	200	205	200
query64	2801	1020	870	870
query65	4889	4801	4774	4774
query66	1832	501	376	376
query67	29442	29411	28706	28706
query68	3046	1516	968	968
query69	437	313	273	273
query70	1097	1015	956	956
query71	339	321	317	317
query72	3105	2871	2362	2362
query73	845	791	418	418
query74	5104	4956	4730	4730
query75	2610	2587	2237	2237
query76	2320	1164	780	780
query77	360	394	277	277
query78	12427	12272	11758	11758
query79	1468	1168	771	771
query80	1289	542	449	449
query81	535	332	284	284
query82	633	161	122	122
query83	369	325	300	300
query84	277	157	132	132
query85	954	579	566	566
query86	434	300	299	299
query87	1835	1815	1751	1751
query88	3729	2807	2802	2802
query89	457	405	356	356
query90	1878	211	198	198
query91	201	186	162	162
query92	63	58	54	54
query93	1656	1499	965	965
query94	702	376	291	291
query95	795	491	582	491
query96	1033	875	347	347
query97	2734	2710	2551	2551
query98	212	208	211	208
query99	1152	1155	1051	1051
Total cold run time: 265898 ms
Total hot run time: 180442 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.09	0.04	0.05
query3	0.25	0.14	0.14
query4	1.61	0.14	0.14
query5	0.24	0.28	0.22
query6	1.25	1.02	1.06
query7	0.04	0.01	0.01
query8	0.06	0.04	0.03
query9	0.38	0.31	0.32
query10	0.55	0.55	0.59
query11	0.19	0.14	0.14
query12	0.18	0.16	0.15
query13	0.48	0.48	0.48
query14	1.03	1.01	1.01
query15	0.61	0.59	0.59
query16	0.31	0.32	0.34
query17	1.12	1.12	1.10
query18	0.22	0.21	0.22
query19	2.05	1.98	2.00
query20	0.02	0.02	0.01
query21	15.42	0.24	0.13
query22	4.68	0.05	0.05
query23	16.15	0.32	0.12
query24	2.92	0.42	0.33
query25	0.11	0.05	0.05
query26	0.72	0.22	0.14
query27	0.04	0.04	0.04
query28	3.50	0.95	0.55
query29	12.48	4.01	3.21
query30	0.27	0.16	0.17
query31	2.78	0.59	0.31
query32	3.21	0.57	0.48
query33	3.20	3.16	3.16
query34	15.60	4.27	3.51
query35	3.49	3.50	3.53
query36	0.56	0.43	0.42
query37	0.09	0.06	0.06
query38	0.05	0.04	0.03
query39	0.04	0.04	0.03
query40	0.18	0.17	0.15
query41	0.09	0.03	0.04
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.34 s
Total hot run time: 24.97 s

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