Skip to content

[fix](filecache) skip redundant ttl scans for non-TTL tablets#65434

Open
freemandealer wants to merge 1 commit into
apache:masterfrom
freemandealer:pick-master-pr-65429
Open

[fix](filecache) skip redundant ttl scans for non-TTL tablets#65434
freemandealer wants to merge 1 commit into
apache:masterfrom
freemandealer:pick-master-pr-65429

Conversation

@freemandealer

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: None

Related PR: #65429

Problem Summary:

Pick #65429 to master.

The file cache TTL manager keeps registered tablet ids in _tablet_id_set. For ordinary non-TTL tablets, the old ttl_seconds <= 0 path always set need_convert_from_ttl = true, so every update round scanned cached blocks even when the tablet had never been recorded in _ttl_info_map.

This PR reduces the repeated CPU work for registered non-TTL tablets:

  • If a tablet was previously tracked as TTL, it is still converted back to NORMAL immediately when TTL is disabled.
  • If a tablet has no prior TTL info, the manager skips the per-round cached block scan.
  • A low-frequency reconciliation scan is kept every 20 update rounds, so cleanup behavior is preserved while avoiding scans on every round.

With the default file_cache_background_ttl_info_update_interval_ms = 180000, ordinary non-TTL tablets avoid the repeated per-round block scan that previously ran every 3 minutes.

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

Unit test on source PR branch:

DORIS_TOOLCHAIN=clang DISABLE_BE_JAVA_EXTENSIONS=ON ENABLE_INJECTION_POINT=ON ENABLE_CACHE_LOCK_DEBUG=0 ENABLE_PCH=0 sh run-be-ut.sh --run --filter='BlockFileCacheTtlMgrTest.*'

Result: 5 tests passed.

Pick validation on master:

git diff --check HEAD~1..HEAD -- be/src/io/cache/block_file_cache_ttl_mgr.cpp be/test/io/cache/block_file_cache_ttl_mgr_test.cpp
clang-format --dry-run --Werror be/src/io/cache/block_file_cache_ttl_mgr.cpp be/test/io/cache/block_file_cache_ttl_mgr_test.cpp
  • Behavior changed:

    • No.
    • Yes. Registered ordinary non-TTL tablets no longer scan cached blocks in every TTL manager update round.
  • 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

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

@freemandealer

Copy link
Copy Markdown
Member Author

run buildall

@freemandealer

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

Automated review completed for PR 65434 at e63d5d4.

I found one blocking issue in the TTL reconcile logic: the new full reconcile only handles tablet IDs already in the TTL manager's in-memory set, so persisted TTL blocks restored from metadata after restart can remain in the TTL queue when the tablet's current TTL is 0. See the inline comment.

Critical checkpoint conclusions: the change is small and focused, no new config is added, and lock ordering/thread structure is not materially changed. The lifecycle/compatibility checkpoint is not satisfied because persisted metadata restore/direct-load paths are parallel paths to request-time cell creation but do not register tablet IDs. Test coverage is incomplete because the new restart-style test manually registers the tablet ID instead of exercising production restore registration. No additional user-provided focus points were supplied.

Validation notes: I did not run local BE tests in this shallow/grafted checkout because thirdparty/installed is absent. The PR body reports BlockFileCacheTtlMgrTest.* passed on the source branch. GitHub's macOS BE UT failure exits before build due ERROR: The JAVA version is 25, it must be JDK-17, so I treated it as environment setup rather than evidence for this patch.

Subagent conclusions: optimizer-rewrite found no valuable optimizer/rewrite findings. tests-session-config proposed TSC-1, which I independently verified and accepted as the inline comment. Convergence round 1 ended with both live subagents replying NO_NEW_VALUABLE_FINDINGS for the final ledger/comment set.

need_convert_from_ttl = true;
// Periodically reconcile blocks restored from persisted TTL metadata,
// because _ttl_info_map is rebuilt only in memory after restart.
need_convert_from_ttl =

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.

