yangzhg commented on a change in pull request #8117:
URL: https://github.com/apache/incubator-doris/pull/8117#discussion_r809912069



##########
File path: be/src/common/status.h
##########
@@ -235,21 +238,59 @@ class Status {
     ///   trailing message.
     Status clone_and_append(const Slice& msg) const;
 
-    operator bool() { return this->ok(); }
+    operator bool() const { return this->ok(); }
 
 private:
-    const char* copy_state(const char* state);
+    void assemble_state(TStatusCode::type code, const Slice& msg, int16_t 
precise_code, const Slice& msg2) {
+        DCHECK(code != TStatusCode::OK);
+        uint32_t len1 = msg.size;
+        uint32_t len2 = msg2.size;
+        uint32_t size = len1 + ((len2 > 0) ? (2 + len2) : 0);
+
+        // limited to MESSAGE_LEN
+        if (UNLIKELY(size > MESSAGE_LEN)) {
+            LOG(WARNING) << "warning: Status msg truncated, " << to_string();
+            size = MESSAGE_LEN;
+        }
+
+        _length = size;
+        _code = (char)code;
+        _precise_code = precise_code;
 
-    Status(TStatusCode::type code, const Slice& msg, int16_t precise_code, 
const Slice& msg2);
+        // copy msg
+        char* result =  _state + HEADER_LEN;
+        uint32_t len = std::min<uint32_t>(len1, MESSAGE_LEN);
+        memcpy(result, msg.data, len);
+
+        // copy msg2
+        if (len2 > 0 && len < MESSAGE_LEN - 2) {
+            result[len++] = ':'; 
+            result[len++] = ' ';
+            memcpy(&result[len], msg2.data, std::min<uint32_t>(len2, 
MESSAGE_LEN - len));
+        }
+    }
+
+    Status(TStatusCode::type code, const Slice& msg, int16_t precise_code, 
const Slice& msg2) {
+        assemble_state(code, msg, precise_code, msg2);
+    }
 
 private:
-    // OK status has a nullptr _state.  Otherwise, _state is a new[] array
+    // OK status has a zero _length.  Otherwise, _state is a static array
     // of the following form:
     //    _state[0..3] == length of message
     //    _state[4]    == code
     //    _state[5..6] == precise_code
     //    _state[7..]  == message
-    const char* _state;
+    union {
+        char _state[STATE_CAPACITY];
+
+        struct {
+            int64_t _length : 32;       // message length
+            int64_t _code : 8;          
+            int64_t _precise_code : 16;

Review comment:
       what is precise_code stand for?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to