Skip to content

[fix](arrow-flight) Keep coordinator alive across GetFlightInfo/DoGet for external table scan#64799

Merged
morningman merged 6 commits into
apache:masterfrom
morningman:fix-62259-arrow-flight-split-source-lifecycle
Jul 18, 2026
Merged

[fix](arrow-flight) Keep coordinator alive across GetFlightInfo/DoGet for external table scan#64799
morningman merged 6 commits into
apache:masterfrom
morningman:fix-62259-arrow-flight-split-source-lifecycle

Conversation

@morningman

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #62259

Related PR: #64797

Problem Summary:

Arrow Flight SQL queries against Iceberg (and other external) tables in batch split mode crashed the BE / failed with Split source X is released.

Arrow Flight executes a query in two phases: GetFlightInfo (plan + submit to BE) and DoGet (the client pulls results from the BE). For an external table scan in batch split mode, the BE keeps scanning during DoGet and lazily fetches file splits from the FE via the fetchSplitBatch RPC, using an async SplitSource that the FE coordinator holds (through its scan nodes).

The FE closed the coordinator at the end of GetFlightInfo (StmtExecutor.executeAndSendResult's finallyCoordinator.close()ScanNode.stop()SplitSourceManager.removeSplitSource()) and also unregistered it (FlightSqlConnectProcessor.close()StmtExecutor.finalizeQuery()). So by the time the BE called fetchSplitBatch during DoGet, the SplitSource was already gone. The MySQL protocol is unaffected because plan + execute share one request, so the coordinator stays alive until all results are consumed.

This PR keeps the coordinator (and its SplitSource) alive across the two phases and cleans it up reliably:

  • StmtExecutor: for an Arrow Flight query that produces results on the BE (coordBase == coord), mark it deferred, register the executor on the ConnectContext, and skip the eager Coordinator.close() in the finally. A failed query (whose exec() threw) is not deferred and is closed as before.
  • ConnectContext: hold the deferred executors and add closeFlightSqlDeferredExecutors(), which closes their coordinators (releasing the SplitSource and the query queue slot) and unregisters the queries.
  • FlightSqlConnectProcessor.close(): do not finalize deferred executors.
  • DorisFlightSqlProducer: finalize the previous query's deferred coordinator when the next query starts on the connection.
  • FlightSqlConnectPoolMgr.unregisterConnection(): finalize deferred coordinators when the connection is torn down. All teardown paths (idle/query timeout, bearer token expiry, explicit CloseSession) reach here, so an abandoned connection cannot leak the coordinator.

Non-Arrow-Flight paths (MySQL, internal tables, point queries) are unchanged: deferredForArrowFlight can only become true for ARROW_FLIGHT_SQL.

The BE-side error-path hardening (so any fetchSplitBatch failure fails gracefully instead of crashing the BE) is handled separately in #64797.

Release note

Fix Arrow Flight SQL queries against external tables (e.g. Iceberg) failing with Split source X is released or crashing the BE in batch split mode.

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

Added regression-test/suites/external_table_p0/iceberg/test_iceberg_arrow_flight_split_source.groovy. It forces batch split mode on the Arrow Flight session (num_files_in_batch_mode=1), asserts via explain that the scan really uses the batch SplitSource path (approximate) so it cannot silently pass on the non-batch path, then scans format_v2.sample_cow_orc over Arrow Flight and checks all rows come back. The test runs in the external (docker) pipeline and is skipped when the Iceberg env or the Arrow Flight endpoint is not configured.

  • Behavior changed:

    • Yes. An Arrow Flight query's coordinator (and its external-table batch SplitSource) is now kept alive until the next query starts on the connection or the connection is torn down, instead of being closed at the end of GetFlightInfo.
  • Does this need documentation?

    • No.

🤖 Generated with Claude Code

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

@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17638	3995	3978	3978
q2	1998	306	194	194
q3	10365	1357	811	811
q4	4675	467	339	339
q5	7497	858	573	573
q6	177	168	132	132
q7	753	848	625	625
q8	9466	1574	1621	1574
q9	6073	4464	4453	4453
q10	6783	1790	1526	1526
q11	445	268	238	238
q12	637	413	290	290
q13	18108	3367	2742	2742
q14	269	260	234	234
q15	q16	786	789	710	710
q17	1091	1041	820	820
q18	6818	5668	5480	5480
q19	1398	1347	1028	1028
q20	468	401	260	260
q21	5873	2578	2376	2376
q22	423	357	298	298
Total cold run time: 101741 ms
Total hot run time: 28681 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4327	4226	4226	4226
q2	320	371	222	222
q3	4576	4960	4394	4394
q4	2032	2132	1356	1356
q5	4440	4307	4317	4307
q6	224	177	127	127
q7	1727	1623	1504	1504
q8	2703	2212	2274	2212
q9	8150	8088	8117	8088
q10	4818	4732	4287	4287
q11	593	424	370	370
q12	740	797	527	527
q13	3310	3549	2943	2943
q14	293	298	284	284
q15	q16	731	742	669	669
q17	1366	1374	1319	1319
q18	8155	7186	7463	7186
q19	1145	1095	1067	1067
q20	2226	2247	1987	1987
q21	5188	4527	4397	4397
q22	508	453	390	390
Total cold run time: 57572 ms
Total hot run time: 51862 ms

@hello-stephen

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

query5	4321	630	488	488
query6	425	183	168	168
query7	4798	548	307	307
query8	365	208	190	190
query9	8760	4006	3964	3964
query10	449	302	251	251
query11	5825	2337	2109	2109
query12	148	100	99	99
query13	1292	641	382	382
query14	6397	5359	5018	5018
query14_1	4376	4404	4386	4386
query15	206	198	176	176
query16	1017	460	431	431
query17	1140	726	584	584
query18	2772	487	351	351
query19	211	191	160	160
query20	109	114	109	109
query21	220	139	120	120
query22	13594	13681	13344	13344
query23	17361	16437	16108	16108
query23_1	16274	16186	16258	16186
query24	7614	1804	1306	1306
query24_1	1350	1284	1377	1284
query25	630	461	412	412
query26	1324	320	171	171
query27	2669	584	345	345
query28	4466	1987	1970	1970
query29	1092	638	497	497
query30	305	240	198	198
query31	1127	1073	961	961
query32	105	63	60	60
query33	537	322	273	273
query34	1145	1113	696	696
query35	739	776	674	674
query36	1351	1364	1238	1238
query37	151	105	86	86
query38	1883	1679	1636	1636
query39	926	917	893	893
query39_1	904	889	867	867
query40	211	123	97	97
query41	62	60	61	60
query42	85	85	84	84
query43	320	315	288	288
query44	1437	774	767	767
query45	189	186	179	179
query46	1079	1209	750	750
query47	2319	2363	2231	2231
query48	396	407	307	307
query49	621	461	351	351
query50	1035	363	268	268
query51	4415	4370	4288	4288
query52	79	80	70	70
query53	247	267	186	186
query54	258	216	192	192
query55	71	68	64	64
query56	227	230	209	209
query57	1433	1404	1306	1306
query58	242	218	211	211
query59	1571	1602	1430	1430
query60	286	246	224	224
query61	151	149	152	149
query62	687	650	587	587
query63	216	192	193	192
query64	2499	760	594	594
query65	4855	4758	4793	4758
query66	1742	475	337	337
query67	29722	29637	29537	29537
query68	3152	1642	977	977
query69	407	294	260	260
query70	1076	924	963	924
query71	295	234	197	197
query72	3101	2587	2332	2332
query73	849	736	446	446
query74	5109	4949	4788	4788
query75	2611	2578	2233	2233
query76	2326	1154	794	794
query77	350	359	286	286
query78	12369	12502	11911	11911
query79	1413	1163	770	770
query80	1312	484	395	395
query81	529	278	236	236
query82	659	160	119	119
query83	314	268	250	250
query84	269	144	118	118
query85	929	517	416	416
query86	420	304	271	271
query87	1824	1834	1761	1761
query88	3690	2791	2745	2745
query89	431	379	329	329
query90	1980	177	178	177
query91	171	176	140	140
query92	66	60	53	53
query93	1534	1480	820	820
query94	712	362	310	310
query95	692	392	351	351
query96	1119	778	350	350
query97	2690	2688	2542	2542
query98	218	208	203	203
query99	1170	1143	1018	1018
Total cold run time: 259104 ms
Total hot run time: 172304 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.09	0.05	0.05
query3	0.25	0.14	0.14
query4	1.61	0.14	0.14
query5	0.25	0.22	0.22
query6	1.26	1.08	1.09
query7	0.03	0.01	0.00
query8	0.08	0.04	0.03
query9	0.37	0.33	0.30
query10	0.54	0.58	0.54
query11	0.18	0.14	0.13
query12	0.18	0.14	0.14
query13	0.47	0.47	0.46
query14	1.02	1.00	1.01
query15	0.60	0.58	0.59
query16	0.30	0.32	0.32
query17	1.07	1.10	1.13
query18	0.23	0.21	0.21
query19	2.00	1.94	1.92
query20	0.02	0.01	0.01
query21	15.45	0.23	0.14
query22	4.80	0.05	0.04
query23	16.14	0.30	0.12
query24	2.97	0.43	0.32
query25	0.10	0.04	0.04
query26	0.72	0.21	0.16
query27	0.04	0.04	0.04
query28	3.53	0.91	0.57
query29	12.48	4.27	3.43
query30	0.29	0.15	0.18
query31	2.78	0.58	0.31
query32	3.23	0.61	0.49
query33	3.22	3.26	3.21
query34	15.59	4.22	3.51
query35	3.55	3.53	3.45
query36	0.56	0.43	0.42
query37	0.08	0.06	0.06
query38	0.06	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.16	0.16
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.54 s
Total hot run time: 25.16 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 77.14% (27/35) 🎉
Increment coverage report
Complete coverage report

@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17626	4089	4009	4009
q2	1998	305	189	189
q3	10335	1437	828	828
q4	4717	475	337	337
q5	7607	871	561	561
q6	217	168	139	139
q7	766	854	637	637
q8	10543	1582	1647	1582
q9	5855	4546	4490	4490
q10	6810	1789	1514	1514
q11	434	280	240	240
q12	636	423	293	293
q13	18106	3402	2778	2778
q14	272	263	242	242
q15	q16	787	774	711	711
q17	1000	904	884	884
q18	6961	5647	5687	5647
q19	1218	1294	1031	1031
q20	499	408	260	260
q21	5576	2603	2467	2467
q22	426	363	308	308
Total cold run time: 102389 ms
Total hot run time: 29147 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4335	4236	4264	4236
q2	315	349	230	230
q3	4540	4945	4372	4372
q4	2074	2167	1372	1372
q5	4420	4276	4257	4257
q6	234	179	128	128
q7	1719	1805	1807	1805
q8	2519	2178	2044	2044
q9	8069	8116	8108	8108
q10	4817	4770	4254	4254
q11	569	429	379	379
q12	732	745	533	533
q13	3532	3527	2962	2962
q14	317	294	268	268
q15	q16	754	767	672	672
q17	1379	1329	1326	1326
q18	8017	7445	7200	7200
q19	1120	1076	1116	1076
q20	2223	2234	1946	1946
q21	5302	4670	4511	4511
q22	525	461	408	408
Total cold run time: 57512 ms
Total hot run time: 52087 ms

@hello-stephen

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

query5	4349	625	487	487
query6	438	186	167	167
query7	4924	579	321	321
query8	369	211	199	199
query9	8755	4112	4135	4112
query10	450	311	281	281
query11	5759	2353	2119	2119
query12	161	106	100	100
query13	1263	617	430	430
query14	6458	5377	5028	5028
query14_1	4384	4365	4388	4365
query15	206	204	173	173
query16	1020	473	420	420
query17	1105	687	556	556
query18	2509	482	337	337
query19	200	178	143	143
query20	106	109	105	105
query21	213	142	118	118
query22	13691	13659	13370	13370
query23	17476	16522	16117	16117
query23_1	16256	16256	16207	16207
query24	7489	1758	1311	1311
query24_1	1329	1325	1292	1292
query25	590	459	399	399
query26	1321	346	167	167
query27	2611	559	314	314
query28	4485	2063	2065	2063
query29	1093	626	500	500
query30	332	241	200	200
query31	1122	1083	971	971
query32	122	64	61	61
query33	532	324	265	265
query34	1149	1132	654	654
query35	769	804	688	688
query36	1400	1417	1286	1286
query37	161	113	93	93
query38	1909	1740	1640	1640
query39	940	918	907	907
query39_1	902	883	867	867
query40	224	123	105	105
query41	73	67	67	67
query42	90	90	93	90
query43	323	330	280	280
query44	1473	783	793	783
query45	200	190	181	181
query46	1110	1209	785	785
query47	2440	2367	2189	2189
query48	427	432	311	311
query49	638	464	374	374
query50	1096	381	265	265
query51	4475	4458	4317	4317
query52	83	85	79	79
query53	265	266	198	198
query54	285	250	228	228
query55	76	73	69	69
query56	261	242	225	225
query57	1460	1430	1319	1319
query58	256	244	223	223
query59	1590	1679	1440	1440
query60	303	264	232	232
query61	205	149	145	145
query62	698	646	578	578
query63	224	199	192	192
query64	2519	767	606	606
query65	4876	4740	4786	4740
query66	1768	469	347	347
query67	29845	29815	29664	29664
query68	2996	1601	978	978
query69	400	302	261	261
query70	1098	906	968	906
query71	286	239	209	209
query72	3006	2417	2376	2376
query73	826	751	430	430
query74	5133	4984	4774	4774
query75	2625	2589	2254	2254
query76	2339	1213	811	811
query77	353	395	295	295
query78	12600	12574	11896	11896
query79	1905	1219	791	791
query80	1310	470	407	407
query81	533	297	246	246
query82	613	155	125	125
query83	315	271	244	244
query84	258	148	115	115
query85	897	510	431	431
query86	430	304	276	276
query87	1831	1830	1779	1779
query88	3778	2829	2865	2829
query89	441	395	335	335
query90	1860	191	188	188
query91	171	170	139	139
query92	69	59	57	57
query93	1680	1431	894	894
query94	719	328	311	311
query95	682	475	347	347
query96	1111	793	361	361
query97	2731	2691	2554	2554
query98	210	209	200	200
query99	1182	1134	1044	1044
Total cold run time: 260102 ms
Total hot run time: 173041 ms

@hello-stephen

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

query1	0.01	0.00	0.01
query2	0.10	0.05	0.04
query3	0.26	0.13	0.12
query4	1.61	0.13	0.14
query5	0.24	0.22	0.22
query6	1.21	1.06	1.06
query7	0.04	0.00	0.00
query8	0.06	0.04	0.04
query9	0.38	0.32	0.31
query10	0.56	0.54	0.55
query11	0.19	0.14	0.14
query12	0.18	0.15	0.14
query13	0.47	0.48	0.48
query14	1.01	1.02	1.02
query15	0.62	0.60	0.62
query16	0.31	0.32	0.33
query17	1.12	1.13	1.11
query18	0.21	0.21	0.20
query19	2.00	1.94	1.96
query20	0.02	0.02	0.01
query21	15.42	0.21	0.13
query22	4.93	0.06	0.05
query23	16.08	0.30	0.13
query24	3.00	0.41	0.32
query25	0.10	0.05	0.04
query26	0.73	0.21	0.14
query27	0.03	0.04	0.03
query28	3.54	0.89	0.53
query29	12.48	4.32	3.49
query30	0.28	0.15	0.16
query31	2.77	0.61	0.31
query32	3.22	0.59	0.49
query33	3.23	3.28	3.25
query34	15.77	4.19	3.53
query35	3.54	3.51	3.59
query36	0.55	0.44	0.43
query37	0.09	0.06	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.16	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.8 s
Total hot run time: 25.31 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 77.14% (27/35) 🎉
Increment coverage report
Complete coverage report

@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17588	4175	4123	4123
q2	1992	327	186	186
q3	10302	1486	850	850
q4	4704	512	339	339
q5	7656	871	591	591
q6	215	183	140	140
q7	814	851	625	625
q8	10145	1668	1687	1668
q9	6070	4581	4527	4527
q10	6825	1839	1516	1516
q11	461	280	242	242
q12	650	476	297	297
q13	18069	3515	2783	2783
q14	276	265	239	239
q15	q16	795	777	706	706
q17	1017	1053	1025	1025
q18	7255	5767	5677	5677
q19	1177	1319	1182	1182
q20	497	414	267	267
q21	5717	2672	2425	2425
q22	449	362	300	300
Total cold run time: 102674 ms
Total hot run time: 29708 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4566	4486	4492	4486
q2	332	362	239	239
q3	4740	5098	4447	4447
q4	2317	2343	1397	1397
q5	4670	4497	4699	4497
q6	309	242	159	159
q7	2258	1774	1634	1634
q8	2781	2348	2332	2332
q9	8418	8406	8369	8369
q10	5114	5158	4327	4327
q11	632	419	397	397
q12	826	801	550	550
q13	3360	3774	2977	2977
q14	317	310	267	267
q15	q16	749	761	655	655
q17	1447	1401	1350	1350
q18	8471	7317	6965	6965
q19	1139	1087	1103	1087
q20	2268	2243	1942	1942
q21	5685	4862	4653	4653
q22	534	460	420	420
Total cold run time: 60933 ms
Total hot run time: 53150 ms

@hello-stephen

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

query5	4311	635	476	476
query6	434	188	175	175
query7	4819	554	316	316
query8	340	185	171	171
query9	8759	4028	4062	4028
query10	445	309	267	267
query11	5918	2332	2145	2145
query12	152	101	95	95
query13	1260	619	434	434
query14	6275	5289	4939	4939
query14_1	4291	4260	4292	4260
query15	214	202	185	185
query16	999	460	389	389
query17	1131	731	589	589
query18	2484	502	351	351
query19	207	192	173	173
query20	114	109	108	108
query21	216	138	116	116
query22	13621	13544	13384	13384
query23	17269	16590	16227	16227
query23_1	16251	16333	16185	16185
query24	7452	1750	1298	1298
query24_1	1322	1299	1272	1272
query25	545	440	359	359
query26	1275	314	164	164
query27	2694	576	353	353
query28	4474	2037	2019	2019
query29	1086	627	479	479
query30	314	233	198	198
query31	1096	1068	945	945
query32	107	58	58	58
query33	521	307	258	258
query34	1160	1160	632	632
query35	762	779	672	672
query36	1411	1422	1199	1199
query37	156	105	91	91
query38	1885	1719	1665	1665
query39	938	923	899	899
query39_1	870	888	890	888
query40	223	134	102	102
query41	66	62	64	62
query42	88	94	88	88
query43	318	319	281	281
query44	1417	779	787	779
query45	207	184	183	183
query46	1042	1189	754	754
query47	2368	2363	2237	2237
query48	415	375	300	300
query49	567	423	307	307
query50	991	360	253	253
query51	4385	4453	4398	4398
query52	78	82	71	71
query53	249	255	190	190
query54	266	231	225	225
query55	72	67	64	64
query56	226	206	223	206
query57	1438	1414	1308	1308
query58	234	214	198	198
query59	1543	1664	1469	1469
query60	280	243	231	231
query61	152	141	146	141
query62	678	649	581	581
query63	228	206	189	189
query64	2522	766	599	599
query65	4892	4731	4777	4731
query66	1781	451	334	334
query67	29219	28871	28586	28586
query68	3233	1610	881	881
query69	408	292	279	279
query70	1053	987	987	987
query71	290	232	216	216
query72	2963	2693	2321	2321
query73	874	776	456	456
query74	5089	4979	4730	4730
query75	2570	2548	2159	2159
query76	2306	1183	787	787
query77	348	380	267	267
query78	12308	12337	11900	11900
query79	1227	1197	772	772
query80	518	476	371	371
query81	444	284	241	241
query82	235	154	119	119
query83	269	272	241	241
query84	257	142	113	113
query85	819	521	410	410
query86	322	281	273	273
query87	1814	1818	1776	1776
query88	3667	2814	2777	2777
query89	408	386	325	325
query90	2152	174	190	174
query91	190	176	147	147
query92	66	63	58	58
query93	1456	1452	934	934
query94	544	370	325	325
query95	700	373	453	373
query96	1053	825	344	344
query97	2765	2683	2564	2564
query98	216	217	197	197
query99	1190	1163	1029	1029
Total cold run time: 255677 ms
Total hot run time: 171061 ms

@hello-stephen

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

query1	0.01	0.00	0.00
query2	0.09	0.06	0.05
query3	0.26	0.14	0.13
query4	1.61	0.14	0.13
query5	0.27	0.22	0.22
query6	1.22	1.04	1.08
query7	0.04	0.01	0.00
query8	0.06	0.04	0.03
query9	0.38	0.31	0.31
query10	0.54	0.55	0.55
query11	0.19	0.13	0.13
query12	0.18	0.15	0.14
query13	0.47	0.46	0.47
query14	1.00	1.01	1.01
query15	0.60	0.59	0.59
query16	0.32	0.32	0.32
query17	1.08	1.12	1.09
query18	0.22	0.20	0.21
query19	2.06	1.90	1.88
query20	0.02	0.01	0.01
query21	15.43	0.24	0.13
query22	4.86	0.05	0.05
query23	16.13	0.30	0.12
query24	2.99	0.41	0.34
query25	0.12	0.05	0.04
query26	0.74	0.20	0.16
query27	0.05	0.04	0.04
query28	3.44	0.92	0.54
query29	12.48	4.30	3.44
query30	0.27	0.16	0.15
query31	2.77	0.59	0.30
query32	3.22	0.59	0.48
query33	3.20	3.21	3.18
query34	15.55	4.27	3.53
query35	3.55	3.51	3.47
query36	0.56	0.42	0.43
query37	0.08	0.07	0.06
query38	0.05	0.03	0.03
query39	0.04	0.03	0.03
query40	0.18	0.15	0.14
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.03
Total cold run time: 96.49 s
Total hot run time: 25.03 s

@morningman
morningman force-pushed the fix-62259-arrow-flight-split-source-lifecycle branch from eecedcb to cd50205 Compare June 25, 2026 11:09
@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 66.67% (22/33) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17694	4022	3983	3983
q2	2097	306	184	184
q3	10300	1427	814	814
q4	4682	471	340	340
q5	7490	865	568	568
q6	176	171	138	138
q7	791	866	632	632
q8	9398	1530	1583	1530
q9	5595	4482	4563	4482
q10	6780	1800	1559	1559
q11	433	273	235	235
q12	631	419	292	292
q13	18089	3358	2803	2803
q14	258	256	243	243
q15	q16	786	774	713	713
q17	1050	896	949	896
q18	7035	5751	5539	5539
q19	1294	1341	1107	1107
q20	488	385	263	263
q21	5963	2557	2402	2402
q22	436	353	300	300
Total cold run time: 101466 ms
Total hot run time: 29023 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4312	4238	4239	4238
q2	337	348	219	219
q3	4611	4957	4383	4383
q4	2098	2176	1386	1386
q5	4423	4336	4496	4336
q6	231	185	135	135
q7	1740	1646	1825	1646
q8	2705	2219	2207	2207
q9	8233	8460	8139	8139
q10	4823	4749	4301	4301
q11	609	406	373	373
q12	797	773	595	595
q13	3246	3593	2911	2911
q14	310	296	285	285
q15	q16	726	718	636	636
q17	1365	1330	1344	1330
q18	8313	7499	7256	7256
q19	1176	1152	1143	1143
q20	2207	2213	1946	1946
q21	5268	4579	4417	4417
q22	524	442	415	415
Total cold run time: 58054 ms
Total hot run time: 52297 ms

@hello-stephen

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

query5	4315	638	491	491
query6	442	202	169	169
query7	4862	508	316	316
query8	327	185	172	172
query9	8746	4088	4050	4050
query10	465	311	271	271
query11	5903	2327	2159	2159
query12	149	103	102	102
query13	1271	608	434	434
query14	6220	5307	4978	4978
query14_1	4308	4290	4285	4285
query15	206	208	183	183
query16	1000	465	465	465
query17	966	747	608	608
query18	2437	483	355	355
query19	206	197	154	154
query20	112	126	109	109
query21	222	140	116	116
query22	13601	13607	13429	13429
query23	17507	16574	16076	16076
query23_1	16296	16206	16348	16206
query24	7434	1754	1305	1305
query24_1	1308	1288	1289	1288
query25	543	429	352	352
query26	1300	316	162	162
query27	2712	572	347	347
query28	4440	2021	1999	1999
query29	1057	613	468	468
query30	317	228	197	197
query31	1123	1078	957	957
query32	101	58	58	58
query33	523	313	240	240
query34	1170	1136	677	677
query35	757	780	665	665
query36	1349	1366	1242	1242
query37	154	118	92	92
query38	1896	1686	1632	1632
query39	918	915	894	894
query39_1	871	874	869	869
query40	228	121	102	102
query41	65	66	63	63
query42	87	88	94	88
query43	327	328	311	311
query44	1428	767	777	767
query45	203	193	191	191
query46	1069	1188	749	749
query47	2391	2364	2276	2276
query48	404	425	313	313
query49	584	444	322	322
query50	939	358	275	275
query51	4415	4364	4397	4364
query52	81	81	68	68
query53	245	254	191	191
query54	282	246	190	190
query55	71	77	65	65
query56	241	225	214	214
query57	1428	1396	1301	1301
query58	243	211	224	211
query59	1576	1646	1402	1402
query60	294	250	224	224
query61	149	154	173	154
query62	689	653	587	587
query63	225	185	194	185
query64	2525	781	596	596
query65	4928	4791	4696	4696
query66	1775	462	335	335
query67	28950	28829	28634	28634
query68	3152	1604	972	972
query69	409	293	263	263
query70	1072	972	983	972
query71	289	236	216	216
query72	2942	2663	2349	2349
query73	810	798	441	441
query74	5132	4950	4768	4768
query75	2564	2542	2184	2184
query76	2314	1157	804	804
query77	353	369	288	288
query78	12537	12332	11937	11937
query79	1250	1198	720	720
query80	557	504	404	404
query81	451	288	243	243
query82	240	164	126	126
query83	276	279	255	255
query84	291	150	122	122
query85	910	615	493	493
query86	323	306	291	291
query87	1844	1835	1786	1786
query88	3680	2774	2789	2774
query89	417	392	337	337
query90	2171	187	184	184
query91	185	176	173	173
query92	67	58	56	56
query93	1479	1423	844	844
query94	522	322	304	304
query95	696	375	444	375
query96	1082	777	356	356
query97	2696	2690	2571	2571
query98	218	206	203	203
query99	1205	1155	1025	1025
Total cold run time: 255809 ms
Total hot run time: 172555 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.09	0.05	0.05
query3	0.25	0.14	0.14
query4	1.61	0.14	0.14
query5	0.24	0.22	0.21
query6	1.25	1.06	1.08
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.38	0.32	0.31
query10	0.54	0.54	0.54
query11	0.19	0.14	0.14
query12	0.18	0.14	0.14
query13	0.48	0.47	0.48
query14	1.02	1.00	1.01
query15	0.61	0.59	0.60
query16	0.31	0.33	0.32
query17	1.10	1.11	1.09
query18	0.22	0.21	0.21
query19	2.03	1.94	1.96
query20	0.02	0.01	0.01
query21	15.43	0.22	0.15
query22	4.73	0.05	0.06
query23	16.13	0.33	0.13
query24	2.90	0.42	0.33
query25	0.11	0.06	0.03
query26	0.72	0.20	0.16
query27	0.03	0.04	0.04
query28	3.53	0.94	0.54
query29	12.50	4.31	3.44
query30	0.28	0.15	0.15
query31	2.77	0.61	0.31
query32	3.23	0.60	0.50
query33	3.29	3.17	3.24
query34	15.50	4.21	3.49
query35	3.57	3.55	3.53
query36	0.54	0.43	0.43
query37	0.08	0.06	0.06
query38	0.05	0.04	0.03
query39	0.04	0.02	0.02
query40	0.18	0.17	0.17
query41	0.08	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.39 s
Total hot run time: 25.23 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 69.23% (27/39) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 56.25% (27/48) 🎉
Increment coverage report
Complete coverage report

@morningman

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.

I found two correctness issues in the Arrow Flight remote-result lifecycle changes.

Critical checkpoints: the PR targets the right split-source lifetime problem, but the current cleanup trigger is still not safe for concurrent/interleaved Flight RPCs and it misses a failed-GetFlightInfo cleanup path. The change is small and focused, and it does not add configs, persistence, storage-format changes, or FE/BE protocol fields. It does involve non-trivial lifecycle and concurrency: deferred coordinators hold query queue slots and external-table split sources after GetFlightInfo, while DoGet runs independently against BE endpoints. The tests cover normal cleanup and one external-table scan, but they do not cover an overlapping second statement or schema-fetch failure after deferral.

Validation: no existing inline review threads were present; git diff --check over the GitHub changed-file list was clean. I did not run FE tests because thirdparty/installed/bin/protoc is missing in this checkout.

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

Subagent conclusions: OPT-1 became MAIN-1 and is submitted as an inline comment; TSC-1 became MAIN-2 and is submitted as an inline comment. No candidates were dismissed or merged as duplicates. Convergence round 1 ended with both optimizer-rewrite and tests-session-config replying NO_NEW_VALUABLE_FINDINGS for the same current ledger/comment set.

// deferred (Arrow Flight keeps it alive across GetFlightInfo -> DoGet so the BE can
// fetch external-table splits during DoGet). By now the previous DoGet is done. #62259
connectContext.closeFlightSqlDeferredExecutors();
// After the previous query was executed, there was no getStreamStatement to take away the result.

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.

The new cleanup assumes that starting the next statement means the previous DoGet has finished, but Flight RPCs are independent and this method has no completion signal from the BE result stream. A client can get FlightInfo for q1, keep reading q1's BE endpoint, and issue GetFlightInfo for q2 on the same session; this call will close q1's deferred coordinator. Closing the coordinator stops the scan nodes and removes the batch split sources, while q1's BE scan can still call fetchSplitBatch, which then fails with Split source X is released. This reintroduces the issue for pipelined/interleaved clients. Please keep the deferred coordinator until the result stream is actually complete or the session is closed, or reject/serialize a new statement while a remote Arrow Flight result is still live.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked into this and don't think it's a regression this PR introduces, nor something that can be properly fixed within this PR's scope. Details:

Not a new failure mode / not a regression. Before this PR, every external-table batch-split query over Arrow Flight already failed with Split source X is released, because the coordinator was closed at the end of GetFlightInfo — sequential queries included (that is exactly #62259). After this PR the sequential case works; the interleaved case you describe fails as it did before. So nothing is "reintroduced" — interleaving never worked.

Interleaving two queries on one session is not a supported usage. A bearer token maps to a single shared ConnectContext (FlightSessionsWithTokenManager), and that context is single-query-by-construction: each GetFlightInfo resets the shared FlightSqlChannel, clears the single flightSqlEndpointsLocations list, and reuses one queryId. Two concurrent/interleaved queries on one session corrupt all of that, not just the deferred coordinator — the same way sharing one JDBC Connection across threads is unsafe. The supported pattern (drain the result, then issue the next query) makes "the previous DoGet is done by the time the next query starts" hold, since the BE has consumed the SplitSource by the time the client reaches end-of-stream.

The suggested fix needs a signal the FE does not have. For an external-table scan the result DoGet endpoint points directly at the BE; the FE is not in that data path and gets no completion signal when the BE-side stream finishes. "Keep the coordinator until the result stream completes" or "serialize/reject a new statement while a result is live" both require a new BE -> FE completion notification (or session-level serialization keyed on it), which is a separate architectural change out of scope here.

Leaks are already bounded. The "or the session is closed" fallback is implemented: FlightSqlConnectPoolMgr.unregisterConnection() -> closeFlightSqlDeferredExecutors() covers idle/query timeout, bearer-token expiry and explicit CloseSession. And the BE-side hardening in #64797 makes a stale fetchSplitBatch fail gracefully instead of crashing the BE.

If first-class concurrent Flight clients are ever needed, the right follow-up is a BE -> FE completion signal plus session serialization; I can track that separately.

asynExecutor.finalizeQuery();
if (!asynExecutor.isDeferredForArrowFlight()) {
asynExecutor.finalizeQuery();
}

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 guard also skips cleanup when GetFlightInfo fails after a remote executor has already been marked deferred. In that flow, StmtExecutor.executeAndSendResult() adds the executor to the deferred list after coordBase.exec(), then executeQueryStatement() still has to fetch the Arrow schema. If that schema fetch times out, returns non-OK/empty/mismatched schema, or hits an RPC error, try-with-resources calls this close(), but both deferred executors are skipped and the outer catch only rethrows. No FlightInfo is returned, so no DoGet can need the coordinator, but the query registration, query queue slot, and split sources stay alive until a later query or session/token teardown. Please explicitly close the deferred executors on this error path, and add a test that fails schema fetch after deferral.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed — this is a real (bounded) leak. If the Arrow schema fetch in executeQueryStatement fails after the coordinator was already deferred during planning, FlightSqlConnectProcessor.close() skips the deferred executor and the outer catch only rethrows, so the coordinator (its external-table batch SplitSource, the query queue slot and the query registration) stays alive until the next query starts or the connection is torn down — even though no DoGet will ever pull this query's results.

Fixed in 41a79a6 by finalizing the deferred coordinator on the GetFlightInfo error path: executeQueryStatement's catch now calls connectContext.closeFlightSqlDeferredExecutors(). At that point the list holds only this failed query's coordinator (the previous one was already finalized at the top of the method), and it covers every post-deferral failure, not just the schema fetch.

Added DorisFlightSqlProducerTest.testGetFlightInfoFinalizesDeferredExecutorWhenSchemaFetchFails, which defers a coordinator then fails the schema fetch and asserts the deferred executor is finalized (verified to fail without the fix).

@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 66.67% (24/36) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17768	4080	4014	4014
q2	2003	311	184	184
q3	10373	1432	830	830
q4	4680	465	339	339
q5	7507	903	576	576
q6	188	172	135	135
q7	761	856	631	631
q8	9377	1576	1635	1576
q9	5554	4535	4492	4492
q10	6757	1789	1520	1520
q11	434	273	240	240
q12	619	423	289	289
q13	18119	3329	2759	2759
q14	269	270	238	238
q15	q16	790	776	713	713
q17	1052	945	1006	945
q18	7046	5873	5568	5568
q19	1306	1349	1123	1123
q20	494	415	270	270
q21	5899	2632	2348	2348
q22	441	361	306	306
Total cold run time: 101437 ms
Total hot run time: 29096 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4372	4275	4278	4275
q2	311	345	222	222
q3	4622	4971	4390	4390
q4	2041	2140	1387	1387
q5	4420	4273	4317	4273
q6	235	178	130	130
q7	1732	1623	1958	1623
q8	2587	2194	2200	2194
q9	8423	8519	8029	8029
q10	4839	4773	4327	4327
q11	574	409	388	388
q12	769	745	560	560
q13	3259	3629	2971	2971
q14	289	297	280	280
q15	q16	706	718	637	637
q17	1371	1322	1324	1322
q18	8070	7396	7291	7291
q19	1204	1173	1086	1086
q20	2216	2246	1977	1977
q21	5255	4579	4442	4442
q22	512	475	391	391
Total cold run time: 57807 ms
Total hot run time: 52195 ms

@hello-stephen

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

query5	4308	641	488	488
query6	430	190	167	167
query7	4890	583	304	304
query8	324	183	182	182
query9	8772	4080	4090	4080
query10	439	324	266	266
query11	5991	2357	2148	2148
query12	159	113	102	102
query13	1263	623	433	433
query14	6196	5350	4960	4960
query14_1	4371	4404	4371	4371
query15	212	209	182	182
query16	1000	494	471	471
query17	1100	731	588	588
query18	2531	493	356	356
query19	210	191	156	156
query20	116	107	109	107
query21	218	145	124	124
query22	13877	13687	13433	13433
query23	17526	16542	16154	16154
query23_1	16313	16298	16285	16285
query24	7428	1814	1316	1316
query24_1	1324	1322	1319	1319
query25	573	460	396	396
query26	1301	328	165	165
query27	2650	560	358	358
query28	4464	2051	2054	2051
query29	1080	648	512	512
query30	307	237	209	209
query31	1118	1092	967	967
query32	108	66	61	61
query33	521	323	277	277
query34	1200	1155	648	648
query35	769	798	667	667
query36	1420	1368	1209	1209
query37	156	111	99	99
query38	1883	1718	1677	1677
query39	978	939	908	908
query39_1	887	896	863	863
query40	215	125	105	105
query41	64	62	61	61
query42	86	87	89	87
query43	333	340	287	287
query44	1500	807	807	807
query45	192	204	181	181
query46	1084	1240	763	763
query47	2362	2300	2197	2197
query48	382	439	285	285
query49	580	441	319	319
query50	1094	369	267	267
query51	4432	4520	4358	4358
query52	84	83	71	71
query53	258	261	193	193
query54	264	223	197	197
query55	76	71	66	66
query56	230	230	213	213
query57	1407	1389	1300	1300
query58	252	212	203	203
query59	1609	1652	1507	1507
query60	298	249	236	236
query61	145	149	155	149
query62	717	656	591	591
query63	240	189	193	189
query64	2523	798	594	594
query65	4891	4866	4758	4758
query66	1775	466	339	339
query67	29078	28978	28784	28784
query68	3429	1559	870	870
query69	410	308	323	308
query70	1085	973	1009	973
query71	292	240	213	213
query72	2966	2639	2371	2371
query73	811	741	454	454
query74	5086	5001	4779	4779
query75	2575	2570	2177	2177
query76	2322	1232	793	793
query77	378	393	288	288
query78	12451	12537	11910	11910
query79	1396	1154	799	799
query80	1280	483	388	388
query81	526	279	241	241
query82	626	168	118	118
query83	355	280	248	248
query84	273	149	112	112
query85	922	541	415	415
query86	422	303	263	263
query87	1868	1835	1780	1780
query88	3804	2850	2796	2796
query89	446	400	331	331
query90	1904	188	192	188
query91	174	163	133	133
query92	65	62	58	58
query93	1612	1515	989	989
query94	724	356	306	306
query95	682	398	438	398
query96	1139	804	394	394
query97	2711	2682	2575	2575
query98	217	207	205	205
query99	1171	1147	1029	1029
Total cold run time: 259129 ms
Total hot run time: 172666 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 77.78% (28/36) 🎉
Increment coverage report
Complete coverage report

@morningman
morningman force-pushed the fix-62259-arrow-flight-split-source-lifecycle branch from 41a79a6 to 08beee9 Compare July 2, 2026 14:58
@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17689	4112	4085	4085
q2	2031	327	198	198
q3	10260	1455	828	828
q4	4719	473	340	340
q5	7756	859	584	584
q6	262	171	142	142
q7	850	851	631	631
q8	10477	1483	1552	1483
q9	5929	4459	4424	4424
q10	6768	1795	1518	1518
q11	513	346	315	315
q12	700	560	428	428
q13	18114	3327	2739	2739
q14	266	259	240	240
q15	q16	798	778	711	711
q17	1070	1057	1123	1057
q18	7155	5896	5552	5552
q19	1151	1247	1143	1143
q20	769	630	527	527
q21	5653	2686	2549	2549
q22	443	363	295	295
Total cold run time: 103373 ms
Total hot run time: 29789 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4395	4407	4366	4366
q2	301	315	211	211
q3	4636	4969	4398	4398
q4	2106	2187	1359	1359
q5	4503	4329	4318	4318
q6	227	174	126	126
q7	2286	1908	1682	1682
q8	2752	2122	2279	2122
q9	8056	7898	7962	7898
q10	4762	4700	4245	4245
q11	734	420	380	380
q12	764	770	537	537
q13	3339	3578	3030	3030
q14	313	322	263	263
q15	q16	713	738	649	649
q17	1360	1375	1334	1334
q18	8005	7401	6827	6827
q19	1130	1123	1097	1097
q20	2234	2212	1922	1922
q21	5315	4632	4458	4458
q22	516	479	440	440
Total cold run time: 58447 ms
Total hot run time: 51662 ms

@hello-stephen

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

query5	4331	650	492	492
query6	473	244	200	200
query7	4838	592	357	357
query8	357	196	175	175
query9	8778	4044	4084	4044
query10	449	345	299	299
query11	5728	2360	2147	2147
query12	158	102	100	100
query13	1287	604	443	443
query14	6304	5381	5020	5020
query14_1	4379	4331	4352	4331
query15	214	207	182	182
query16	1048	501	455	455
query17	1146	740	607	607
query18	2515	489	354	354
query19	224	192	152	152
query20	111	110	109	109
query21	240	160	138	138
query22	13660	13580	13474	13474
query23	17362	16530	16052	16052
query23_1	16289	16284	16294	16284
query24	7525	1801	1296	1296
query24_1	1347	1310	1294	1294
query25	573	462	386	386
query26	1356	339	211	211
query27	2596	618	388	388
query28	4467	2002	2042	2002
query29	1111	638	511	511
query30	341	268	238	238
query31	1141	1101	985	985
query32	107	66	64	64
query33	535	322	260	260
query34	1248	1177	662	662
query35	763	804	676	676
query36	1418	1429	1207	1207
query37	157	107	97	97
query38	1887	1721	1655	1655
query39	929	932	885	885
query39_1	877	869	901	869
query40	288	157	134	134
query41	67	63	61	61
query42	92	91	90	90
query43	319	327	282	282
query44	1482	785	769	769
query45	206	203	185	185
query46	1131	1186	728	728
query47	2341	2351	2206	2206
query48	417	394	295	295
query49	585	421	313	313
query50	1065	432	333	333
query51	4473	4426	4357	4357
query52	86	87	76	76
query53	272	269	202	202
query54	290	223	225	223
query55	77	70	71	70
query56	312	294	284	284
query57	1421	1421	1317	1317
query58	280	255	254	254
query59	1606	1659	1440	1440
query60	307	276	242	242
query61	148	146	176	146
query62	695	650	592	592
query63	251	206	214	206
query64	2514	762	610	610
query65	4840	4732	4796	4732
query66	1804	502	382	382
query67	28885	29503	29383	29383
query68	3177	1542	961	961
query69	422	305	274	274
query70	1081	999	994	994
query71	352	370	312	312
query72	2879	2622	2349	2349
query73	841	743	438	438
query74	5136	4979	4825	4825
query75	2612	2587	2217	2217
query76	2334	1185	769	769
query77	358	384	275	275
query78	12404	12479	11995	11995
query79	1431	1121	730	730
query80	1300	538	452	452
query81	533	325	284	284
query82	667	160	121	121
query83	380	321	296	296
query84	277	165	129	129
query85	945	608	545	545
query86	424	310	298	298
query87	1841	1817	1758	1758
query88	3776	2846	2789	2789
query89	457	415	353	353
query90	1939	203	200	200
query91	206	192	161	161
query92	65	65	56	56
query93	1664	1553	1037	1037
query94	733	356	314	314
query95	771	575	460	460
query96	1120	782	335	335
query97	2719	2707	2603	2603
query98	223	209	204	204
query99	1174	1147	1033	1033
Total cold run time: 258831 ms
Total hot run time: 173955 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.10	0.05	0.05
query3	0.25	0.14	0.13
query4	1.61	0.13	0.17
query5	0.24	0.23	0.23
query6	1.20	1.08	1.07
query7	0.04	0.01	0.00
query8	0.06	0.04	0.04
query9	0.38	0.31	0.31
query10	0.55	0.56	0.59
query11	0.19	0.14	0.15
query12	0.19	0.15	0.15
query13	0.46	0.48	0.48
query14	1.03	1.01	1.00
query15	0.61	0.60	0.61
query16	0.32	0.32	0.31
query17	1.14	1.11	1.15
query18	0.23	0.20	0.22
query19	2.04	1.97	2.00
query20	0.01	0.02	0.01
query21	15.43	0.26	0.13
query22	4.69	0.06	0.06
query23	16.16	0.31	0.12
query24	3.01	0.44	0.31
query25	0.12	0.06	0.04
query26	0.72	0.20	0.17
query27	0.06	0.04	0.03
query28	3.53	0.94	0.54
query29	12.51	4.36	3.46
query30	0.28	0.15	0.15
query31	2.76	0.60	0.31
query32	3.21	0.58	0.48
query33	3.13	3.23	3.20
query34	15.47	4.25	3.48
query35	3.50	3.49	3.49
query36	0.54	0.44	0.43
query37	0.09	0.06	0.07
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.19	0.17	0.15
query41	0.09	0.04	0.03
query42	0.04	0.02	0.04
query43	0.05	0.04	0.03
Total cold run time: 96.32 s
Total hot run time: 25.25 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 77.78% (28/36) 🎉
Increment coverage report
Complete coverage report

@morningman
morningman force-pushed the fix-62259-arrow-flight-split-source-lifecycle branch from 08beee9 to 8047781 Compare July 17, 2026 06:57
… for external table scan

Arrow Flight SQL executes a query in two phases: GetFlightInfo (plan +
submit to BE) and DoGet (the client pulls results from the BE). For an
external table scan in batch split mode, the BE keeps scanning during
DoGet and lazily fetches file splits from the FE via the fetchSplitBatch
RPC, using a batch SplitSource that the FE's coordinator holds (through
its scan nodes).

The problem: the FE closed the coordinator at the end of GetFlightInfo
(StmtExecutor.executeAndSendResult's finally -> Coordinator.close() ->
ScanNode.stop() -> SplitSourceManager.removeSplitSource()) and also
unregistered it (FlightSqlConnectProcessor.close() ->
StmtExecutor.finalizeQuery()). So by the time the BE called
fetchSplitBatch during DoGet, the SplitSource was already gone and the
query failed with "Split source X is released". MySQL protocol is
unaffected because plan + execute share one request and the coordinator
stays alive until all results are consumed.

This keeps the coordinator (and its SplitSource) alive across the two
phases and cleans it up reliably:

- StmtExecutor: for an Arrow Flight query that produces results on the BE
  (coordBase == coord), mark it deferred, register the executor on the
  ConnectContext, and skip the eager Coordinator.close() in the finally.
  A failed query (exec threw) is not deferred and is closed as before.
- ConnectContext: hold the deferred executors and provide
  closeFlightSqlDeferredExecutors() to close their coordinators (releasing
  the SplitSource and the query queue slot) and unregister the queries.
- FlightSqlConnectProcessor.close(): do not finalize deferred executors.
- DorisFlightSqlProducer: finalize the previous query's deferred
  coordinator when the next query starts on the connection.
- FlightSqlConnectPoolMgr.unregisterConnection(): finalize deferred
  coordinators when the connection is torn down. All teardown paths
  (idle/query timeout, bearer token expiry, explicit CloseSession) reach
  here, so an abandoned connection cannot leak the coordinator.

This is the root-cause fix for apache#62259. The BE-side error-path hardening
(so any fetchSplitBatch failure fails gracefully instead of crashing) is
handled separately in apache#64797.
…t in batch split mode

Reproduces apache#62259: scanning an Iceberg external table over Arrow Flight
SQL in batch split mode used to fail ("Split source X is released" / BE
crash) because the FE released the async SplitSource at the end of
GetFlightInfo, before the BE fetched splits during DoGet.

The test forces batch split mode on the Arrow Flight session
(num_files_in_batch_mode=1), asserts via explain that the scan really
uses the batch SplitSource path ("approximate"), then scans
format_v2.sample_cow_orc over Arrow Flight and checks all 1000 rows come
back. Running several queries on the same connection also exercises the
cleanup of the previous query's deferred coordinator. The test is skipped
when the Iceberg env or the Arrow Flight endpoint is not configured.
…ster's real Arrow Flight port

The external regression cluster serves Arrow Flight SQL on the default port
(FE 8070) rather than the configured extArrowFlightSqlPort (8081), so the
framework's arrow_flight_sql() helper failed at connect with
"Connection refused: <ip>:8081" before the test ever reached the batch
split-source path it is meant to exercise. The error surfaced on the
finally line because the reconnect there also failed and masked the
original exception.

Read the live Arrow Flight port from SHOW FRONTENDS and open a dedicated
connection against it (as the remote_doris tests already do), skip when
Arrow Flight is disabled, and make the finally best-effort so a dead
endpoint can no longer mask the real failure or leak the catalog.
…rce cleanup

The fix for apache#62259 keeps an Arrow Flight query's coordinator alive across
GetFlightInfo -> DoGet and releases it later via deferred executors held on
the ConnectContext. These tests pin the leak-prevention contract of that
deferred cleanup so the coordinator (and the external-table batch SplitSource
and query queue slot it holds, plus the query registration) cannot leak:

- ConnectContextTest: closeFlightSqlDeferredExecutors() finalizes every
  deferred executor, clears the list (idempotent, no double-close, no retain),
  and still finalizes the rest when one executor's finalize throws.
- FlightSqlConnectPoolMgrTest (new): unregisterConnection() finalizes the
  deferred executors on connection teardown (idle/query timeout, bearer token
  expiry, explicit CloseSession), even for a connection that was never
  registered, so an abandoned connection cannot leak the coordinator.
- StmtExecutorTest: finalizeArrowFlightQuery() still unregisters the query
  (releases the registration) when coord.close() throws (the try/finally).

Each test was verified to fail when its corresponding cleanup is removed.
…fails after deferral

For an Arrow Flight external-table scan, executeAndSendResult() registers the
query's coordinator as a deferred executor on the ConnectContext (kept alive
across GetFlightInfo -> DoGet, see apache#62259) right after submitting it to the BE.
GetFlightInfo then still has to fetch the Arrow schema from the BE. If that
fetch fails (timeout / non-OK / empty / mismatched schema / RPC error),
FlightSqlConnectProcessor.close() skips the deferred executor and the outer
catch only rethrows. No FlightInfo is returned, so no DoGet will ever pull the
results, yet the coordinator (its external-table batch SplitSource, the query
queue slot and the query registration) stays alive until the next query starts
or the connection is torn down.

Finalize the deferred coordinator on the GetFlightInfo error path:
executeQueryStatement's catch now calls closeFlightSqlDeferredExecutors(). At
that point the list holds only this failed query's coordinator (the previous
one was already finalized at the top of the method), and this covers every
post-deferral failure, not just the schema fetch.