This reconcile still misses the restart case described in the comment. The update loop only iterates tablet_ids_to_process, which is copied from _tablet_id_set; however startup restore from RocksDB goes through FSFileCacheStorage::load_cache_info_into_memory_from_db() -> mgr->add_cell(...), and BlockFileCache::add_cell() does not call register_tablet_id (the registration in this area only happens when split_range_into_cells() creates new request cells). After a BE restart, a persisted TTL block for a tablet whose current TTL is now 0 can therefore be loaded into the TTL queue without its tablet ID ever entering _tablet_id_set, so the 20-round reconcile will never scan or demote it unless a later cache miss happens to register the same tablet. The new test manually calls register_tablet_id, so it does not cover that production restore path. Please register restored/direct-loaded tablet IDs with the TTL manager or initialize the manager from the meta store, and add a restart-style test that does not manually register the tablet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not introduced by this PR

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17595	4065	4016	4016
q2	2069	323	215	215
q3	10215	1393	807	807
q4	4689	467	344	344
q5	7499	851	571	571
q6	192	173	139	139
q7	796	855	616	616
q8	9335	1555	1523	1523
q9	5609	4396	4352	4352
q10	6777	1783	1534	1534
q11	498	366	324	324
q12	726	544	434	434
q13	18085	3297	2691	2691
q14	265	268	240	240
q15	q16	789	778	716	716
q17	1047	1030	965	965
q18	7070	5857	5455	5455
q19	1296	1364	1080	1080
q20	763	651	540	540
q21	5974	2653	2405	2405
q22	429	353	293	293
Total cold run time: 101718 ms
Total hot run time: 29260 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4352	4442	4292	4292
q2	288	312	215	215
q3	4497	4917	4382	4382
q4	2059	2131	1375	1375
q5	4402	4305	4308	4305
q6	223	173	132	132
q7	1739	1682	2034	1682
q8	2644	2261	2232	2232
q9	8103	8256	7858	7858
q10	4686	4687	4192	4192
q11	622	421	380	380
q12	740	769	566	566
q13	3284	3594	2959	2959
q14	290	307	276	276
q15	q16	728	740	645	645
q17	1357	1316	1334	1316
q18	7784	7228	7297	7228
q19	1134	1104	1084	1084
q20	2208	2190	1943	1943
q21	5281	4561	4527	4527
q22	544	457	387	387
Total cold run time: 56965 ms
Total hot run time: 51976 ms

@freemandealer freemandealer dismissed github-actions[bot]’s stale review July 10, 2026 02:54

not introduced by this PR

@hello-stephen

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

query5	4311	663	497	497
query6	459	228	197	197
query7	4838	596	329	329
query8	336	192	171	171
query9	8795	4040	4044	4040
query10	488	336	295	295
query11	5967	2372	2112	2112
query12	164	107	102	102
query13	1288	601	434	434
query14	6273	5301	4973	4973
query14_1	4305	4312	4283	4283
query15	209	201	184	184
query16	1001	455	395	395
query17	952	717	585	585
query18	2434	477	352	352
query19	210	198	158	158
query20	111	110	105	105
query21	231	158	136	136
query22	13654	13567	13375	13375
query23	17478	16441	16212	16212
query23_1	16264	16183	16275	16183
query24	7602	1758	1285	1285
query24_1	1294	1305	1291	1291
query25	588	467	390	390
query26	1332	352	222	222
query27	2616	567	371	371
query28	4470	2052	2050	2050
query29	1121	667	502	502
query30	344	256	223	223
query31	1110	1093	972	972
query32	110	63	64	63
query33	531	333	269	269
query34	1194	1110	644	644
query35	784	806	659	659
query36	1401	1394	1173	1173
query37	158	109	93	93
query38	1872	1700	1672	1672
query39	925	919	909	909
query39_1	909	870	880	870
query40	243	155	139	139
query41	65	62	62	62
query42	92	88	92	88
query43	319	323	281	281
query44	1420	781	814	781
query45	202	187	176	176
query46	1079	1240	753	753
query47	2332	2333	2212	2212
query48	405	434	290	290
query49	570	436	319	319
query50	1077	435	330	330
query51	11010	10597	10704	10597
query52	93	86	73	73
query53	254	284	208	208
query54	273	252	210	210
query55	74	75	66	66
query56	285	303	298	298
query57	1425	1399	1315	1315
query58	276	251	254	251
query59	1534	1604	1471	1471
query60	309	266	246	246
query61	157	155	154	154
query62	692	651	590	590
query63	240	203	212	203
query64	2834	1070	855	855
query65	4846	4798	4751	4751
query66	1834	549	375	375
query67	29468	29488	29367	29367
query68	3223	1549	971	971
query69	403	306	269	269
query70	1034	989	925	925
query71	355	331	306	306
query72	3093	2742	2369	2369
query73	822	728	393	393
query74	5119	4962	4758	4758
query75	2607	2615	2222	2222
query76	2321	1187	773	773
query77	350	377	283	283
query78	12358	12162	11831	11831
query79	1380	1154	748	748
query80	1119	536	455	455
query81	513	328	280	280
query82	563	164	124	124
query83	406	326	290	290
query84	327	157	130	130
query85	991	602	509	509
query86	406	309	289	289
query87	1827	1813	1746	1746
query88	3710	2834	2811	2811
query89	450	398	357	357
query90	1819	205	193	193
query91	199	194	161	161
query92	64	63	54	54
query93	1543	1587	1026	1026
query94	645	347	316	316
query95	764	489	557	489
query96	1121	792	362	362
query97	2675	2700	2580	2580
query98	214	202	198	198
query99	1137	1169	1035	1035
Total cold run time: 265511 ms
Total hot run time: 180190 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.09	0.05	0.05
query3	0.26	0.14	0.13
query4	1.61	0.14	0.14
query5	0.26	0.24	0.23
query6	1.25	1.06	1.08
query7	0.04	0.00	0.00
query8	0.06	0.04	0.04
query9	0.40	0.32	0.33
query10	0.58	0.59	0.57
query11	0.18	0.14	0.14
query12	0.19	0.15	0.14
query13	0.48	0.47	0.48
query14	1.05	1.01	1.01
query15	0.60	0.59	0.58
query16	0.32	0.34	0.33
query17	1.09	1.18	1.15
query18	0.23	0.21	0.21
query19	2.10	1.97	1.96
query20	0.02	0.01	0.01
query21	15.43	0.23	0.13
query22	4.76	0.05	0.04
query23	16.11	0.32	0.13
query24	2.95	0.42	0.31
query25	0.13	0.05	0.04
query26	0.71	0.20	0.15
query27	0.04	0.04	0.03
query28	3.57	0.96	0.54
query29	12.52	4.04	3.21
query30	0.28	0.17	0.15
query31	2.78	0.62	0.31
query32	3.22	0.59	0.49
query33	3.16	3.23	3.25
query34	15.66	4.22	3.52
query35	3.55	3.50	3.56
query36	0.59	0.44	0.42
query37	0.08	0.06	0.07
query38	0.06	0.04	0.03
query39	0.04	0.03	0.03
query40	0.18	0.17	0.15
query41	0.09	0.04	0.03
query42	0.03	0.03	0.02
query43	0.05	0.04	0.04
Total cold run time: 96.81 s
Total hot run time: 25.11 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (6/6) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 56.81% (23455/41285)
Line Coverage 40.42% (228760/565921)
Region Coverage 36.36% (180879/497530)
Branch Coverage 37.45% (80747/215609)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (6/6) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.67% (30088/40296)
Line Coverage 58.62% (329828/562677)
Region Coverage 55.38% (276700/499597)
Branch Coverage 56.68% (122333/215844)

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