Skip to content

[fix](fe) Guard auto partition result against concurrent drops#65282

Open
zclllyybb wants to merge 1 commit into
apache:masterfrom
zclllyybb:codex-fix-doris-26817
Open

[fix](fe) Guard auto partition result against concurrent drops#65282
zclllyybb wants to merge 1 commit into
apache:masterfrom
zclllyybb:codex-fix-doris-26817

Conversation

@zclllyybb

@zclllyybb zclllyybb commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Auto partition creation can race with dynamic partition retention. After new partitions are added, the response builder reads the table partition map and partition info without holding the table metadata lock. If a retention drop removes one of those partitions in the same window, the response builder can observe a missing partition or partition item and hit a null pointer while constructing partition and tablet metadata. This change snapshots the required partition metadata under the table read lock, returns a normal error when the partition was already dropped before the snapshot, and keeps tablet location/cache/backend resolution work outside the table lock.

Release note

None

Check List (For Author)

  • Test: Manual test

    • ./build.sh --fe

    • git diff --check -- fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java

  • Behavior changed: Yes, concurrent retention drops now return a retry error instead of throwing an FE null pointer.

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

@zclllyybb

Copy link
Copy Markdown
Contributor Author

/review

@zclllyybb

Copy link
Copy Markdown
Contributor Author

run buildall

@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. I did not find a PR-scoped issue that needs an inline comment.

Critical checkpoint conclusions:

  • Goal/test: the patch snapshots the auto-partition result metadata under the table read lock and returns a normal error when a just-created partition or partition item has already disappeared. Existing FE tests cover successful createPartition paths, and the PR reports ./build.sh --fe plus git diff --check; I did not rerun the FE build in this runner because thirdparty/installed/bin/protoc is missing.
  • Scope: the change is limited to FrontendServiceImpl.createPartition and stays focused on the concurrent retention-drop result-builder race.
  • Concurrency/locks: table metadata reads for partition count, partition item, tablet IDs, mutability, random-distribution state, and quorum now happen under the table read lock. Backend/cloud tablet-location and cache work remains outside that lock, so I did not find a metadata-lock RPC or external-IO issue.
  • Parallel paths: I inspected replacePartition as the closest parallel tablet-building path. It is an unchanged insert-overwrite path with its own task lock and comments allowing outside-transaction changes to fail naturally, so I did not find a distinct PR-scoped issue there.
  • Compatibility/persistence/config: no thrift schema, persisted metadata, storage format, or config item changes were introduced.
  • Tests: I did not see a new automated test for the concurrent-drop branch; the current test tree exercises successful auto-partition creation. Given the narrow guarded snapshot change and static review constraints, I am not blocking on this.
  • Observability/performance: the new retry errors are logged with partition context, and the heavier BE/cloud resolution remains outside the table lock.

Subagent conclusions:

  • optimizer-rewrite: no optimizer/rewrite candidate in the initial pass; convergence returned NO_NEW_VALUABLE_FINDINGS.
  • tests-session-config: no tests/session/config candidate in the initial pass; convergence returned NO_NEW_VALUABLE_FINDINGS.
  • Convergence round 1 completed with all live subagents reporting NO_NEW_VALUABLE_FINDINGS for the same ledger and empty inline comment set.

User focus: no additional user-provided focus was supplied.

Validation performed: read the review prompt, repository code-review skill, required AGENTS files, existing review context, changed-file list, and shared ledger; reviewed the GitHub patch and surrounding createPartition/replacePartition code paths; verified the live PR head is still 489c29166f6f0af3be744a5667ef319bae1f6a2b; confirmed there are no existing inline PR comments; ran git diff --check -- fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java.

@zclllyybb zclllyybb force-pushed the codex-fix-doris-26817 branch 2 times, most recently from 5327c7d to 5f01f5b Compare July 7, 2026 10:07
@zclllyybb

Copy link
Copy Markdown
Contributor Author

run buildall

@zclllyybb zclllyybb marked this pull request as ready for review July 7, 2026 10:20
@zclllyybb

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 result: request changes.

I found one correctness issue: the new snapshot pattern fixes createPartition, but the parallel replacePartition RPC still builds result metadata after releasing taskLock and can race task-group rollback of temp partitions into an FE NPE instead of returning a normal error status.

Checkpoint conclusions: goal is clear and mostly focused; concurrency/lifecycle is the main risk; no new config, persistence, or protocol format change; the functionally parallel code path is incomplete; tests were not runnable locally because this checkout is missing thirdparty/installed and thirdparty/installed/bin/protoc. Static validation: git diff --check -- fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java passed.

