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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 94b03b83068f44d17fd03a1074b2e65bba3f7602
Author: yiguolei <[email protected]>
AuthorDate: Tue May 28 12:49:58 2024 +0800

    [enhancement](atomicstatus) use lock to make the status object more stable 
(#35476)
    
    ## Proposed changes
    
    1. In the past, if error code is not ok and then get status, the status
    maybe ok. some dcheck maybe failed.
    
    In this PR use std mutex to make this behavior stable.
    ## Further comments
    
    If this is a relatively large or complex change, kick off the discussion
    at [[email protected]](mailto:[email protected]) by explaining why
    you chose the solution you did and what alternatives you considered,
    etc...
    
    ---------
    
    Co-authored-by: yiguolei <[email protected]>
---
 be/src/common/status.h | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/be/src/common/status.h b/be/src/common/status.h
index 99b591639e9..ea33e64307a 100644
--- a/be/src/common/status.h
+++ b/be/src/common/status.h
@@ -553,26 +553,24 @@ class AtomicStatus {
 public:
     AtomicStatus() : error_st_(Status::OK()) {}
 
-    bool ok() const { return error_code_.load() == 0; }
+    bool ok() const { return error_code_.load(std::memory_order_acquire) == 0; 
}
 
     bool update(const Status& new_status) {
         // If new status is normal, or the old status is abnormal, then not 
need update
-        if (new_status.ok() || error_code_.load() != 0) {
+        if (new_status.ok() || error_code_.load(std::memory_order_acquire) != 
0) {
             return false;
         }
-        int16_t expected_error_code = 0;
-        if (error_code_.compare_exchange_strong(expected_error_code, 
new_status.code(),
-                                                std::memory_order_acq_rel)) {
-            // lock here for read status, to avoid core during return error_st_
-            std::lock_guard l(mutex_);
-            error_st_ = new_status;
-            return true;
-        } else {
+        std::lock_guard l(mutex_);
+        if (error_code_.load(std::memory_order_acquire) != 0) {
             return false;
         }
+        error_st_ = new_status;
+        error_code_.store(new_status.code(), std::memory_order_release);
+        return true;
     }
 
     // will copy a new status object to avoid concurrency
+    // This stauts could only be called when ok==false
     Status status() const {
         std::lock_guard l(mutex_);
         return error_st_;


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

Reply via email to