Add DorisFlightSqlProducerTest.testGetFlightInfoFinalizesDeferredExecutorWhen
SchemaFetchFails, which defers a coordinator then fails the schema fetch and
asserts the deferred executor is finalized (verified to fail without the fix).
…sult Flight queries, not only external batch scans

The gate that defers the coordinator close is coordBase == coord for any
ARROW_FLIGHT_SQL query whose results are produced on the BE, so it captures
internal-table and non-batch external SELECTs too, not only external-table
batch-split scans. Deferral is only strictly required for the batch-split case
(where the BE fetches splits from the FE during DoGet); the others are deferred
by the same gate and merely hold their coordinator, query queue slot and query
registration until the next query or connection teardown. The old comment
implied only external batch scans were affected. Comment-only change. See apache#62259.
@morningman
morningman force-pushed the fix-62259-arrow-flight-split-source-lifecycle branch from 8047781 to 663491e Compare July 17, 2026 07:58
@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17846	4281	4058	4058
q2	2037	309	202	202
q3	10275	1438	816	816
q4	4715	471	340	340
q5	7697	838	571	571
q6	245	172	135	135
q7	785	830	622	622
q8	10346	1664	1629	1629
q9	5814	4431	4419	4419
q10	6825	1757	1455	1455
q11	516	349	320	320
q12	749	572	447	447
q13	18200	3364	2745	2745
q14	274	264	244	244
q15	q16	782	783	703	703
q17	1160	949	1076	949
q18	7021	5778	5546	5546
q19	2824	1391	1062	1062
q20	832	684	576	576
q21	5929	2573	2496	2496
q22	424	354	293	293
Total cold run time: 105296 ms
Total hot run time: 29628 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4537	4539	4526	4526
q2	294	311	210	210
q3	4552	4959	4396	4396
q4	2116	2150	1375	1375
q5	4413	4285	4720	4285
q6	249	188	143	143
q7	2022	1816	1618	1618
q8	2456	2138	2142	2138
q9	7911	7764	7853	7764
q10	4698	4671	4236	4236
q11	595	458	382	382
q12	783	754	546	546
q13	3226	3659	2993	2993
q14	289	321	282	282
q15	q16	730	730	627	627
q17	1413	1360	1315	1315
q18	7943	7262	6697	6697
q19	1158	1089	1122	1089
q20	2221	2209	1937	1937
q21	5280	4584	4462	4462
q22	544	480	419	419
Total cold run time: 57430 ms
Total hot run time: 51440 ms