User focus: no additional user-provided focus.

Subagent conclusions: optimizer-rewrite reported NO_NEW_VALUABLE_FINDINGS. tests-session-config proposed TSC-1; main verification accepted it as MAIN-1 with narrowed evidence around replacePartition rollback rather than the broader retention wording. Convergence round 1 ended with both subagents reporting NO_NEW_VALUABLE_FINDINGS for the current ledger/comment set.

List<PartitionResultSnapshot> partitionSnapshots = new ArrayList<>();

olapTable.readLock();
try {

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.

Can we apply this same snapshot pattern to replacePartition before returning? The BE auto-detect overwrite path calls FrontendService.replacePartition with the same routing fields (be_endpoint, load_to_single_tablet, enable_adaptive_random_bucket, query_id) from VRowDistribution::_replace_overwriting_partition. In replacePartition, after taskLock is released, the response builder still does olapTable.getPartition(partitionId) and immediately dereferences partition.getId() / partitionInfo.getItem(...) without a table read lock or null check. InsertOverwriteManager.taskGroupFail can acquire the task lock after this point and roll back the temp partitions via InsertOverwriteUtil.dropPartitions, so a failed or cancelled auto-detect overwrite can still race this response builder into an FE NPE instead of a normal error status. Please snapshot the replace result metadata under the table read lock, or otherwise keep the task/table protection until the metadata needed for the response has been captured, and return a retry/failure status if a result partition or item has already disappeared.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17614	4198	4120	4120
q2	2023	327	204	204
q3	10272	1443	798	798
q4	4680	480	347	347
q5	7494	884	569	569
q6	182	175	149	149
q7	777	842	630	630
q8	9318	1622	1575	1575
q9	5593	4469	4399	4399
q10	6795	1816	1515	1515
q11	503	342	319	319
q12	706	550	423	423
q13	18177	3494	2775	2775
q14	272	278	250	250
q15	q16	794	782	708	708
q17	1015	994	1085	994
q18	7048	5709	5550	5550
q19	1283	1364	959	959
q20	761	651	531	531
q21	6014	2696	2413	2413
q22	457	370	301	301
Total cold run time: 101778 ms
Total hot run time: 29529 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4450	4405	4423	4405
q2	310	318	217	217
q3	4634	4956	4404	4404
q4	2082	2167	1379	1379
q5	4528	4399	4414	4399
q6	227	178	130	130
q7	1939	2023	1678	1678
q8	2609	2285	2274	2274
q9	8096	8134	8007	8007
q10	4731	4785	4275	4275
q11	605	439	379	379
q12	764	767	543	543
q13	3223	3647	3055	3055
q14	309	309	275	275
q15	q16	730	730	655	655
q17	1364	1344	1353	1344
q18	8024	7346	7292	7292
q19	1128	1118	1100	1100
q20	2232	2205	1958	1958
q21	5278	4547	4441	4441
q22	532	450	397	397
Total cold run time: 57795 ms
Total hot run time: 52607 ms

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Auto partition creation can race with dynamic partition retention after new partitions are added, and auto-detect insert-overwrite replacePartition can race with task-group rollback after taskLock is released. Both paths build RPC result partition metadata by reading table partitions and partition info; if a result partition or partition item disappears in that window, FE can hit a null pointer while constructing partition and tablet metadata. This change snapshots the required partition metadata through a shared helper under the table read lock. replacePartition captures that snapshot before releasing the task lock, while backend, cloud tablet-location, and cache work still run outside metadata locks. If a result partition has already disappeared before the snapshot, the RPC now returns a normal retry/failure status instead of throwing an FE null pointer.

### Release note

None

### Check List (For Author)

- Test: Manual test

    - mvn checkstyle:check -rf :fe-core

    - ./build.sh --fe

    - git diff --check -- fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java

- Behavior changed: Yes, concurrent result-partition drops now return a retry/failure error instead of throwing an FE null pointer.

- Does this need documentation: No
@hello-stephen

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

query5	4334	645	504	504
query6	493	226	211	211
query7	4875	600	335	335
query8	480	195	174	174
query9	8778	4021	4009	4009
query10	507	347	308	308
query11	5928	2362	2166	2166
query12	170	106	102	102
query13	1259	549	436	436
query14	6291	5332	4994	4994
query14_1	4314	4325	4300	4300
query15	226	210	190	190
query16	1045	449	457	449
query17	1155	734	585	585
query18	2484	492	367	367
query19	210	197	157	157
query20	127	108	121	108
query21	245	159	140	140
query22	13652	13622	13385	13385
query23	17382	16545	16197	16197
query23_1	16274	16332	16185	16185
query24	7704	1787	1304	1304
query24_1	1298	1302	1298	1298
query25	569	470	397	397
query26	1339	374	213	213
query27	2569	576	375	375
query28	4441	2045	2015	2015
query29	1062	621	500	500
query30	341	276	230	230
query31	1115	1098	988	988
query32	112	67	62	62
query33	533	329	259	259
query34	1162	1174	658	658
query35	793	783	689	689
query36	1385	1392	1219	1219
query37	151	109	99	99
query38	1874	1701	1657	1657
query39	947	904	920	904
query39_1	930	882	890	882
query40	261	160	140	140
query41	65	65	61	61
query42	94	89	93	89
query43	318	323	277	277
query44	1416	782	778	778
query45	204	196	175	175
query46	1092	1177	741	741
query47	2391	2313	2237	2237
query48	416	395	295	295
query49	571	432	325	325
query50	1024	436	326	326
query51	11090	10822	10655	10655
query52	84	86	73	73
query53	253	270	200	200
query54	275	233	210	210
query55	72	70	66	66
query56	292	272	274	272
query57	1431	1419	1331	1331
query58	280	282	265	265
query59	1567	1653	1417	1417
query60	306	262	246	246
query61	155	144	144	144
query62	713	659	590	590
query63	240	210	209	209
query64	2534	757	600	600
query65	4844	4759	4759	4759
query66	1809	497	388	388
query67	29763	29537	29426	29426
query68	3132	1537	1033	1033
query69	405	292	267	267
query70	1068	973	963	963
query71	345	315	313	313
query72	2946	2649	2332	2332
query73	854	773	446	446
query74	5130	4996	4737	4737
query75	2626	2587	2224	2224
query76	2296	1158	779	779
query77	356	380	279	279
query78	12246	12461	11709	11709
query79	1387	1198	752	752
query80	1315	542	465	465
query81	518	323	273	273
query82	580	161	125	125
query83	363	317	287	287
query84	273	166	169	166
query85	975	604	508	508
query86	452	293	292	292
query87	1821	1826	1745	1745
query88	3704	2784	2784	2784
query89	473	403	364	364
query90	2000	194	196	194
query91	201	192	163	163
query92	63	61	58	58
query93	1520	1528	972	972
query94	727	363	338	338
query95	758	594	468	468
query96	1046	772	368	368
query97	2685	2698	2530	2530
query98	214	206	201	201
query99	1169	1167	1035	1035
Total cold run time: 266011 ms
Total hot run time: 179564 ms

@zclllyybb zclllyybb force-pushed the codex-fix-doris-26817 branch from 5f01f5b to cdffecb Compare July 7, 2026 11:04
@zclllyybb

Copy link
Copy Markdown
Contributor Author

run buildall

1 similar comment
@zclllyybb

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17690	3951	3975	3951
q2	2101	312	194	194
q3	10212	1370	809	809
q4	4675	473	340	340
q5	7535	852	581	581
q6	179	173	135	135
q7	739	834	623	623
q8	9871	1503	1550	1503
q9	6340	4377	4365	4365
q10	6844	1791	1527	1527
q11	495	340	320	320
q12	722	541	437	437
q13	18080	3379	2741	2741
q14	275	253	238	238
q15	q16	776	765	700	700
q17	1011	921	915	915
q18	6919	5715	5639	5639
q19	1435	1232	976	976
q20	790	670	565	565
q21	5724	2562	2347	2347
q22	434	358	302	302
Total cold run time: 102847 ms
Total hot run time: 29208 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4351	4254	4244	4244
q2	284	315	225	225
q3	4579	4950	4392	4392
q4	2038	2161	1379	1379
q5	4418	4291	4297	4291
q6	226	180	128	128
q7	1750	2021	1616	1616
q8	2527	2181	2054	2054
q9	7794	7834	7722	7722
q10	4739	4706	4222	4222
q11	576	417	406	406
q12	786	755	540	540
q13	3438	3545	2951	2951
q14	313	342	281	281
q15	q16	729	721	684	684
q17	1361	1318	1338	1318
q18	8061	7429	6868	6868
q19	1083	1077	1046	1046
q20	2216	2217	1926	1926
q21	5211	4566	4426	4426
q22	535	467	417	417
Total cold run time: 57015 ms
Total hot run time: 51136 ms

@hello-stephen

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

query5	4323	633	494	494
query6	480	225	205	205
query7	4875	610	359	359
query8	332	188	176	176
query9	8769	4059	4064	4059
query10	479	333	288	288
query11	5861	2364	2205	2205
query12	158	105	100	100
query13	1302	592	421	421
query14	6270	5308	4964	4964
query14_1	4370	4293	4268	4268
query15	218	197	181	181
query16	1033	469	468	468
query17	1102	722	575	575
query18	2524	465	337	337
query19	203	183	153	153
query20	116	106	107	106
query21	232	166	143	143
query22	13685	13600	13423	13423
query23	17364	16531	16084	16084
query23_1	16322	16290	16257	16257
query24	7435	1736	1295	1295
query24_1	1341	1324	1308	1308
query25	579	478	399	399
query26	1522	368	221	221
query27	2903	568	389	389
query28	4544	2044	1987	1987
query29	1107	637	521	521
query30	334	264	237	237
query31	1117	1102	989	989
query32	108	65	63	63
query33	524	323	256	256
query34	1153	1104	649	649
query35	788	787	665	665
query36	1423	1402	1219	1219
query37	152	110	103	103
query38	1869	1722	1645	1645
query39	929	905	889	889
query39_1	878	861	888	861
query40	246	166	146	146
query41	76	73	69	69
query42	105	97	97	97
query43	327	327	295	295
query44	1422	776	767	767
query45	204	204	188	188
query46	1096	1166	747	747
query47	2330	2376	2237	2237
query48	390	384	297	297
query49	592	433	310	310
query50	1061	438	342	342
query51	10603	10637	10513	10513
query52	89	92	92	92
query53	272	293	208	208
query54	308	250	249	249
query55	91	74	68	68
query56	313	311	310	310
query57	1461	1398	1288	1288
query58	299	282	253	253
query59	1566	1648	1509	1509
query60	319	280	270	270
query61	173	170	199	170
query62	693	649	587	587
query63	248	200	205	200
query64	2818	1023	854	854
query65	4869	4783	4776	4776
query66	1807	512	391	391
query67	29557	29414	29361	29361
query68	3150	1578	920	920
query69	399	301	269	269
query70	1066	997	969	969
query71	356	315	321	315
query72	3005	2700	2296	2296
query73	862	785	453	453
query74	5119	4980	4772	4772
query75	2619	2579	2239	2239
query76	2358	1184	787	787
query77	347	370	300	300
query78	12324	12337	11728	11728
query79	1465	1166	815	815
query80	1321	550	463	463
query81	543	323	300	300
query82	600	162	127	127
query83	378	332	296	296
query84	286	157	133	133
query85	1002	600	499	499
query86	438	299	297	297
query87	1836	1840	1757	1757
query88	3673	2798	2795	2795
query89	456	403	361	361
query90	1976	206	199	199
query91	201	192	162	162
query92	67	67	59	59
query93	1576	1613	962	962
query94	725	372	315	315
query95	799	506	478	478
query96	1080	798	344	344
query97	2690	2678	2587	2587
query98	214	207	202	202
query99	1165	1187	1021	1021
Total cold run time: 266586 ms
Total hot run time: 180916 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.10	0.05	0.05
query3	0.26	0.12	0.13
query4	1.62	0.14	0.13
query5	0.24	0.22	0.26
query6	1.27	1.10	1.03
query7	0.04	0.00	0.01
query8	0.06	0.04	0.04
query9	0.38	0.31	0.31
query10	0.57	0.56	0.54
query11	0.18	0.14	0.14
query12	0.19	0.15	0.14
query13	0.47	0.48	0.49
query14	1.03	1.03	1.01
query15	0.63	0.59	0.60
query16	0.33	0.31	0.33
query17	1.09	1.14	1.11
query18	0.23	0.21	0.22
query19	2.05	1.98	1.96
query20	0.02	0.01	0.02
query21	15.42	0.24	0.13
query22	4.67	0.06	0.05
query23	16.13	0.32	0.11
query24	3.18	0.48	0.34
query25	0.11	0.05	0.04
query26	0.73	0.20	0.14
query27	0.03	0.04	0.03
query28	3.53	0.89	0.55
query29	12.53	4.03	3.22
query30	0.27	0.16	0.15
query31	2.78	0.60	0.30
query32	3.24	0.59	0.48
query33	3.21	3.25	3.18
query34	15.51	4.23	3.54
query35	3.55	3.55	3.56
query36	0.56	0.44	0.47
query37	0.09	0.07	0.07
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.17	0.15
query41	0.09	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.74 s
Total hot run time: 25.04 s

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants