Skip to content

branch-4.1: [fix](be) Fix DCHECK in LocalExchangeSharedState::sub_total_mem_usage #63742#64014

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-63742-branch-4.1
Jun 3, 2026
Merged

branch-4.1: [fix](be) Fix DCHECK in LocalExchangeSharedState::sub_total_mem_usage #63742#64014
yiguolei merged 1 commit into
branch-4.1from
auto-pick-63742-branch-4.1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 2, 2026

Cherry-picked from #63742

…#63742)

Problem Summary: In LocalExchangeSharedState::sub_total_mem_usage(),
`mem_usage` is `std::atomic<int64_t>` but `delta` is `size_t`. The
existing debug check

    DCHECK_GE(prev_usage - delta, 0);

was never effective: the usual arithmetic conversions promote
`prev_usage - delta` to `size_t`, and an unsigned expression is
trivially `>= 0`. So the guard against `mem_usage` underflow
(subtracting more than was added) silently passed in all debug builds,
leaving any over-subtraction undetected.

Fix: compare `prev_usage` (int64_t) against `cast_set<int64_t>(delta)`
so the comparison is performed entirely in signed space, and a real
underflow will actually trip the DCHECK with the original prev_usage and
delta values in the failure message. The release-mode guard on the next
line (`cast_set<int64_t>(prev_usage - delta)` throws on underflow
because the wrapped size_t result exceeds INT64_MAX) is preserved as-is.
@github-actions github-actions Bot requested a review from yiguolei as a code owner June 2, 2026 08:19
@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?

@hello-stephen
Copy link
Copy Markdown
Contributor

run buildall

@yiguolei yiguolei merged commit 31670b8 into branch-4.1 Jun 3, 2026
28 of 31 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.

3 participants