@hello-stephen

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

query5	4308	647	498	498
query6	472	220	205	205
query7	4853	586	353	353
query8	337	195	176	176
query9	8779	4037	4003	4003
query10	483	344	304	304
query11	5907	2307	2122	2122
query12	169	104	101	101
query13	1254	658	436	436
query14	6213	5162	4869	4869
query14_1	4235	4208	4196	4196
query15	209	204	186	186
query16	1013	516	464	464
query17	1144	730	583	583
query18	2582	468	361	361
query19	210	192	156	156
query20	112	107	107	107
query21	239	163	137	137
query22	13505	13568	13318	13318
query23	17369	16515	16162	16162
query23_1	16167	16226	16274	16226
query24	7489	1748	1286	1286
query24_1	1303	1304	1279	1279
query25	572	452	401	401
query26	1335	362	224	224
query27	2572	605	401	401
query28	4438	2013	1979	1979
query29	1081	630	489	489
query30	344	276	234	234
query31	1125	1090	970	970
query32	112	63	63	63
query33	530	335	261	261
query34	1162	1130	623	623
query35	778	773	676	676
query36	1184	1223	1038	1038
query37	156	111	96	96
query38	1872	1714	1668	1668
query39	880	866	841	841
query39_1	832	821	845	821
query40	255	206	153	153
query41	67	64	64	64
query42	92	92	93	92
query43	326	324	283	283
query44	1429	765	744	744
query45	190	184	174	174
query46	1042	1138	696	696
query47	2106	2110	2018	2018
query48	377	417	297	297
query49	607	407	304	304
query50	1073	429	335	335
query51	10695	10692	10619	10619
query52	94	92	74	74
query53	273	280	201	201
query54	278	239	212	212
query55	74	72	65	65
query56	314	297	282	282
query57	1325	1265	1167	1167
query58	297	261	248	248
query59	1641	1672	1454	1454
query60	302	264	258	258
query61	154	152	154	152
query62	543	493	427	427
query63	239	198	206	198
query64	2822	1052	899	899
query65	4686	4644	4638	4638
query66	1792	525	374	374
query67	28964	29282	29082	29082
query68	3085	1603	1037	1037
query69	412	302	259	259
query70	1054	961	982	961
query71	377	327	321	321
query72	3072	2665	2330	2330
query73	893	776	448	448
query74	5084	4901	4693	4693
query75	2542	2497	2140	2140
query76	2334	1177	768	768
query77	363	396	285	285
query78	11873	11776	11276	11276
query79	1366	1134	768	768
query80	1308	605	469	469
query81	518	326	288	288
query82	600	156	122	122
query83	376	332	303	303
query84	278	155	132	132
query85	996	634	524	524
query86	432	299	253	253
query87	1823	1818	1776	1776
query88	3731	2796	2763	2763
query89	446	388	334	334
query90	2026	219	199	199
query91	200	193	158	158
query92	63	64	59	59
query93	1583	1487	1028	1028
query94	743	372	312	312
query95	817	598	489	489
query96	1089	793	360	360
query97	2605	2618	2486	2486
query98	211	204	195	195
query99	1097	1125	980	980
Total cold run time: 262843 ms
Total hot run time: 177704 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.10	0.04	0.05
query3	0.25	0.13	0.13
query4	1.61	0.15	0.13
query5	0.24	0.22	0.22
query6	1.24	1.14	1.09
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.39	0.31	0.33
query10	0.57	0.57	0.55
query11	0.19	0.14	0.14
query12	0.18	0.14	0.14
query13	0.48	0.46	0.48
query14	1.02	1.03	1.02
query15	0.64	0.61	0.62
query16	0.33	0.33	0.33
query17	1.14	1.11	1.13
query18	0.23	0.21	0.21
query19	2.11	1.88	1.95
query20	0.02	0.01	0.01
query21	15.42	0.22	0.13
query22	4.80	0.05	0.05
query23	16.14	0.31	0.12
query24	3.07	0.43	0.32
query25	0.11	0.05	0.05
query26	0.76	0.21	0.15
query27	0.04	0.04	0.03
query28	3.48	0.94	0.55
query29	12.48	4.11	3.27
query30	0.27	0.16	0.16
query31	2.77	0.60	0.30
query32	3.23	0.60	0.49
query33	3.24	3.17	3.17
query34	15.46	4.20	3.51
query35	3.53	3.54	3.54
query36	0.55	0.43	0.44
query37	0.09	0.06	0.07
query38	0.05	0.04	0.03
query39	0.04	0.03	0.03
query40	0.18	0.16	0.15
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.03	0.03
Total cold run time: 96.73 s
Total hot run time: 25.06 s

