Skip to content

[improvement](compaction) extract functions of compaction execution - #67466

Open
mymeiyi wants to merge 1 commit into
apache:masterfrom
mymeiyi:5-abstract-compaction
Open

[improvement](compaction) extract functions of compaction execution#67466
mymeiyi wants to merge 1 commit into
apache:masterfrom
mymeiyi:5-abstract-compaction

Conversation

@mymeiyi

@mymeiyi mymeiyi commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Later, we will support parallel compaction. This PR extracts the cloud compaction execution into reusable functions.

Copilot AI lite review requested due to automatic review settings September 3, 2026 04:14
@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?

Copilot AI 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.

🟡 Changes recommended

It introduces a potentially incorrect DORIS_CHECK_GT(execution_start_time_us, 0) that can fail for valid monotonic timestamps (e.g., 0 very early after boot).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors BE storage compaction code by extracting compaction execution steps into reusable helper functions (especially for cloud compaction), which should make it easier to introduce parallel compaction execution later.

Changes:

  • Split Compaction::merge_input_rowsets() into prepare_*, execute_*, and finish_* stages via a new MergeInputRowsetsContext.
  • Split cloud compaction execution (CloudCompactionMixin::execute_compact_impl) into prepare_execute_compact() + finish_execute_compact() with elapsed-time accounting based on MonotonicMicros().
  • Minor header re-organization to expose the new helper methods and adjust declarations.

Critical Checkpoints (Part 1.3)

  • Goal & completeness: Achieves the stated goal (function extraction for reuse) without changing the overall execution order of cloud compaction.
  • Concurrency: No new concurrency introduced; execution flow remains sequential.
  • Lifecycle / cleanup: No new ownership/lifetime hazards introduced; the new context is stack-scoped and passed through stages.
  • Compatibility / storage format: No protocol or on-disk format changes observed in the diff.
  • Tests: No tests were added/updated; this appears to be a refactor rather than new behavior.
  • Observability: Logging remains present; elapsed-time metric updates are preserved (but see the correctness issue below).
  • Main issue found: An invariant check in the new finish_execute_compact() can spuriously fail (comment added).
File summaries
File Description
be/src/storage/compaction/compaction.h Adds context/stage APIs for merge_input_rowsets and cloud compaction execution helpers.
be/src/storage/compaction/compaction.cpp Implements the staged execution helpers and refactors cloud compaction timing to use MonotonicMicros().
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread be/src/storage/compaction/compaction.cpp Outdated
### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Compaction merge execution and Cloud compaction execution each combined preparation, merge work, and finalization in one method, preventing callers from coordinating those phases independently. Extract shared execution contexts and prepare, execute, and finish methods while preserving operation order and timer scopes. Move get_compaction_permits to protected so derived compaction implementations can coordinate the same execution flow.

### Release note

None

### Check List (For Author)

- Test: Not run per request; clang-format and build hygiene checks passed
- Behavior changed: No
- Does this need documentation: No
@mymeiyi
mymeiyi force-pushed the 5-abstract-compaction branch from 699c33f to b18221d Compare September 3, 2026 06:13
@mymeiyi

mymeiyi commented Sep 3, 2026

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.

Automated review conclusion: no blocking correctness issue found on head b18221de47adf5d49f8a70e7c66e3cf5a9ecc817.

Critical checkpoints:

  • Goal and proof: the PR extracts merge and Cloud execution phases for reuse. The only current wrappers preserve the original operation order, timer boundaries, virtual-hook dispatch, and Status short-circuit points. No targeted test was added and the BE build/tests were skipped; existing compaction tests cover the unchanged grouped-result hooks, so this is a test-proof limitation rather than a demonstrated regression.
  • Scope and compatibility: the two-file change is focused. It adds protected non-virtual helpers/context and widens access to an existing helper without changing object layout, vtables, config, FE/BE protocol, serialization, storage format, or persisted metadata.
  • Concurrency and lifecycle: current callers remain sequential. The merge context lives through prepare/execute/finish, and the writer copies the reader shared pointers. The helpers mutate per-compaction writer/stat/schema/profile state, so future parallel coordination must not interleave them on the same object without isolating that state.
  • Error, write, and transaction safety: output preparation -> merge/build/check -> meta-service commit -> virtual in-memory modify remains unchanged. Status and Doris-exception exits still reach the existing subclass garbage-collection/abort path, including the MoW delete-bitmap lock fallback.
  • Parallel paths: local compaction still uses the sequential merge wrapper; Cloud base, cumulative, full, and index-change paths still pass through the Cloud wrapper; cumulative grouped-compaction hooks retain their per-call result state.
  • Performance and observability: the reader-vector work and counter/log updates are unchanged. MonotonicMicros() measures the same interval as the old stopwatch and is safer against wall-clock adjustment. The prior inline concern about rejecting timestamp zero is resolved on this head.
  • Validation: live formatting, license, and repository checks pass. No build or test execution was reported for this head.
  • User focus: no additional focus was supplied; the complete PR was reviewed.

Review completion: complete after one full normal/risk round; all subagents returned no new valuable findings, and all initial risks and existing-thread context were resolved.

@mymeiyi

mymeiyi commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

mymeiyi added a commit to mymeiyi/doris that referenced this pull request Sep 3, 2026
…paction

### What problem does this PR solve?

Issue Number: None

Related PR: apache#67466

Problem Summary: Distributed compaction workers use a preferred peer to read input blocks from the coordinator, but the read-through path synchronously duplicated those one-shot blocks in each worker file cache. When a preferred peer is configured, skip cache append and finalize while preserving the existing cache lookup path. Also skip prefetch because it cannot provide value without cache writeback.

### Release note

Distributed compaction workers no longer cache input blocks fetched through the coordinator preferred-peer path.

### Check List (For Author)

- Test: Unit Test (updated, not run per request)
- Behavior changed: Yes (preferred-peer distributed compaction reads no longer write worker file cache)
- Does this need documentation: No
mymeiyi added a commit to mymeiyi/doris that referenced this pull request Sep 3, 2026
### What problem does this PR solve?

Issue Number: None

Related PR: apache#67466

Problem Summary: Distributed compaction readers need to read cached data from the coordinator even when general peer reads are disabled. Carry an optional preferred peer through RowsetReader and IOContext, try only that peer first, and fall back to remote storage on failure. Because worker compaction reads are one-shot, skip worker file-cache writeback and ineffective prefetch when a preferred peer is configured. Record successful preferred peers in PeerCacheNodes and cover routing, fallback, propagation, and no-write behavior.

### Release note

Support per-request preferred peer reads for backend rowset readers. Distributed compaction workers do not cache input blocks fetched through the preferred-peer path.

### Check List (For Author)

- Test: Unit Test not completed
    - ./run-be-ut.sh --run --filter=CachedRemoteFileReaderPeerTest.read_at_uses_preferred_peer_when_global_peer_read_disabled -j4 was attempted previously; configuration failed because thirdparty/installed/arrow-24.0.0 is incomplete
    - Per request, the merged changes were not compiled or run
- Behavior changed: Yes (a configured preferred peer is tried before remote storage, reported in PeerCacheNodes, and does not write worker file cache)
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.02% (29552/46896)
Line Coverage 48.06% (309836/644721)
Region Coverage 43.64% (250313/573559)
Branch Coverage 45.22% (116476/257558)

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17597	3103	3104	3103
q2	2117	263	228	228
q3	10212	926	538	538
q4	4677	256	202	202
q5	7666	576	378	378
q6	138	116	94	94
q7	540	500	381	381
q8	9237	932	919	919
q9	3498	2511	2374	2374
q10	6507	860	721	721
q11	395	198	188	188
q12	621	263	201	201
q13	18119	1535	1158	1158
q14	159	149	137	137
q15	q16	431	399	376	376
q17	1416	864	784	784
q18	3141	2237	2233	2233
q19	1279	911	765	765
q20	372	283	205	205
q21	5703	1672	1782	1672
q22	327	270	230	230
Total cold run time: 94152 ms
Total hot run time: 16887 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3487	3448	3409	3409
q2	513	400	366	366
q3	2227	2396	2129	2129
q4	1201	1165	894	894
q5	2170	2088	2086	2086
q6	170	115	86	86
q7	1002	930	858	858
q8	1600	1415	1436	1415
q9	3152	3132	3138	3132
q10	1836	1811	1629	1629
q11	365	270	252	252
q12	462	429	338	338
q13	1480	1536	1146	1146
q14	182	170	169	169
q15	q16	394	398	363	363
q17	3597	3301	3196	3196
q18	4812	4419	4735	4419
q19	956	931	880	880
q20	1028	976	831	831
q21	3894	3196	3212	3196
q22	413	355	328	328
Total cold run time: 34941 ms
Total hot run time: 31122 ms

@hello-stephen

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

query5	4257	408	343	343
query6	387	136	130	130
query7	4941	411	239	239
query8	285	128	114	114
query9	8684	2908	2895	2895
query10	405	223	186	186
query11	5373	1044	907	907
query12	112	72	69	69
query13	1201	439	340	340
query14	6112	2214	2089	2089
query14_1	2005	1982	1985	1982
query15	177	129	108	108
query16	927	421	351	351
query17	778	435	333	333
query18	2326	314	228	228
query19	159	130	99	99
query20	72	68	69	68
query21	200	100	85	85
query22	5477	5353	5245	5245
query23	6838	6328	6030	6030
query23_1	6000	6091	5928	5928
query24	7330	1103	768	768
query24_1	764	764	791	764
query25	417	301	243	243
query26	1256	231	129	129
query27	2792	431	252	252
query28	4681	1504	1505	1504
query29	904	429	335	335
query30	256	156	129	129
query31	816	400	340	340
query32	142	68	70	68
query33	460	214	180	180
query34	984	815	485	485
query35	423	401	341	341
query36	561	540	529	529
query37	116	88	68	68
query38	1007	839	813	813
query39	504	498	488	488
query39_1	463	463	453	453
query40	203	87	73	73
query41	56	50	51	50
query42	75	70	71	70
query43	240	247	213	213
query44	1016	552	548	548
query45	107	107	96	96
query46	770	827	534	534
query47	782	770	726	726
query48	315	322	229	229
query49	557	245	192	192
query50	776	267	198	198
query51	8275	8168	8266	8168
query52	65	76	59	59
query53	195	201	151	151
query54	219	166	182	166
query55	84	62	54	54
query56	207	289	174	174
query57	748	646	673	646
query58	209	162	178	162
query59	1248	1261	1103	1103
query60	241	195	180	180
query61	164	137	141	137
query62	370	235	193	193
query63	179	139	145	139
query64	2735	690	623	623
query65	1628	1600	1600	1600
query66	1949	249	204	204
query67	9789	9705	9704	9704
query68	2759	1193	717	717
query69	354	226	192	192
query70	686	627	619	619
query71	250	172	166	166
query72	2423	1753	1576	1576
query73	680	610	348	348
query74	1597	1234	1130	1130
query75	1170	1110	962	962
query76	2317	744	543	543
query77	256	267	218	218
query78	3782	3515	3206	3206
query79	2511	816	565	565
query80	1584	340	285	285
query81	489	157	135	135
query82	1077	126	92	92
query83	291	215	195	195
query84	301	115	88	88
query85	785	409	297	297
query86	444	171	163	163
query87	1020	995	887	887
query88	2772	2125	2112	2112
query89	281	190	173	173
query90	1976	122	122	122
query91	135	124	100	100
query92	79	63	69	63
query93	1663	1136	705	705
query94	700	237	222	222
query95	512	269	222	222
query96	831	596	278	278
query97	1035	1048	970	970
query98	159	137	133	133
query99	447	343	317	317
Total cold run time: 178603 ms
Total hot run time: 82018 ms

@hello-stephen

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

query1	0.01	0.00	0.00
query2	0.08	0.04	0.04
query3	0.24	0.12	0.11
query4	1.60	0.10	0.10
query5	0.17	0.16	0.16
query6	1.25	0.71	0.70
query7	0.03	0.01	0.00
query8	0.05	0.03	0.03
query9	0.31	0.21	0.20
query10	0.35	0.34	0.31
query11	0.16	0.12	0.12
query12	0.15	0.12	0.11
query13	0.31	0.30	0.30
query14	0.45	0.48	0.44
query15	0.36	0.33	0.36
query16	0.23	0.22	0.23
query17	0.60	0.67	0.65
query18	0.18	0.16	0.15
query19	1.17	1.13	1.16
query20	0.01	0.01	0.01
query21	15.48	0.16	0.11
query22	5.10	0.04	0.04
query23	16.18	0.25	0.10
query24	3.02	0.32	0.26
query25	0.10	0.05	0.04
query26	0.79	0.16	0.13
query27	0.04	0.04	0.03
query28	3.62	0.53	0.29
query29	12.47	3.23	2.59
query30	0.26	0.11	0.12
query31	2.76	0.38	0.17
query32	3.53	0.31	0.24
query33	1.52	1.39	1.53
query34	15.35	2.20	1.79
query35	1.74	1.70	1.72
query36	0.46	0.31	0.28
query37	0.06	0.04	0.04
query38	0.05	0.03	0.02
query39	0.02	0.02	0.03
query40	0.12	0.08	0.08
query41	0.08	0.03	0.02
query42	0.03	0.03	0.02
query43	0.03	0.03	0.03
Total cold run time: 90.52 s
Total hot run time: 14.61 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.33% (34671/45422)
Line Coverage 61.41% (391414/637358)
Region Coverage 57.48% (328448/571375)
Branch Coverage 58.43% (150063/256819)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants