This is an automated email from the ASF dual-hosted git repository.

HappenLee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new cddb80e8487 [fix](be) Fix DCHECK in 
LocalExchangeSharedState::sub_total_mem_usage (#63742)
cddb80e8487 is described below

commit cddb80e84872517dade5e3420bdc16bf16381224
Author: TengJianPing <[email protected]>
AuthorDate: Tue Jun 2 16:17:06 2026 +0800

    [fix](be) Fix DCHECK in LocalExchangeSharedState::sub_total_mem_usage 
(#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.
---
 be/src/exec/pipeline/dependency.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/be/src/exec/pipeline/dependency.h 
b/be/src/exec/pipeline/dependency.h
index 9ffbb2c5c7a..b08dd186710 100644
--- a/be/src/exec/pipeline/dependency.h
+++ b/be/src/exec/pipeline/dependency.h
@@ -927,7 +927,8 @@ public:
 
     void sub_total_mem_usage(size_t delta) {
         auto prev_usage = mem_usage.fetch_sub(delta);
-        DCHECK_GE(prev_usage - delta, 0) << "prev_usage: " << prev_usage << " 
delta: " << delta;
+        DCHECK_GE(prev_usage, cast_set<int64_t>(delta))
+                << "prev_usage: " << prev_usage << " delta: " << delta;
         if (cast_set<int64_t>(prev_usage - delta) <= _buffer_mem_limit) {
             sink_deps.front()->set_ready();
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to