@morningman

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 summary

Requesting changes for four P1 lifecycle and cancellation defects in the new deferred-coordinator ownership.

Critical checkpoint conclusions

  • Goal and proof: The change does keep legacy and Nereids external-batch SplitSources alive across sequential GetFlightInfo/DoGet, and the Iceberg regression plus schema-fetch-failure unit test exercise the main success and error paths. The lifecycle is not complete because of the four inline findings.
  • Scope and focus: The plumbing is localized, but the coordBase == coord condition is broader than the actual batch-file-scan requirement and retains ordinary distributed queries too.
  • Concurrency: Flight request threads, token eviction, CloseSession, administrative/REST cancellation, and workload-policy threads can act independently on the shared context. The list monitor keeps heavy close work outside the lock, but it lacks a terminal add/drain handshake, immutable executor identity, and a cancellation lookup.
  • Lifecycle and static initialization: Deferred ownership spans separate Flight RPCs and the BE result stream. Release on next request/error/teardown is not sufficient for terminal publication, supported EOF, or cancellation. No static-initialization or circular-reference issue applies.
  • Configuration: No configuration is added. Existing defaults (wait_timeout 28,800 seconds and long token lifetime) amplify retained-resource impact.
  • Compatibility: No storage, wire, function-symbol, or rolling-upgrade format changes were found.
  • Parallel paths: Statement and prepared execution share the producer path; both legacy and Nereids distributed coordinators defer. Point queries and local FE results retain their separate cleanup paths. No omitted parallel implementation produced another finding.
  • Special conditions: The changed condition is documented but not minimal: only batch file scans need the live SplitSource, while all distributed BE-result queries enter it.
  • Tests and results: Added tests cover sequential drain, idempotence, failure continuation, schema-fetch failure, pool unregister, real batch scanning, and next-query cleanup. Missing latch/barrier, two-session queue-release, stable-ID, and post-processor-close cancellation tests map directly to the four inline issues. No changed expected-result defect was found.
  • Observability: Finalizer failures are logged and cleanup continues, but query-ID KILL can report success after a null-executor no-op; that is covered by the cancellation finding. No separate observability-only issue was substantiated.
  • Transactions and persistence: No EditLog or persisted metadata changes apply. Delayed Qe unregister can delay Hive transaction deregistration, already included in the resource-retention finding.
  • Data writes: No data-write or transaction-atomicity path is modified.
  • FE-BE propagation: No new FE-BE variable or serialization field is introduced.
  • Performance and resources: Broad deferral retains coordinator, scan-node, workload queue, Qe instance, and sometimes Hive ownership; terminal drain-before-add can make that retention unbounded.
  • Other issues and deduplication: The two existing threads cover premature cleanup for unsupported interleaved streams and the now-fixed schema-fetch error path. None of the four comments duplicates them or another accepted finding. A proposed catalog-cleanup concern was dismissed because the repository rule is table-specific and neighboring Iceberg suites routinely clean temporary catalogs.
  • User focus: review_focus.txt contained no additional focus point; the full PR was reviewed.
  • Validation and completion: Static review only, as required by the task; no local build or test command was run. The checkout also lacks .worktree_initialized, thirdparty/installed, and the bundled protoc. Live CI currently has compile, CheckStyle, external, P0, nonconcurrent, performance, and cloud checks passing; FE unit tests are pending and FE coverage is failing. Review convergence completed in three rounds, with all three final reviewers returning NO_NEW_VALUABLE_FINDINGS against this exact four-comment set and every candidate accepted, deduplicated, or dismissed.


