Skip to content

[fix](file cache) guard null IOContext in cached remote reader#63842

Merged
eldenmoon merged 1 commit into
apache:masterfrom
eldenmoon:branch-fix-cache-reader-null-iocontext-master
May 29, 2026
Merged

[fix](file cache) guard null IOContext in cached remote reader#63842
eldenmoon merged 1 commit into
apache:masterfrom
eldenmoon:branch-fix-cache-reader-null-iocontext-master

Conversation

@eldenmoon
Copy link
Copy Markdown
Member

Proposed changes

  • Guard CachedRemoteFileReader::read_at_impl against nullable IOContext.
  • Pass NativeReader _io_ctx through header and block reads.
  • Add BE unit coverage for reading through CachedRemoteFileReader without an explicit IOContext.

Root cause

FileReader::read_at allows callers to omit IOContext, but CachedRemoteFileReader::read_at_impl dereferenced it before checking. NativeReader also issued header and block reads without forwarding its _io_ctx, which exposed the cached remote reader to a null context.

Test

  • git diff --check
  • DORIS_CLANG_HOME=/mnt/disk6/common/ldb_toolchain_026 DORIS_THIRDPARTY=/mnt/disk6/common/doris-thirdparties/doris-thirdparty-master ./run-be-ut.sh --run --filter='BlockFileCacheTest.cached_remote_file_reader_accepts_null_io_context'

@eldenmoon
Copy link
Copy Markdown
Member Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

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

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17654	4052	3990	3990
q2	q3	10848	1394	825	825
q4	4687	473	354	354
q5	7566	2300	2136	2136
q6	243	180	135	135
q7	963	785	659	659
q8	9385	1672	1593	1593
q9	5089	4922	4969	4922
q10	6375	2204	1866	1866
q11	430	266	249	249
q12	633	426	291	291
q13	18115	3363	2805	2805
q14	268	256	237	237
q15	q16	819	776	704	704
q17	916	905	953	905
q18	6940	5762	5595	5595
q19	1345	1339	1094	1094
q20	515	401	262	262
q21	5883	2584	2346	2346
q22	438	357	302	302
Total cold run time: 99112 ms
Total hot run time: 31270 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4321	4234	4355	4234
q2	q3	4534	4942	4383	4383
q4	2091	2199	1369	1369
q5	4413	4327	4326	4326
q6	223	170	129	129
q7	2217	1939	1777	1777
q8	2566	2244	2188	2188
q9	8267	8011	8064	8011
q10	4789	4799	4273	4273
q11	586	411	394	394
q12	743	753	566	566
q13	3390	3629	2970	2970
q14	323	308	281	281
q15	q16	706	729	641	641
q17	1374	1475	1358	1358
q18	8187	7645	7561	7561
q19	1184	1117	1160	1117
q20	2252	2265	1970	1970
q21	5281	4595	4348	4348
q22	547	476	402	402
Total cold run time: 57994 ms
Total hot run time: 52298 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 172213 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 e8261a3a1e9afa41f340de6a20529a3aa39449e9, data reload: false

query5	4334	659	516	516
query6	334	217	210	210
query7	4255	562	318	318
query8	330	225	225	225
query9	8800	4000	3980	3980
query10	467	340	284	284
query11	5778	2442	2278	2278
query12	174	125	125	125
query13	1275	580	432	432
query14	6026	5455	5137	5137
query14_1	4449	4471	4418	4418
query15	213	203	187	187
query16	971	458	424	424
query17	1136	716	590	590
query18	2468	488	357	357
query19	217	234	172	172
query20	137	131	132	131
query21	216	136	121	121
query22	13610	13560	13462	13462
query23	17296	16615	16222	16222
query23_1	16369	16320	16462	16320
query24	7473	1773	1331	1331
query24_1	1343	1330	1347	1330
query25	593	514	454	454
query26	1319	329	176	176
query27	2710	582	356	356
query28	4457	1992	2003	1992
query29	1025	649	522	522
query30	301	237	200	200
query31	1132	1083	963	963
query32	99	79	76	76
query33	556	393	319	319
query34	1228	1169	643	643
query35	777	803	709	709
query36	1453	1398	1259	1259
query37	156	104	91	91
query38	3182	3113	3078	3078
query39	937	931	897	897
query39_1	908	890	876	876
query40	249	149	133	133
query41	75	70	71	70
query42	123	110	110	110
query43	332	332	300	300
query44	
query45	218	207	199	199
query46	1083	1265	754	754
query47	2351	2378	2228	2228
query48	411	440	320	320
query49	671	523	405	405
query50	1040	362	255	255
query51	4319	4273	4309	4273
query52	107	111	98	98
query53	265	276	212	212
query54	338	313	277	277
query55	95	94	86	86
query56	315	317	315	315
query57	1438	1436	1343	1343
query58	317	283	276	276
query59	1599	1708	1434	1434
query60	329	327	317	317
query61	164	160	161	160
query62	712	655	590	590
query63	240	196	209	196
query64	2458	802	646	646
query65	
query66	1756	482	358	358
query67	29773	29695	29585	29585
query68	
query69	465	340	311	311
query70	1089	1005	1000	1000
query71	302	273	269	269
query72	3061	2685	2459	2459
query73	843	776	436	436
query74	5099	4935	4769	4769
query75	2694	2621	2264	2264
query76	2321	1155	762	762
query77	395	445	345	345
query78	12448	12490	11859	11859
query79	1463	1025	761	761
query80	683	534	460	460
query81	459	281	240	240
query82	1400	156	124	124
query83	354	274	245	245
query84	267	147	117	117
query85	902	540	455	455
query86	387	333	306	306
query87	3424	3381	3254	3254
query88	3597	2712	2697	2697
query89	451	384	348	348
query90	1995	184	179	179
query91	180	171	144	144
query92	81	78	85	78
query93	1429	1418	852	852
query94	552	352	286	286
query95	679	377	443	377
query96	1109	802	340	340
query97	2731	2753	2639	2639
query98	242	229	248	229
query99	1174	1147	1040	1040
Total cold run time: 254540 ms
Total hot run time: 172213 ms

@eldenmoon eldenmoon marked this pull request as ready for review May 28, 2026 12:21
@eldenmoon eldenmoon requested a review from liaoxin01 as a code owner May 28, 2026 12:21
Copilot AI review requested due to automatic review settings May 28, 2026 12:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Guards CachedRemoteFileReader::read_at_impl against a null IOContext by substituting a default-constructed one, and forwards NativeReader::_io_ctx to its header/block file reads to avoid passing null down to the cached remote reader.

Changes:

  • Allocate a stack default IOContext when caller passes nullptr in CachedRemoteFileReader::read_at_impl.
  • Thread _io_ctx through NativeReader header validation and block length/body reads.
  • Add a BE unit test exercising CachedRemoteFileReader::read_at with no explicit IOContext.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
be/src/io/cache/cached_remote_file_reader.cpp Substitute default IOContext when caller passes null before dereferencing fields.
be/src/format/native/native_reader.cpp Forward _io_ctx to header validation and block length/body read_at calls.
be/test/io/cache/block_file_cache_test.cpp Adds cached_remote_file_reader_accepts_null_io_context test covering null-context path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (10/10) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.86% (28106/38054)
Line Coverage 57.82% (305536/528422)
Region Coverage 55.05% (256135/465239)
Branch Coverage 56.52% (110573/195623)

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (10/10) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.86% (28105/38054)
Line Coverage 57.82% (305515/528422)
Region Coverage 55.05% (256117/465239)
Branch Coverage 56.52% (110568/195623)

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label May 28, 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.

@eldenmoon
Copy link
Copy Markdown
Member Author

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated review completed for PR 63842. I did not find any blocking correctness issues in the changed code.

Critical checkpoint conclusions:

  • Goal and tests: The PR addresses the stated null IOContext path by defaulting CachedRemoteFileReader::read_at_impl to a local IOContext and by forwarding NativeReader::_io_ctx into header/block reads. The added BE unit test covers the direct null-IOContext cached reader case.
  • Scope and clarity: The change is small and focused on IOContext propagation/null handling.
  • Concurrency: No new shared mutable state or lock ordering was introduced. The stack default IOContext is used synchronously within read_at_impl.
  • Lifecycle/static initialization: No new static/global lifecycle hazards were introduced.
  • Configuration/compatibility: No new configuration, protocol, storage format, or rolling-upgrade compatibility concerns.
  • Parallel paths: The relevant NativeReader reads now pass IOContext, and CachedRemoteFileReader tolerates the public FileReader::read_at default null context.
  • Conditional checks: The new null handling is straightforward and matches FileReader::read_at API semantics.
  • Test coverage: Added targeted BE unit coverage. I did not rerun the full BE UT suite; I ran git diff --check locally in this runner.
  • Observability: Existing file-cache statistics/profile behavior is preserved when a caller provides IOContext; null context uses default stats behavior without query profile updates.
  • Transaction/persistence/data write correctness: Not applicable to this PR.
  • FE/BE variable passing: Not applicable.
  • Performance: No meaningful hot-path regression found; the default IOContext construction is only a small stack object and only affects read calls.
  • User focus: No additional user-provided review focus was specified.

@eldenmoon eldenmoon merged commit c27fef6 into apache:master May 29, 2026
35 of 36 checks passed
github-actions Bot pushed a commit that referenced this pull request May 29, 2026
- Guard `CachedRemoteFileReader::read_at_impl` against nullable
`IOContext`.
- Pass `NativeReader` `_io_ctx` through header and block reads.
- Add BE unit coverage for reading through `CachedRemoteFileReader`
without an explicit `IOContext`.
eldenmoon added a commit that referenced this pull request May 29, 2026
…eader #63842 (#63869)

Cherry-picked from #63842

Co-authored-by: lihangyu <lihangyu@selectdb.com>
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. dev/4.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants