Skip to content

[refactor](fe) Modularize external metadata cache - #66382

Draft
924060929 wants to merge 2 commits into
apache:masterfrom
924060929:refactor-meta-cache-module
Draft

[refactor](fe) Modularize external metadata cache#66382
924060929 wants to merge 2 commits into
apache:masterfrom
924060929:refactor-meta-cache-module

Conversation

@924060929

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: #65126

Problem Summary: External metadata caching currently has parallel implementations in FE core and connector
modules. Cache policy, statistics, invalidation, lifecycle, and concurrency behavior are therefore duplicated,
while connector implementations still depend on FE-owned concepts.

This PR introduces an implementation-free MetaCache SPI module and a shared Caffeine-backed runtime module.
Common lifecycle, entry, registry, statistics, invalidation, and ID/name coordination are moved into these
modules. FE core retains only FE-specific catalog routing, configuration injection, refresh orchestration,
edit-log integration, and schema validation. Hive, HMS, Iceberg, Paimon, and MaxCompute consumers are migrated
to the shared implementation.

The refactor preserves the existing connector constructor policy and the guarded bulk-load contract. A guarded
bulk publication participates in the same short generation protocol as manual miss loads, exact-key actions, and
asynchronous refreshes, while REFRESH/flush invalidation continues to win without holding a publication monitor
during external I/O.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
      • All seven MetaCache runtime test classes: 87 tests
      • CachingHmsClientTest: 23 tests
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test
    • Full FE build: ./build.sh --fe -j8
    • Checkstyle: 0 violations
  • Behavior changed:

    • No. This is a module-boundary refactor that preserves connector cache, FE refresh, scoped
      invalidation, bulk-load generation-fence, and plugin class-identity behavior.
    • 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#65126

Problem Summary: External metadata caching had parallel implementations in FE core and connector modules, which duplicated cache policy, statistics, invalidation, and concurrency behavior. Introduce an implementation-free MetaCache SPI module and a shared Caffeine-backed runtime module, move the common lifecycle and entry machinery into them, and keep only FE-specific catalog routing, configuration, refresh orchestration, edit-log integration, and schema validation in FE core. Migrate Hive, HMS, Iceberg, Paimon, and MaxCompute consumers to the single shared implementation while preserving refresh, scoped invalidation, bulk-load generation fences, and plugin class identity.

### Release note

None

### Check List (For Author)

- Test: Unit Test and FE build
    - SPI and shared runtime unit tests
    - FE metadata cache and refresh unit tests
    - Affected connector cache unit tests and plugin package/install
    - ./build.sh --fe -j8
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#65126

Problem Summary: The shared MetaCache runtime selected FE defaults for the connector-facing convenience constructor and did not advance its publication generations for guarded bulk values. Source-migrated connector caches could unexpectedly enable automatic refresh and manual miss loading, while an older manual load, exact-key action, or refresh admitted before a guarded bulk result could outlive that result and publish stale cache or auxiliary state. Restore the documented connector defaults and make guarded values participate in the existing short generation protocol.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - All seven MetaCache runtime test classes (87 tests)
    - CachingHmsClientTest (23 tests)
    - Full FE build with ./build.sh --fe -j8
- Behavior changed: Yes. Restore connector constructor defaults and fence older admitted cache publications after guarded bulk puts.
- Does this need documentation: No
@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?

@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

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 the full PR; there was no additional user-provided focus beyond the whole change. I found no PR-introduced correctness issue that warrants an inline comment.