public void addFlightSqlDeferredExecutor(StmtExecutor executor) {
synchronized (flightSqlDeferredExecutors) {
flightSqlDeferredExecutors.add(executor);

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.

[P1] Make terminal teardown atomic with deferred registration

Token eviction or CloseSession can call unregisterConnection() on another thread while this query is still inside coordBase.exec(). If teardown drains the currently empty list and removes the context/token mapping first, the query then returns, adds itself here, and FlightSqlConnectProcessor.close() skips it because it is deferred. No later request or timeout can retrieve that removed context, so its Qe registration/instance accounting, queue token, coordinator, and batch SplitSources remain indefinitely. The monitor prevents list corruption but does not close this drain-then-add window. Please mark terminal teardown under the same synchronization and make a late add finalize/reject the executor, with a latch test for this ordering.

// registration stay held until the next query / teardown instead of being released
// at the end of GetFlightInfo. Point queries use a different coordBase (not
// deferred). See #62259.
if (coordBase == coord) {

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.

[P1] Do not leave every BE-result query attached to the Flight session

This gate also defers internal-table and non-batch queries even though only an external batch scan needs a live SplitSource. Skipping Coordinator.close() retains the workload-group token, and delaying unregisterQuery() retains per-user instance accounting (and Hive transaction deregistration). After the client fully drains DoGet, the FE receives no completion callback. The Arrow Java 19 driver used by the new regression sends CloseSession from close() only when an optional catalog is present (source); this URL has none, so without another statement the resources remain until the default 28,800-second idle timeout. With workload-group max concurrency 1, one completed q1 therefore leaves q2 on another session queued for up to eight hours. Please restrict deferral to plans that actually own batch SplitSources and provide completion-driven cleanup/decoupled ownership for those plans; add a two-session queue-release test.

coord.close();
}
} finally {
finalizeQuery();

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.

[P1] Unregister the deferred executor's captured query ID

This calls finalizeQuery(), which removes context.queryId() rather than the ID owned by this executor. closeFlightSqlDeferredExecutors() clears q1 from the list and finalizes it outside the monitor; if token teardown races an already-admitted next request, q2 can see the empty list and handleQuery() can reset/set the shared ID before q1 reaches this line. Q1 then remains registered (or the null removal throws), while q2 may be unregistered and lose status/profile/cancel routing; instance accounting and Hive transaction deregistration use the same wrong key. Please capture the immutable query ID when this executor is registered/deferred and finalize that exact ID, with a blocked-q1-close/q2-ID latch test.

}
returnResultFromRemoteExecutor.clear();
executor.finalizeQuery();
if (executor != null && !executor.isDeferredForArrowFlight()) {

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.

[P1] Keep deferred queries reachable by cancellation

This branch keeps q1 active for the later DoGet, but ctx.clear() immediately nulls ConnectContext.executor. During DoGet, query-ID lookup still finds this context; however, KILL QUERY calls FlightSqlConnectContext.kill(false) -> cancelQuery(), which now sees no executor and does nothing, after which KILL reports success. REST and workload-policy cancellation use the same no-op path, and none falls back to the retained Qe coordinator/private deferred list, so the BE fragments continue. Please keep deferred executors addressable by their captured query ID (also aligning with stable ownership in the other finding) and route cancellation to the matching executor/coordinator; add a test that closes the processor, cancels q1 during DoGet, and verifies coordinator cancellation plus later single finalization.

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 66.67% (24/36) 🎉
Increment coverage report
Complete coverage report

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

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@morningman
morningman merged commit 1127003 into apache:master Jul 18, 2026
31 of 32 checks passed
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. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Arrow Flight SQL + Iceberg: SplitSource released before DoGet (fetchSplitBatch crash)

3 participants