Skip to content

[improvement](be) Add release-enabled Doris check macros#63730

Open
mrhhsg wants to merge 1 commit into
apache:masterfrom
mrhhsg:codex/doris-check-comparison-macros
Open

[improvement](be) Add release-enabled Doris check macros#63730
mrhhsg wants to merge 1 commit into
apache:masterfrom
mrhhsg:codex/doris-check-comparison-macros

Conversation

@mrhhsg
Copy link
Copy Markdown
Member

@mrhhsg mrhhsg commented May 27, 2026

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Add a dedicated common/check.h header for Doris check macros. DORIS_CHECK accepts streamed context through the usual << syntax while avoiding evaluation of streamed operands on successful checks. DORIS_CHECK_EQ/NE/LT/LE/GT/GE are intended for invariants that should remain checked in Release builds: Debug builds map them to the corresponding DCHECK_* macros, while Release builds evaluate each operand once, compare with the requested operator, and throw through the existing DORIS_CHECK-style fatal error path with a message that includes both compared expressions and their actual values. Release comparison checks also accept streamed context. status.h re-exports common/check.h to keep existing includes compatible.

Release note

None

Check List (For Author)

  • Test: Manual test
    • DORIS_HOME=$PWD ninja -C be/ut_build_ASAN src/common/CMakeFiles/Common.dir/check.cpp.o test/CMakeFiles/doris_be_test.dir/common/status_test.cpp.o
    • DORIS_HOME=$PWD ninja -C be/ut_build_ASAN Common
    • Compiled a small -DNDEBUG translation unit that includes common/check.h directly and exercises the Release macro branch, streamed DORIS_CHECK context, streamed comparison-check context, and stream-operand laziness on success.
    • Compiled a small -DNDEBUG translation unit that checks DORIS_CHECK/DORIS_CHECK_EQ statement behavior under if/else.
    • git diff --check
    • build-support/check-format.sh
    • Attempted ./run-be-ut.sh --run --filter=StatusTest.*, but stopped it after it expanded into a broad BE UT rebuild.
    • Attempted build-support/run-clang-tidy.sh on the changed files before this follow-up; it failed on pre-existing/toolchain header diagnostics outside this change.
  • Behavior changed: No
  • Does this need documentation: No

@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@mrhhsg
Copy link
Copy Markdown
Member Author

mrhhsg commented May 27, 2026

/review

@mrhhsg mrhhsg force-pushed the codex/doris-check-comparison-macros branch 2 times, most recently from ea4605c to 641d320 Compare May 27, 2026 08:15
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.

Review result: one blocking issue found.

Critical checkpoints:

  • Goal/test: The PR adds release-enabled Doris check macros and tests basic success/failure/stream-laziness behavior, but it misses streamed messages containing fmt braces.
  • Scope: The change is focused and small.
  • Concurrency/lifecycle/config/compatibility/transactions/data writes/FE-BE variables: Not applicable to this macro refactor.
  • Parallel paths: status.h re-exports the new header; direct common/check.h include path is covered structurally.
  • Error handling: The new failure helper incorrectly forwards an already-rendered stream message as a fmt format string through Status::FatalError in debug builds.
  • Tests: Unit coverage exists for simple streaming, but not for brace-containing streamed context, which exposes the issue.
  • Observability/performance: No additional issue found; success paths avoid stream operand evaluation as intended.

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

Comment thread be/src/common/check.cpp
Issue Number: None

Related PR: None

Problem Summary: Add a dedicated common/check.h header for Doris check macros. DORIS_CHECK accepts streamed context through the usual << syntax while avoiding evaluation of streamed operands on successful checks. DORIS_CHECK_EQ/NE/LT/LE/GT/GE are intended for invariants that should remain checked in Release builds: Debug builds map them to the corresponding DCHECK_* macros, while Release builds evaluate each operand once, compare with the requested operator, and throw through DORIS_CHECK-style fatal error handling with a message that includes both compared expressions and their actual values. Release comparison checks also accept streamed context. status.h re-exports common/check.h to keep existing includes compatible. The added tests cover successful comparisons, single-evaluation behavior, stream operand laziness, and failure behavior for Debug/Release builds.

None