Checkpoint conclusions:

  • Goal and tests: The new JDK-only SPI plus shared Caffeine runtime matches the stated behavior-preserving modularization. The relocated and added tests cover cache policy, registry/lifecycle, concurrency/deadlock, compatibility, and connector consumers; the nested modules remain in the standard FE -am reactor path.
  • Scope and focus: Reviewed all 81 authoritative changed paths plus the required upstream/downstream lifecycle, classloader, assembly, configuration, metadata-stats, and test-runner paths. No extra review focus was supplied.
  • Concurrency: Traced manual miss loading, async refresh, public mutation, exact-key actions, invalidation, synchronous removal, and HMS bulk publication. The new coordination preserves the moved FE implementation's invalidation and mutation fences without introducing a new deadlock or lost-side-effect path. A possible same-key HMS completion-order race was checked against the deleted implementation and unchanged caller and dismissed as pre-existing, not introduced here.
  • Lifecycle and persistence: Catalog create/init, ordinary REFRESH, ALTER/reset, replay, drop/removal, routing, schema validation, index cleanup, and cache close ownership retain their prior distinctions. No transaction or external write path is changed.
  • Configuration and edge conditions: FE configuration is explicitly injected across the module boundary, compatibility overlays remain intact, and enabled/disabled, zero/no-expiry TTL, contextual-only, auto-refresh, and cold/hot entry cases retain their intended behavior.
  • Compatibility and parallel paths: Current/previous FE-plugin directions resolve the intended runtime through the parent-first connector namespace with plugin fallback, and the inspected assemblies ship the SPI/runtime and appropriate Caffeine dependency. Hive/HMS, Iceberg, Paimon, MaxCompute, default FE, and Doris-engine cache paths were all traced.
  • Observability and performance: The shared stats contract remains wired into metadata reporting. The refactor preserves the existing bounded stripe/publication model and does not introduce an identified hot-path or cache-capacity regression.
  • Other issues: Repository-wide checks found no remaining old package/artifact consumer, reflective/build reference, or parallel implementation left behind.

This was a static-only review as required by the review instructions; I did not run local builds or tests.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17883	4073	3970	3970
q2	2059	314	196	196
q3	10303	1437	813	813
q4	4680	480	341	341
q5	7515	922	571	571
q6	186	173	136	136
q7	777	790	599	599
q8	9350	1539	1501	1501
q9	5338	4026	4023	4023
q10	6751	1629	1348	1348
q11	511	374	327	327
q12	733	587	457	457
q13	18106	3274	2749	2749
q14	267	263	235	235
q15	q16	741	733	655	655
q17	956	993	1014	993
q18	7155	5745	5498	5498
q19	1402	1255	1061	1061
q20	807	705	604	604
q21	5872	2661	2358	2358
q22	425	358	298	298
Total cold run time: 101817 ms
Total hot run time: 28733 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4357	4196	4189	4189
q2	283	312	222	222
q3	4579	4903	4372	4372
q4	2152	2247	1428	1428
q5	4244	4127	4130	4127
q6	228	174	131	131
q7	1682	1603	1437	1437
q8	2730	2188	2191	2188
q9	7482	7376	7489	7376
q10	4315	4276	3862	3862
q11	553	389	384	384
q12	739	715	519	519
q13	3188	3488	2903	2903
q14	309	314	298	298
q15	q16	685	722	627	627
q17	1298	1303	1280	1280
q18	7813	7196	7208	7196
q19	1174	1090	1124	1090
q20	2198	2191	1914	1914
q21	5324	4600	4382	4382
q22	516	465	398	398
Total cold run time: 55849 ms
Total hot run time: 50323 ms

@hello-stephen

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

