Skip to content

Conversation

@bobhan1
Copy link
Contributor

@bobhan1 bobhan1 commented Sep 5, 2025

pick #55630

…ache#55630)

Currently, `MetaServiceImpl::get_rowset` use `calc_sync_versions` to
eliminate unnecessary version ranges when BE sync rowset metas. One of
the optimizations is as the following:
```cpp
std::vector<std::pair<int64_t, int64_t>> calc_sync_versions(int64_t req_bc_cnt, int64_t bc_cnt,
                                                            int64_t req_cc_cnt, int64_t cc_cnt,
                                                            int64_t req_cp, int64_t cp,
                                                            int64_t req_start, int64_t req_end) {
    // ...
    if (req_cc_cnt < cc_cnt) {
        Version cc_version;
        if (req_cp < cp && req_cc_cnt + 1 == cc_cnt) {
            // * only one CC happened and CP changed
            // BE  [=][=][=][=][=====][=][=]
            //                  ^~~~~ req_cp
            // MS  [=][=][=][=][xxxxxxxxxxxxxx][=======][=][=]
            //                                  ^~~~~~~ ms_cp
            //                  ^____________^ related_versions: [req_cp, ms_cp - 1]
            //
            cc_version = {req_cp, cp - 1};
        } else {
    // ...
}
```
This optimization replies on the assumption that only cumulative
compaction will change the cumulative point. However, full compaction
can also change the cumulative point, which breaks the above replied
assumption. This will cause data correctness problem in multi-cluster
environment because it will make the tablet failed to sync some rowset
metas forever.

A data correctness problem has been observed in the following
situaitions:

1. For a certain tablet, base_compaction_cnt=14,
cumulative_compaction_cnt=804, cumu_point=7458.
On node A of the write cluster (cluster 0), a full compaction of
[2-7464] and a cumulative compaction of [7465-7486] were performed. The
stats then became base_compaction_cnt=15, cumulative_compaction_cnt=805,
cumu_point=7465.
2. On node B of the read cluster (cluster 1), during sync_rowset, we
have:
req_base_compaction_cnt=14, base_compaction_cnt=15,
req_cumulative_compaction_cnt=804, cumulative_compaction_cnt=805,
req_cp=7458, cp=7465,
req_start=7487, req_end=int_max.
3. calc_sync_version computes that the rowsets to be pulled are [0-7464]
and [7487-int_max], but it misses the rowset [7465-7486] produced by
cumulative compaction.
4. Moreover, since the max_version of the tablet on cluster 1 node B has
been updated, subsequent sync_rowset operations will also not pull the
rowset [7465-7486].
5. This causes duplicate keys problem on MOW table because new rowset
will generate delete bitmap marks on [7465-7486].

---
This PR forbids the above optimization when full compaction cnt is
changed.

None

- Test <!-- At least one of them must be included. -->
    - [x] Regression test
    - [x] 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 <!-- Add your reason?  -->

- Behavior changed:
    - [ ] No.
    - [ ] Yes. <!-- Explain the behavior change -->

- Does this need documentation?
    - [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
apache/doris-website#1214 -->

- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
@bobhan1 bobhan1 requested a review from dataroaring as a code owner September 5, 2025 02:21
@Thearas
Copy link
Contributor

Thearas commented Sep 5, 2025

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?

@bobhan1
Copy link
Contributor Author

bobhan1 commented Sep 5, 2025

run buildall

@hello-stephen
Copy link
Contributor

Cloud UT Coverage Report

Increment line coverage 66.67% (6/9) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 80.94% (1176/1453)
Line Coverage 65.30% (20309/31101)
Region Coverage 66.93% (10239/15298)
Branch Coverage 56.53% (5410/9570)

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage `` 🎉
Increment coverage report
Complete coverage report

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17592	6789	6735	6735
q2	2043	202	191	191
q3	10580	1141	1166	1141
q4	10408	744	781	744
q5	7751	2886	2815	2815
q6	218	135	135	135
q7	960	617	628	617
q8	9383	2001	2052	2001
q9	6699	6440	6406	6406
q10	7017	2268	2291	2268
q11	474	265	263	263
q12	410	212	209	209
q13	17805	3004	2997	2997
q14	230	213	208	208
q15	501	462	461	461
q16	483	379	374	374
q17	991	667	573	573
q18	7388	6630	6538	6538
q19	1412	1116	1085	1085
q20	491	198	200	198
q21	3911	3169	3337	3169
q22	1095	1004	995	995
Total cold run time: 107842 ms
Total hot run time: 40123 ms

----- Round 2, with runtime_filter_mode=off -----
q1	6668	6636	6620	6620
q2	341	232	231	231
q3	2924	2915	2904	2904
q4	2012	1832	1849	1832
q5	5723	5749	5736	5736
q6	211	131	129	129
q7	2290	1785	1802	1785
q8	3413	3549	3602	3549
q9	8797	8931	8862	8862
q10	3554	3543	3545	3543
q11	604	491	506	491
q12	825	593	612	593
q13	11025	3216	3135	3135
q14	296	285	287	285
q15	518	463	475	463
q16	481	452	449	449
q17	1900	1635	1645	1635
q18	8232	7834	7724	7724
q19	1677	1465	1598	1465
q20	2074	1845	1862	1845
q21	5253	5043	4996	4996
q22	1117	1068	1035	1035
Total cold run time: 69935 ms
Total hot run time: 59307 ms

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 42.31% (11/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 42.09% (11245/26716)
Line Coverage 32.62% (96301/295201)
Region Coverage 30.55% (55284/180965)
Branch Coverage 26.88% (27369/101838)

@doris-robot
Copy link

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

query1	948	410	403	403
query2	6250	1972	1889	1889
query3	8687	204	202	202
query4	33576	23395	23393	23393
query5	3619	462	437	437
query6	273	181	201	181
query7	4205	302	304	302
query8	283	216	215	215
query9	9498	2618	2580	2580
query10	498	268	258	258
query11	18462	15232	15357	15232
query12	173	104	102	102
query13	1561	440	418	418
query14	8655	7291	7077	7077
query15	246	169	176	169
query16	8024	484	507	484
query17	1616	648	625	625
query18	2156	330	324	324
query19	284	164	166	164
query20	125	114	122	114
query21	215	106	107	106
query22	4653	4514	4367	4367
query23	35650	34093	34071	34071
query24	11788	2835	2972	2835
query25	605	427	421	421
query26	1337	171	172	171
query27	2974	348	356	348
query28	7761	2162	2177	2162
query29	704	452	450	450
query30	271	162	163	162
query31	1044	862	847	847
query32	108	57	63	57
query33	766	309	299	299
query34	980	517	526	517
query35	876	755	721	721
query36	1121	934	970	934
query37	207	70	69	69
query38	4111	4056	3939	3939
query39	1561	1477	1439	1439
query40	265	99	105	99
query41	51	51	50	50
query42	110	106	102	102
query43	537	497	499	497
query44	1309	800	824	800
query45	187	169	177	169
query46	1194	730	762	730
query47	2047	1928	1891	1891
query48	482	392	390	390
query49	1059	400	410	400
query50	840	427	432	427
query51	7344	7341	7339	7339
query52	102	93	87	87
query53	267	182	177	177
query54	1256	457	454	454
query55	78	78	78	78
query56	275	259	251	251
query57	1290	1211	1224	1211
query58	219	208	211	208
query59	3328	3081	3021	3021
query60	298	262	261	261
query61	114	106	111	106
query62	899	684	709	684
query63	245	201	198	198
query64	5075	672	629	629
query65	3707	3294	3320	3294
query66	1333	296	306	296
query67	16668	16143	15434	15434
query68	4824	567	565	565
query69	454	263	257	257
query70	1131	1087	1072	1072
query71	388	252	247	247
query72	5968	4007	4004	4004
query73	763	344	347	344
query74	10420	9212	9341	9212
query75	3390	2638	2656	2638
query76	2725	1116	1157	1116
query77	372	270	268	268
query78	10334	9574	9526	9526
query79	1846	605	594	594
query80	1273	421	418	418
query81	510	224	229	224
query82	309	88	88	88
query83	169	158	149	149
query84	297	79	85	79
query85	1046	298	289	289
query86	352	305	307	305
query87	4362	4246	4187	4187
query88	4114	2382	2371	2371
query89	421	288	289	288
query90	2191	185	186	185
query91	184	149	152	149
query92	66	52	51	51
query93	1895	537	543	537
query94	893	286	287	286
query95	349	252	255	252
query96	619	287	284	284
query97	3280	3202	3180	3180
query98	215	203	193	193
query99	1625	1339	1313	1313
Total cold run time: 303235 ms
Total hot run time: 192438 ms

@doris-robot
Copy link

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

query1	0.03	0.03	0.03
query2	0.08	0.04	0.05
query3	0.24	0.05	0.06
query4	1.64	0.08	0.07
query5	0.53	0.51	0.51
query6	1.14	0.75	0.75
query7	0.02	0.01	0.01
query8	0.06	0.05	0.04
query9	0.56	0.50	0.50
query10	0.56	0.55	0.55
query11	0.16	0.12	0.12
query12	0.16	0.13	0.12
query13	0.62	0.60	0.60
query14	0.77	0.80	0.80
query15	0.87	0.83	0.84
query16	0.38	0.36	0.39
query17	1.04	1.06	0.99
query18	0.20	0.19	0.20
query19	1.88	1.85	1.89
query20	0.02	0.01	0.02
query21	15.37	0.69	0.65
query22	3.21	6.95	2.50
query23	18.26	1.40	1.35
query24	2.29	0.22	0.21
query25	0.15	0.08	0.09
query26	0.28	0.18	0.19
query27	0.09	0.08	0.08
query28	13.36	0.59	0.59
query29	12.66	3.37	3.37
query30	0.26	0.06	0.06
query31	2.84	0.41	0.41
query32	3.22	0.48	0.48
query33	3.00	3.04	2.98
query34	17.08	4.53	4.51
query35	4.65	4.59	4.65
query36	0.66	0.49	0.48
query37	0.19	0.16	0.16
query38	0.17	0.16	0.14
query39	0.05	0.04	0.04
query40	0.17	0.13	0.14
query41	0.11	0.05	0.05
query42	0.06	0.05	0.05
query43	0.04	0.04	0.05
Total cold run time: 109.13 s
Total hot run time: 31.55 s

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (26/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.22% (19715/26209)
Line Coverage 68.47% (201233/293886)
Region Coverage 66.52% (120446/181069)
Branch Coverage 59.83% (61121/102162)

@bobhan1
Copy link
Contributor Author

bobhan1 commented Sep 5, 2025

run buildall

@hello-stephen
Copy link
Contributor

Cloud UT Coverage Report

Increment line coverage 66.67% (6/9) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 80.94% (1176/1453)
Line Coverage 65.38% (20335/31101)
Region Coverage 66.94% (10241/15298)
Branch Coverage 56.55% (5412/9570)

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 42.31% (11/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 42.08% (11243/26716)
Line Coverage 32.60% (96246/295201)
Region Coverage 30.54% (55269/180965)
Branch Coverage 26.86% (27358/101838)

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17930	6749	6649	6649
q2	2047	205	181	181
q3	10598	1103	1157	1103
q4	10422	760	741	741
q5	7743	2874	2811	2811
q6	216	133	137	133
q7	979	630	626	626
q8	9357	1893	1948	1893
q9	6596	6397	6425	6397
q10	7035	2244	2346	2244
q11	455	263	260	260
q12	391	217	215	215
q13	17793	2986	3015	2986
q14	234	203	204	203
q15	505	452	467	452
q16	482	383	378	378
q17	976	611	572	572
q18	7165	6494	6681	6494
q19	1460	1061	998	998
q20	480	202	203	202
q21	3859	3049	3171	3049
q22	1125	989	991	989
Total cold run time: 107848 ms
Total hot run time: 39576 ms

----- Round 2, with runtime_filter_mode=off -----
q1	6610	6534	6549	6534
q2	327	230	231	230
q3	2898	2880	2893	2880
q4	2021	1765	1851	1765
q5	5719	5709	5705	5705
q6	214	130	129	129
q7	2220	1845	1784	1784
q8	3376	3512	3556	3512
q9	8781	8931	8812	8812
q10	3527	3518	3531	3518
q11	625	493	502	493
q12	810	611	598	598
q13	10659	3183	3176	3176
q14	300	278	263	263
q15	510	474	458	458
q16	511	444	438	438
q17	1856	1611	1606	1606
q18	8250	7894	7741	7741
q19	1686	1616	1491	1491
q20	2060	1813	1920	1813
q21	5277	5087	5061	5061
q22	1154	1062	1034	1034
Total cold run time: 69391 ms
Total hot run time: 59041 ms

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (26/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.22% (19715/26209)
Line Coverage 68.47% (201233/293886)
Region Coverage 66.52% (120446/181069)
Branch Coverage 59.83% (61121/102162)

@doris-robot
Copy link

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

query1	913	396	430	396
query2	6234	1972	1893	1893
query3	8692	198	195	195
query4	33587	23676	23731	23676
query5	4000	460	464	460
query6	299	185	176	176
query7	4204	310	322	310
query8	313	231	229	229
query9	9476	2576	2563	2563
query10	475	263	277	263
query11	17904	15056	15205	15056
query12	154	100	101	100
query13	1539	425	417	417
query14	9569	7528	6669	6669
query15	262	171	185	171
query16	8056	503	529	503
query17	1694	615	591	591
query18	2207	351	341	341
query19	393	163	169	163
query20	124	117	127	117
query21	219	119	113	113
query22	4756	4448	4307	4307
query23	35088	34286	33882	33882
query24	11827	2930	2873	2873
query25	626	408	406	406
query26	1212	173	171	171
query27	2342	342	360	342
query28	7186	2157	2177	2157
query29	852	445	454	445
query30	255	169	157	157
query31	1021	820	802	802
query32	102	60	60	60
query33	765	324	311	311
query34	996	526	514	514
query35	858	749	749	749
query36	1109	953	962	953
query37	127	71	66	66
query38	4043	3941	3969	3941
query39	1533	1446	1446	1446
query40	201	96	104	96
query41	57	46	48	46
query42	111	100	102	100
query43	523	487	477	477
query44	1214	829	815	815
query45	190	166	178	166
query46	1165	722	741	722
query47	2023	1928	1909	1909
query48	470	392	383	383
query49	925	391	408	391
query50	849	425	427	425
query51	7417	7247	7323	7247
query52	108	86	89	86
query53	251	184	181	181
query54	1236	464	466	464
query55	77	80	80	80
query56	268	247	261	247
query57	1328	1219	1208	1208
query58	235	208	220	208
query59	3290	3023	3056	3023
query60	289	255	253	253
query61	111	122	110	110
query62	859	668	714	668
query63	222	194	197	194
query64	4097	664	628	628
query65	3343	3254	3331	3254
query66	857	302	296	296
query67	15786	15726	15487	15487
query68	4493	568	551	551
query69	441	273	270	270
query70	1207	1089	1116	1089
query71	345	251	256	251
query72	6484	4175	4170	4170
query73	738	357	357	357
query74	10473	9016	9314	9016
query75	3356	2670	2679	2670
query76	2710	1048	1072	1048
query77	379	275	267	267
query78	10566	9697	9473	9473
query79	2448	599	598	598
query80	1096	431	421	421
query81	551	221	218	218
query82	574	88	86	86
query83	232	142	151	142
query84	234	77	77	77
query85	1758	303	282	282
query86	477	298	295	295
query87	4406	4233	4187	4187
query88	4094	2492	2378	2378
query89	395	289	284	284
query90	1902	185	186	185
query91	185	148	147	147
query92	60	48	48	48
query93	2137	549	549	549
query94	875	298	297	297
query95	361	260	259	259
query96	617	282	288	282
query97	3312	3114	3173	3114
query98	214	201	199	199
query99	1553	1314	1301	1301
Total cold run time: 301187 ms
Total hot run time: 191659 ms

@doris-robot
Copy link

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

query1	0.03	0.03	0.03
query2	0.08	0.04	0.04
query3	0.23	0.05	0.06
query4	1.64	0.08	0.09
query5	0.54	0.50	0.50
query6	1.14	0.75	0.74
query7	0.02	0.02	0.01
query8	0.05	0.05	0.04
query9	0.55	0.48	0.49
query10	0.56	0.53	0.55
query11	0.17	0.12	0.11
query12	0.16	0.13	0.13
query13	0.62	0.60	0.60
query14	0.77	0.81	0.79
query15	0.86	0.83	0.84
query16	0.38	0.39	0.39
query17	1.02	1.04	1.02
query18	0.20	0.18	0.20
query19	1.87	1.82	1.88
query20	0.02	0.02	0.01
query21	15.39	0.66	0.65
query22	3.67	6.71	2.30
query23	18.25	1.39	1.44
query24	2.06	0.26	0.21
query25	0.15	0.09	0.09
query26	0.26	0.18	0.18
query27	0.08	0.07	0.08
query28	13.33	0.60	0.57
query29	12.67	3.31	3.30
query30	0.25	0.06	0.06
query31	2.86	0.40	0.40
query32	3.24	0.48	0.48
query33	3.00	3.03	3.03
query34	16.88	4.58	4.57
query35	4.65	4.64	4.57
query36	0.67	0.50	0.47
query37	0.19	0.16	0.16
query38	0.16	0.17	0.16
query39	0.06	0.04	0.04
query40	0.15	0.13	0.13
query41	0.10	0.05	0.05
query42	0.06	0.06	0.05
query43	0.05	0.05	0.04
Total cold run time: 109.09 s
Total hot run time: 31.35 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage `` 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (26/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.22% (19715/26209)
Line Coverage 68.47% (201233/293886)
Region Coverage 66.52% (120446/181069)
Branch Coverage 59.83% (61121/102162)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (26/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.20% (19708/26209)
Line Coverage 68.43% (201094/293886)
Region Coverage 66.49% (120384/181069)
Branch Coverage 59.78% (61074/102162)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (26/26) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.20% (19708/26209)
Line Coverage 68.42% (201088/293886)
Region Coverage 66.49% (120400/181069)
Branch Coverage 59.78% (61072/102162)

Copy link
Contributor

@dataroaring dataroaring left a comment

Choose a reason for hiding this comment

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

LGTM

@dataroaring dataroaring merged commit e0d08ca into apache:branch-3.0 Sep 5, 2025
23 of 24 checks passed
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.

5 participants