- Test: Manual test
    - DORIS_HOME=$PWD ninja -C be/ut_build_ASAN src/common/CMakeFiles/Common.dir/check.cpp.o test/CMakeFiles/doris_be_test.dir/common/status_test.cpp.o
    - DORIS_HOME=$PWD ninja -C be/ut_build_ASAN Common
    - Compiled a small -DNDEBUG translation unit that includes common/check.h directly and exercises the Release macro branch, streamed DORIS_CHECK context, streamed comparison-check context, and stream-operand laziness on success.
    - Compiled a small -DNDEBUG translation unit that checks DORIS_CHECK/DORIS_CHECK_EQ statement behavior under if/else.
    - git diff --check
    - build-support/check-format.sh
    - Attempted ./run-be-ut.sh --run --filter=StatusTest.*, but stopped it after it expanded into a broad BE UT rebuild.
    - Attempted build-support/run-clang-tidy.sh on the changed files before this follow-up; it failed on pre-existing/toolchain header diagnostics outside this change.
- Behavior changed: No
- Does this need documentation: No
@mrhhsg mrhhsg force-pushed the codex/doris-check-comparison-macros branch from 641d320 to 4ae57b2 Compare May 27, 2026 09:39
@mrhhsg
Copy link
Copy Markdown
Member Author

mrhhsg commented May 27, 2026

/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.

I found one blocking issue: one DCHECK-to-DORIS_CHECK conversion turns an existing user-facing InvalidArgument path into a fatal invariant failure, making the following validation branch unreachable in Release builds.

Critical checkpoint conclusions:

  • Goal and tests: the goal is to add release-enabled Doris check macros; the check macro tests cover the new macro mechanics, but the json_remove invalid-arity path is not covered after this conversion.
  • Scope/focus: the macro addition is focused, but converting argument validation-adjacent DCHECKs needs care.
  • Concurrency/lifecycle/config: no new concurrency, lifecycle, or configuration concerns found.
  • Compatibility: no storage/protocol compatibility issue found; one user-visible error-handling compatibility issue is raised inline.
  • Parallel paths: I reviewed the other changed JSONB checks and did not find another changed line with an immediately following explicit InvalidArgument branch like this one.
  • Error handling: blocking issue found because a recoverable InvalidArgument becomes FatalError/Exception before the intended Status return. The existing check.cpp fmt-format concern was already present in the supplied review context and the current patch shows it addressed.
  • Memory/transactions/persistence/observability: no additional issue found.
  • Tests: add or preserve coverage for invalid json_remove arity so this remains a normal error instead of a fatal check.

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

uint32_t result, size_t input_rows_count) const override {
DCHECK_GE(arguments.size(), 2);
DORIS_CHECK_GE(arguments.size(), 2);

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 check now fires before the existing validation below, so json_remove with fewer than two arguments no longer returns Status::InvalidArgument("json_remove requires at least 2 arguments") in Release builds; it throws a fatal check exception instead. Since this function is variadic (get_number_of_arguments() == 0, is_variadic() == true) and already has a user-facing arity check immediately after this line, the arity failure is not an invariant for DORIS_CHECK_GE. Please leave this as a non-fatal validation path, for example by removing this DORIS_CHECK_GE and relying on the existing if (arguments.size() < 2) branch.

@mrhhsg
Copy link
Copy Markdown
Member Author

mrhhsg commented May 27, 2026

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31808 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 4ae57b270c3eea2a933518d7ecf88ac20d1f8b75, 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	17663	4034	3992	3992
q2	q3	10766	1499	825	825
q4	4683	474	344	344
q5	7561	2292	2148	2148
q6	250	176	136	136
q7	963	788	628	628
q8	9365	1739	1675	1675
q9	5531	4983	4940	4940
q10	6447	2217	1889	1889
q11	452	279	247	247
q12	633	426	290	290
q13	18218	3362	2833	2833
q14	271	254	237	237
q15	q16	823	769	713	713
q17	1033	1003	982	982
q18	6946	5828	5530	5530
q19	1305	1233	1162	1162
q20	556	450	285	285
q21	6068	2860	2639	2639
q22	457	504	313	313
Total cold run time: 99991 ms
Total hot run time: 31808 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	4801	4738	4754	4738
q2	q3	4923	5284	4617	4617
q4	2179	2155	1402	1402
q5	4974	4744	4665	4665
q6	244	171	124	124
q7	1921	1781	1569	1569
q8	2397	2152	2175	2152
q9	7833	7424	7384	7384
q10	4769	4679	4187	4187
q11	532	378	347	347
q12	727	740	524	524
q13	3010	3401	2813	2813
q14	271	288	252	252
q15	q16	684	717	614	614
q17	1283	1257	1242	1242
q18	7438	7018	6887	6887
q19	1106	1106	1109	1106
q20	2242	2210	1962	1962
q21	5309	4580	4499	4499
q22	525	473	403	403
Total cold run time: 57168 ms
Total hot run time: 51487 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 172282 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 4ae57b270c3eea2a933518d7ecf88ac20d1f8b75, data reload: false

query5	4313	660	546	546
query6	339	229	207	207
query7	4224	559	304	304
query8	330	234	213	213
query9	8818	4099	4099	4099
query10	467	340	292	292
query11	5776	2804	2227	2227
query12	180	127	126	126
query13	1284	606	419	419
query14	6093	5454	5123	5123
query14_1	4528	4452	4457	4452
query15	216	200	184	184
query16	1058	485	418	418
query17	1126	720	602	602
query18	2514	490	367	367
query19	219	212	165	165
query20	141	137	135	135
query21	212	140	120	120
query22	13611	13594	13320	13320
query23	17438	16421	16232	16232
query23_1	16274	16433	16343	16343
query24	7418	1810	1307	1307
query24_1	1351	1339	1334	1334
query25	589	507	437	437
query26	1322	340	186	186
query27	2644	589	341	341
query28	4515	2006	2046	2006
query29	1059	661	531	531
query30	304	236	203	203
query31	1152	1085	960	960
query32	91	80	78	78
query33	569	373	322	322
query34	1187	1154	687	687
query35	779	797	699	699
query36	1422	1388	1226	1226
query37	156	108	97	97
query38	3190	3182	3060	3060
query39	934	915	931	915
query39_1	908	865	878	865
query40	236	152	130	130
query41	75	71	72	71
query42	114	113	113	113
query43	330	332	300	300
query44	
query45	224	214	204	204
query46	1064	1214	751	751
query47	2370	2401	2286	2286
query48	420	434	302	302
query49	647	517	409	409
query50	1036	354	263	263
query51	4367	4341	4268	4268
query52	115	117	98	98
query53	260	284	204	204
query54	321	302	272	272
query55	96	94	90	90
query56	321	360	303	303
query57	1440	1427	1319	1319
query58	299	282	264	264
query59	1599	1688	1467	1467
query60	322	327	303	303
query61	161	158	149	149
query62	693	643	579	579
query63	249	200	210	200
query64	2425	795	676	676
query65	
query66	1748	478	365	365
query67	29745	29721	29562	29562
query68	
query69	465	347	317	317
query70	1032	994	1023	994
query71	307	280	280	280
query72	3034	2737	2350	2350
query73	863	754	429	429
query74	5127	4974	4776	4776
query75	2695	2606	2273	2273
query76	2299	1130	774	774
query77	411	409	331	331
query78	12541	12460	12025	12025
query79	1479	1061	733	733
query80	774	552	450	450
query81	479	284	246	246
query82	1378	157	128	128
query83	349	281	248	248
query84	264	142	110	110
query85	927	536	450	450
query86	456	342	345	342
query87	3432	3393	3205	3205
query88	3598	2741	2720	2720
query89	453	397	350	350
query90	1757	189	189	189
query91	182	172	143	143
query92	83	81	79	79
query93	1472	1384	807	807
query94	616	347	327	327
query95	668	397	356	356
query96	1035	781	357	357
query97	2723	2743	2598	2598
query98	243	233	226	226
query99	1185	1142	1021	1021
Total cold run time: 254605 ms
Total hot run time: 172282 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 28.89% (13/45) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.89% (20945/38866)
Line Coverage 37.47% (198495/529738)
Region Coverage 33.78% (155556/460493)
Branch Coverage 34.77% (67719/194768)

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 34.15% (14/41) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.87% (28118/38065)
Line Coverage 57.81% (305444/528381)
Region Coverage 54.87% (255085/464914)
Branch Coverage 56.46% (110374/195494)

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.

2 participants