query5	4340	633	478	478
query6	468	223	201	201
query7	4879	594	349	349
query8	335	189	163	163
query9	8785	4045	4043	4043
query10	489	342	319	319
query11	5694	2207	2043	2043
query12	153	97	95	95
query13	1281	615	415	415
query14	6151	4719	4391	4391
query14_1	3849	3813	3810	3810
query15	204	205	177	177
query16	992	486	431	431
query17	934	691	570	570
query18	2482	486	345	345
query19	208	192	156	156
query20	107	107	104	104
query21	240	162	141	141
query22	13064	13106	12900	12900
query23	17417	16463	16090	16090
query23_1	16150	16150	16219	16150
query24	7476	1702	1243	1243
query24_1	1291	1267	1249	1249
query25	557	452	404	404
query26	1340	355	217	217
query27	2593	598	401	401
query28	4471	2067	2051	2051
query29	1105	632	501	501
query30	333	266	233	233
query31	1115	1086	970	970
query32	109	65	65	65
query33	535	357	236	236
query34	1174	1143	630	630
query35	736	738	640	640
query36	788	767	694	694
query37	153	102	90	90
query38	1836	1649	1573	1573
query39	826	820	798	798
query39_1	778	789	777	777
query40	243	167	146	146
query41	65	69	62	62
query42	94	90	91	90
query43	313	314	275	275
query44	1422	790	772	772
query45	178	180	164	164
query46	1051	1159	726	726
query47	1507	1553	1434	1434
query48	410	413	313	313
query49	577	439	294	294
query50	1043	435	340	340
query51	10532	10456	10523	10456
query52	85	86	75	75
query53	258	272	206	206
query54	288	247	221	221
query55	79	71	71	71
query56	293	281	301	281
query57	1047	996	927	927
query58	285	258	258	258
query59	1562	1583	1427	1427
query60	302	270	248	248
query61	155	152	152	152
query62	399	322	270	270
query63	229	201	189	189
query64	2866	1045	867	867
query65	3883	3790	3813	3790
query66	1848	476	359	359
query67	28303	28205	28082	28082
query68	3088	1633	949	949
query69	396	303	266	266
query70	868	838	821	821
query71	380	343	305	305
query72	3001	2674	2265	2265
query73	802	791	411	411
query74	4603	4531	4334	4334
query75	2375	2346	1981	1981
query76	2337	1123	791	791
query77	349	376	274	274
query78	11129	11108	10630	10630
query79	1417	1089	763	763
query80	647	542	453	453
query81	473	325	278	278
query82	565	151	114	114
query83	398	316	289	289
query84	330	162	126	126
query85	919	624	515	515
query86	323	235	225	225
query87	1805	1803	1688	1688
query88	3746	2841	2812	2812
query89	390	328	290	290
query90	1898	208	198	198
query91	207	185	161	161
query92	61	61	55	55
query93	1578	1494	943	943
query94	549	365	329	329
query95	806	588	474	474
query96	1008	868	356	356
query97	2486	2461	2333	2333
query98	205	196	199	196
query99	724	727	608	608
Total cold run time: 254920 ms
Total hot run time: 169704 ms

@hello-stephen

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

query1	0.00	0.01	0.00
query2	0.10	0.05	0.05
query3	0.26	0.13	0.14
query4	1.61	0.14	0.15
query5	0.24	0.23	0.22
query6	1.16	0.82	0.82
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.38	0.30	0.31
query10	0.57	0.54	0.55
query11	0.20	0.14	0.14
query12	0.18	0.14	0.15
query13	0.47	0.49	0.46
query14	1.00	1.00	1.00
query15	0.60	0.58	0.59
query16	0.33	0.32	0.33
query17	1.12	1.09	1.15
query18	0.21	0.20	0.19
query19	2.06	1.99	1.97
query20	0.01	0.01	0.01
query21	15.45	0.19	0.13
query22	4.89	0.05	0.05
query23	16.13	0.31	0.12
query24	3.03	0.44	0.34
query25	0.11	0.05	0.06
query26	0.74	0.20	0.15
query27	0.04	0.04	0.03
query28	3.56	0.78	0.35
query29	12.50	4.05	3.20
query30	0.28	0.15	0.16
query31	2.77	0.55	0.32
query32	3.22	0.58	0.48
query33	3.20	3.21	3.21
query34	15.63	4.01	3.30
query35	3.27	3.24	3.26
query36	0.57	0.42	0.42
query37	0.09	0.06	0.07
query38	0.05	0.04	0.04
query39	0.04	0.04	0.03
query40	0.16	0.15	0.15
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.04	0.03
Total cold run time: 96.51 s
Total hot run time: 24.06 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 27.27% (6/22) 🎉
Increment coverage report
Complete coverage report

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