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

yiguolei 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 4047c3577d [enhancement](Status) Optimize Status implementation
4047c3577d is described below

commit 4047c3577d08b215af6da3bb1335e482621a6fe6
Author: plat1ko <platonekos...@gmail.com>
AuthorDate: Fri Aug 12 11:39:35 2022 +0800

    [enhancement](Status) Optimize Status implementation
---
 be/src/common/status.cpp                 |  88 ++++++--------
 be/src/common/status.h                   | 203 +++++++++----------------------
 be/src/env/env_posix.cpp                 |   2 +-
 be/src/exec/tablet_sink.cpp              |   6 +-
 be/src/io/broker_reader.cpp              |   4 +-
 be/src/io/broker_writer.cpp              |   6 +-
 be/src/io/fs/file_reader.h               |   1 +
 be/src/io/fs/file_system_map.cpp         |   2 +
 be/src/io/fs/file_writer.h               |   1 +
 be/src/runtime/buffered_block_mgr2.cc    |   4 +-
 be/src/runtime/data_stream_sender.h      |   2 +-
 be/src/util/broker_storage_backend.cpp   |   8 +-
 be/src/util/thrift_client.cpp            |   2 +-
 be/src/util/thrift_rpc_helper.cpp        |   2 +-
 be/src/vec/sink/vdata_stream_sender.h    |   2 +-
 be/src/vec/sink/vtablet_sink.cpp         |   2 +-
 be/test/runtime/export_task_mgr_test.cpp |   4 +-
 17 files changed, 120 insertions(+), 219 deletions(-)

diff --git a/be/src/common/status.cpp b/be/src/common/status.cpp
index c46fdb1a8c..a56d99606f 100644
--- a/be/src/common/status.cpp
+++ b/be/src/common/status.cpp
@@ -4,12 +4,13 @@
 
 #include "common/status.h"
 
-#include <glog/logging.h>
 #include <rapidjson/prettywriter.h>
 #include <rapidjson/stringbuffer.h>
 
 #include <boost/stacktrace.hpp>
 
+#include "gen_cpp/types.pb.h" // for PStatus
+
 namespace doris {
 
 constexpr int MAX_ERROR_NUM = 65536;
@@ -41,13 +42,13 @@ Status::Status(const TStatus& s) {
     if (s.status_code != TStatusCode::OK) {
         // It is ok to set precise code == 1 here, because we do not know the 
precise code
         // just from thrift's TStatus
-        if (s.error_msgs.empty()) {
-            assemble_state(s.status_code, Slice(), 1, Slice());
-        } else {
-            assemble_state(s.status_code, s.error_msgs[0], 1, Slice());
+        _code = s.status_code;
+        _precise_code = 1;
+        if (!s.error_msgs.empty()) {
+            _err_msg = s.error_msgs[0];
         }
     } else {
-        _length = 0;
+        _code = 0;
     }
 }
 
@@ -58,18 +59,18 @@ Status::Status(const PStatus& s) {
     if (code != TStatusCode::OK) {
         // It is ok to set precise code == 1 here, because we do not know the 
precise code
         // just from thrift's TStatus
-        if (s.error_msgs_size() == 0) {
-            assemble_state(code, Slice(), 1, Slice());
-        } else {
-            assemble_state(code, s.error_msgs(0), 1, Slice());
+        _code = code;
+        _precise_code = 1;
+        if (s.error_msgs_size() > 0) {
+            _err_msg = s.error_msgs(0);
         }
     } else {
-        _length = 0;
+        _code = 0;
     }
 }
 
 // Implement it here to remove the boost header file from status.h to reduce 
precompile time
-Status Status::ConstructErrorStatus(int16_t precise_code, const Slice& msg) {
+Status Status::ConstructErrorStatus(int16_t precise_code) {
 // This will print all error status's stack, it maybe too many, but it is just 
used for debug
 #ifdef PRINT_ALL_ERR_STATUS_STACKTRACE
     LOG(WARNING) << "Error occurred, error code = " << precise_code << ", with 
message: " << msg
@@ -78,10 +79,10 @@ Status Status::ConstructErrorStatus(int16_t precise_code, 
const Slice& msg) {
     if (error_states[abs(precise_code)].stacktrace) {
         // Add stacktrace as part of message, could use LOG(WARN) << "" << 
status will print both
         // the error message and the stacktrace
-        return Status(TStatusCode::INTERNAL_ERROR, msg, precise_code,
-                      
boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
+        return Status(TStatusCode::INTERNAL_ERROR,
+                      
boost::stacktrace::to_string(boost::stacktrace::stacktrace()), precise_code);
     } else {
-        return Status(TStatusCode::INTERNAL_ERROR, msg, precise_code, Slice());
+        return Status(TStatusCode::INTERNAL_ERROR, std::string_view(), 
precise_code);
     }
 }
 
@@ -91,8 +92,7 @@ void Status::to_thrift(TStatus* s) const {
         s->status_code = TStatusCode::OK;
     } else {
         s->status_code = code();
-        auto msg = message();
-        s->error_msgs.emplace_back(msg.data, msg.size);
+        s->error_msgs.push_back(_err_msg);
         s->__isset.error_msgs = true;
     }
 }
@@ -109,8 +109,7 @@ void Status::to_protobuf(PStatus* s) const {
         s->set_status_code((int)TStatusCode::OK);
     } else {
         s->set_status_code(code());
-        auto msg = message();
-        s->add_error_msgs(msg.data, msg.size);
+        s->add_error_msgs(_err_msg);
     }
 }
 
@@ -129,7 +128,7 @@ std::string Status::code_as_string() const {
     case TStatusCode::INTERNAL_ERROR:
         return "Internal error";
     case TStatusCode::THRIFT_RPC_ERROR:
-        return "Thrift rpc error";
+        return "RPC error";
     case TStatusCode::TIMEOUT:
         return "Timeout";
     case TStatusCode::MEM_ALLOC_FAILED:
@@ -173,9 +172,7 @@ std::string Status::code_as_string() const {
     case TStatusCode::DATA_QUALITY_ERROR:
         return "Data quality error";
     default: {
-        char tmp[30];
-        snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", 
static_cast<int>(code()));
-        return tmp;
+        return fmt::format("Unknown code({})", code());
     }
     }
     return std::string();
@@ -186,39 +183,26 @@ std::string Status::to_string() const {
     if (ok()) {
         return result;
     }
-
-    result.append(": ");
-    Slice msg = message();
-    result.append(reinterpret_cast<const char*>(msg.data), msg.size);
-    int16_t posix = precise_code();
-    if (posix != 1) {
-        char buf[64];
-        snprintf(buf, sizeof(buf), " (error %d)", posix);
-        result.append(buf);
+    if (precise_code() != 1) {
+        result.append(fmt::format("(error {})", precise_code()));
     }
+    result.append(": ");
+    result.append(_err_msg);
     return result;
 }
 
-Slice Status::message() const {
-    if (ok()) {
-        return Slice();
-    }
-
-    return Slice(_state + HEADER_LEN, _length - HEADER_LEN);
-}
-
-Status Status::clone_and_prepend(const Slice& msg) const {
-    if (ok()) {
-        return *this;
+Status& Status::prepend(std::string_view msg) {
+    if (!ok()) {
+        _err_msg = std::string(msg) + _err_msg;
     }
-    return Status(code(), msg, precise_code(), message());
+    return *this;
 }
 
-Status Status::clone_and_append(const Slice& msg) const {
-    if (ok()) {
-        return *this;
+Status& Status::append(std::string_view msg) {
+    if (!ok()) {
+        _err_msg.append(msg);
     }
-    return Status(code(), message(), precise_code(), msg);
+    return *this;
 }
 
 std::string Status::to_json() const {
@@ -234,17 +218,17 @@ std::string Status::to_json() const {
     if (ok()) {
         writer.String("OK");
     } else {
-        auto err_msg = get_error_msg();
         int16_t posix = precise_code();
         if (posix != 1) {
             char buf[64];
             snprintf(buf, sizeof(buf), " (error %d)", posix);
-            err_msg.append(buf);
+            writer.String((_err_msg + buf).c_str());
+        } else {
+            writer.String(_err_msg.c_str());
         }
-        writer.String(err_msg.c_str());
     }
     writer.EndObject();
     return s.GetString();
 }
 
-} // namespace doris
\ No newline at end of file
+} // namespace doris
diff --git a/be/src/common/status.h b/be/src/common/status.h
index bf947cb812..285d84c478 100644
--- a/be/src/common/status.h
+++ b/be/src/common/status.h
@@ -7,19 +7,18 @@
 #include <fmt/format.h>
 #include <glog/logging.h>
 
-#include <boost/stacktrace.hpp>
 #include <iostream>
 #include <string>
-#include <vector>
+#include <string_view>
 
 #include "common/compiler_util.h"
 #include "common/logging.h"
 #include "gen_cpp/Status_types.h" // for TStatus
-#include "gen_cpp/types.pb.h"     // for PStatus
-#include "util/slice.h"           // for Slice
 
 namespace doris {
 
+class PStatus;
+
 // ErrorName, ErrorCode, String Description, Should print stacktrace
 #define APPLY_FOR_ERROR_CODES(M)                                         \
     M(OLAP_SUCCESS, 0, "", false)                                        \
@@ -241,47 +240,36 @@ enum ErrorCode {
 };
 
 class Status {
-    enum {
-        // If the error and log returned by the query are truncated, the 
status to string may be too long.
-        STATE_CAPACITY = 2048,
-        HEADER_LEN = 7,
-        MESSAGE_LEN = STATE_CAPACITY - HEADER_LEN
-    };
-
 public:
-    Status() : _length(0) {}
+    Status() : _code(0) {}
 
     // copy c'tor makes copy of error detail so Status can be returned by value
-    Status(const Status& rhs) { *this = rhs; }
+    Status(const Status& rhs) = default;
 
     // move c'tor
-    Status(Status&& rhs) { *this = rhs; }
+    Status(Status&& rhs) noexcept = default;
 
     // same as copy c'tor
-    Status& operator=(const Status& rhs) {
-        if (rhs._length) {
-            memcpy(_state, rhs._state, rhs._length);
-        } else {
-            _length = 0;
-        }
-        return *this;
-    }
+    Status& operator=(const Status& rhs) = default;
 
     // move assign
-    Status& operator=(Status&& rhs) {
-        this->operator=(rhs);
-        return *this;
-    }
+    Status& operator=(Status&& rhs) noexcept = default;
 
     // "Copy" c'tor from TStatus.
     Status(const TStatus& status);
 
     Status(const PStatus& pstatus);
 
+    Status(TStatusCode::type code, std::string_view msg, int16_t precise_code 
= 1)
+            : _code(code), _precise_code(precise_code), _err_msg(msg) {}
+
+    Status(TStatusCode::type code, std::string&& msg, int16_t precise_code = 1)
+            : _code(code), _precise_code(precise_code), 
_err_msg(std::move(msg)) {}
+
     static Status OK() { return Status(); }
 
     template <typename... Args>
-    static Status ErrorFmt(TStatusCode::type code, const std::string& fmt, 
Args&&... args) {
+    static Status ErrorFmt(TStatusCode::type code, std::string_view fmt, 
Args&&... args) {
         // In some cases, fmt contains '{}' but there are no args.
         if constexpr (sizeof...(args) == 0) {
             return Status(code, fmt);
@@ -291,108 +279,108 @@ public:
     }
 
     template <typename... Args>
-    static Status PublishTimeout(const std::string& fmt, Args&&... args) {
+    static Status PublishTimeout(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::PUBLISH_TIMEOUT, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status MemoryAllocFailed(const std::string& fmt, Args&&... args) {
+    static Status MemoryAllocFailed(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::MEM_ALLOC_FAILED, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status BufferAllocFailed(const std::string& fmt, Args&&... args) {
+    static Status BufferAllocFailed(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::BUFFER_ALLOCATION_FAILED, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status InvalidArgument(const std::string& fmt, Args&&... args) {
+    static Status InvalidArgument(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::INVALID_ARGUMENT, fmt, 
std::forward<Args>(args)...);
     }
     template <typename... Args>
-    static Status MinimumReservationUnavailable(const std::string& fmt, 
Args&&... args) {
+    static Status MinimumReservationUnavailable(std::string_view fmt, 
Args&&... args) {
         return ErrorFmt(TStatusCode::MINIMUM_RESERVATION_UNAVAILABLE, fmt,
                         std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status Corruption(const std::string& fmt, Args&&... args) {
+    static Status Corruption(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::CORRUPTION, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status IOError(const std::string& fmt, Args&&... args) {
+    static Status IOError(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::IO_ERROR, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status NotFound(const std::string& fmt, Args&&... args) {
+    static Status NotFound(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::NOT_FOUND, fmt, 
std::forward<Args>(args)...);
     }
     template <typename... Args>
-    static Status AlreadyExist(const std::string& fmt, Args&&... args) {
+    static Status AlreadyExist(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::ALREADY_EXIST, fmt, 
std::forward<Args>(args)...);
     }
     template <typename... Args>
-    static Status NotSupported(const std::string& fmt, Args&&... args) {
+    static Status NotSupported(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::NOT_IMPLEMENTED_ERROR, fmt, 
std::forward<Args>(args)...);
     }
     template <typename... Args>
-    static Status EndOfFile(const std::string& fmt, Args&&... args) {
+    static Status EndOfFile(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::END_OF_FILE, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status InternalError(const std::string& fmt, Args&&... args) {
+    static Status InternalError(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::INTERNAL_ERROR, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status RuntimeError(const std::string& fmt, Args&&... args) {
+    static Status RuntimeError(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::RUNTIME_ERROR, fmt, 
std::forward<Args>(args)...);
     }
     template <typename... Args>
-    static Status Cancelled(const std::string& fmt, Args&&... args) {
+    static Status Cancelled(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::CANCELLED, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status MemoryLimitExceeded(const std::string& fmt, Args&&... args) {
+    static Status MemoryLimitExceeded(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::MEM_LIMIT_EXCEEDED, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status ThriftRpcError(const std::string& fmt, Args&&... args) {
+    static Status RpcError(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::THRIFT_RPC_ERROR, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status TimedOut(const std::string& fmt, Args&&... args) {
+    static Status TimedOut(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::TIMEOUT, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status TooManyTasks(const std::string& fmt, Args&&... args) {
+    static Status TooManyTasks(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::TOO_MANY_TASKS, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status ServiceUnavailable(const std::string& fmt, Args&&... args) {
+    static Status ServiceUnavailable(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::SERVICE_UNAVAILABLE, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status Uninitialized(const std::string& fmt, Args&&... args) {
+    static Status Uninitialized(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::UNINITIALIZED, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status Aborted(const std::string& fmt, Args&&... args) {
+    static Status Aborted(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::ABORTED, fmt, 
std::forward<Args>(args)...);
     }
 
     template <typename... Args>
-    static Status DataQualityError(const std::string& fmt, Args&&... args) {
+    static Status DataQualityError(std::string_view fmt, Args&&... args) {
         return ErrorFmt(TStatusCode::DATA_QUALITY_ERROR, fmt, 
std::forward<Args>(args)...);
     }
 
@@ -400,16 +388,16 @@ public:
     //      Precise code is for ErrorCode's enum value
     //      All Status Error is treated as Internal Error
     static Status OLAPInternalError(int16_t precise_code) {
-        return ConstructErrorStatus(precise_code, Slice());
+        return ConstructErrorStatus(precise_code);
     }
 
-    static Status ConstructErrorStatus(int16_t precise_code, const Slice& msg);
+    static Status ConstructErrorStatus(int16_t precise_code);
 
-    bool ok() const { return _length == 0; }
+    bool ok() const { return _code == 0; }
 
     bool is_cancelled() const { return code() == TStatusCode::CANCELLED; }
     bool is_mem_limit_exceeded() const { return code() == 
TStatusCode::MEM_LIMIT_EXCEEDED; }
-    bool is_thrift_rpc_error() const { return code() == 
TStatusCode::THRIFT_RPC_ERROR; }
+    bool is_rpc_error() const { return code() == 
TStatusCode::THRIFT_RPC_ERROR; }
     bool is_end_of_file() const { return code() == TStatusCode::END_OF_FILE; }
     bool is_not_found() const { return code() == TStatusCode::NOT_FOUND; }
     bool is_already_exist() const { return code() == 
TStatusCode::ALREADY_EXIST; }
@@ -449,10 +437,7 @@ public:
     TStatus to_thrift() const;
     void to_protobuf(PStatus* status) const;
 
-    std::string get_error_msg() const {
-        auto msg = message();
-        return std::string(msg.data, msg.size);
-    }
+    const std::string& get_error_msg() const { return _err_msg; }
 
     /// @return A string representation of this status suitable for printing.
     ///   Returns the string "OK" for success.
@@ -465,16 +450,6 @@ public:
     ///   text or sub code information.
     std::string code_as_string() const;
 
-    // This is similar to to_string, except that it does not include
-    // the stringified error code or sub code.
-    //
-    // @note The returned Slice is only valid as long as this Status object
-    //   remains live and unchanged.
-    //
-    // @return The message portion of the Status. For @c OK statuses,
-    //   this returns an empty string.
-    Slice message() const;
-
     TStatusCode::type code() const {
         return ok() ? TStatusCode::OK : static_cast<TStatusCode::type>(_code);
     }
@@ -487,19 +462,17 @@ public:
     ///
     /// @param [in] msg
     ///   The message to prepend.
-    /// @return A new Status object with the same state plus an additional
-    ///   leading message.
-    Status clone_and_prepend(const Slice& msg) const;
+    /// @return A ref to Status object
+    Status& prepend(std::string_view msg);
 
-    /// Clone this status and add the specified suffix to the message.
+    /// Add the specified suffix to the message.
     ///
     /// If this status is OK, then an OK status will be returned.
     ///
     /// @param [in] msg
     ///   The message to append.
-    /// @return A new Status object with the same state plus an additional
-    ///   trailing message.
-    Status clone_and_append(const Slice& msg) const;
+    /// @return A ref to Status object
+    Status& append(std::string_view msg);
 
     // if(!status) or if (status) will use this operator
     operator bool() const { return this->ok(); }
@@ -517,68 +490,9 @@ public:
     }
 
 private:
-    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)) {
-            std::string str = code_as_string();
-            str.append(": ");
-            str.append(msg.data, msg.size);
-            char buf[64] = {};
-            int n = snprintf(buf, sizeof(buf), " precise_code:%d ", 
precise_code);
-            str.append(buf, n);
-            str.append(msg2.data, msg2.size);
-            LOG(WARNING) << "warning: Status msg truncated, " << str;
-            size = MESSAGE_LEN;
-        }
-
-        _length = size + HEADER_LEN;
-        _code = (char)code;
-        _precise_code = precise_code;
-
-        // 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 = 1,
-           const Slice& msg2 = Slice()) {
-        assemble_state(code, msg, precise_code, msg2);
-    }
-
-private:
-    // 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
-    union {
-        char _state[STATE_CAPACITY];
-
-        struct {
-            // Message length == HEADER(7 bytes) + message size
-            // Sometimes error message is empty, so that we could not use 
length==0 to indicate
-            // whether there is error happens
-            int64_t _length : 32;
-            int64_t _code : 8;
-            int64_t _precise_code : 16;
-            int64_t _message : 8; // save message since here
-        };
-    };
+    int8_t _code;
+    int16_t _precise_code;
+    std::string _err_msg;
 };
 
 // Override the << operator, it is used during LOG(INFO) << "xxxx" << status;
@@ -617,14 +531,13 @@ inline std::ostream& operator<<(std::ostream& ostr, const 
Status& param) {
         }                                    \
     } while (false)
 
-#define EXIT_IF_ERROR(stmt)                        \
-    do {                                           \
-        const Status& _status_ = (stmt);           \
-        if (UNLIKELY(!_status_.ok())) {            \
-            string msg = _status_.get_error_msg(); \
-            LOG(ERROR) << msg;                     \
-            exit(1);                               \
-        }                                          \
+#define EXIT_IF_ERROR(stmt)                         \
+    do {                                            \
+        const Status& _status_ = (stmt);            \
+        if (UNLIKELY(!_status_.ok())) {             \
+            LOG(ERROR) << _status_.get_error_msg(); \
+            exit(1);                                \
+        }                                           \
     } while (false)
 
 /// @brief Emit a warning if @c to_call returns a bad status.
@@ -658,4 +571,4 @@ inline std::ostream& operator<<(std::ostream& ostr, const 
Status& param) {
 #undef WARN_UNUSED_RESULT
 #endif
 
-#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
\ No newline at end of file
+#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
diff --git a/be/src/env/env_posix.cpp b/be/src/env/env_posix.cpp
index 4f6243ae3e..414c86c9ca 100644
--- a/be/src/env/env_posix.cpp
+++ b/be/src/env/env_posix.cpp
@@ -596,7 +596,7 @@ Status PosixEnv::create_dir_if_missing(const string& 
dirname, bool* created) {
         if (is_dir) {
             return Status::OK();
         } else {
-            return s.clone_and_append("path already exists but not a dir");
+            return std::move(s.append("path already exists but not a dir"));
         }
     }
     return s;
diff --git a/be/src/exec/tablet_sink.cpp b/be/src/exec/tablet_sink.cpp
index 35d024f719..8993cec7ce 100644
--- a/be/src/exec/tablet_sink.cpp
+++ b/be/src/exec/tablet_sink.cpp
@@ -292,7 +292,7 @@ Status NodeChannel::add_row(Tuple* input_tuple, int64_t 
tablet_id) {
             std::lock_guard<SpinLock> l(_cancel_msg_lock);
             return Status::InternalError("add row failed. {}", _cancel_msg);
         } else {
-            return st.clone_and_prepend("already stopped, can't add row. 
cancelled/eos: ");
+            return std::move(st.prepend("already stopped, can't add row. 
cancelled/eos: "));
         }
     }
 
@@ -376,8 +376,8 @@ Status NodeChannel::close_wait(RuntimeState* state) {
             std::lock_guard<SpinLock> l(_cancel_msg_lock);
             return Status::InternalError("wait close failed. {}", _cancel_msg);
         } else {
-            return st.clone_and_prepend(
-                    "already stopped, skip waiting for close. cancelled/!eos: 
");
+            return std::move(
+                    st.prepend("already stopped, skip waiting for close. 
cancelled/!eos: "));
         }
     }
 
diff --git a/be/src/io/broker_reader.cpp b/be/src/io/broker_reader.cpp
index b2f33b7d29..57db2d1c29 100644
--- a/be/src/io/broker_reader.cpp
+++ b/be/src/io/broker_reader.cpp
@@ -98,7 +98,7 @@ Status BrokerReader::open() {
         std::stringstream ss;
         ss << "Open broker reader failed, broker:" << broker_addr << " 
failed:" << e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 
     if (response.opStatus.statusCode != TBrokerOperationStatusCode::OK) {
@@ -170,7 +170,7 @@ Status BrokerReader::readat(int64_t position, int64_t 
nbytes, int64_t* bytes_rea
         std::stringstream ss;
         ss << "Read from broker failed, broker:" << broker_addr << " failed:" 
<< e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 
     if (response.opStatus.statusCode == 
TBrokerOperationStatusCode::END_OF_FILE) {
diff --git a/be/src/io/broker_writer.cpp b/be/src/io/broker_writer.cpp
index 5271d34f73..8972ccc519 100644
--- a/be/src/io/broker_writer.cpp
+++ b/be/src/io/broker_writer.cpp
@@ -99,7 +99,7 @@ Status BrokerWriter::open() {
         std::stringstream ss;
         ss << "Open broker writer failed, broker:" << broker_addr << " 
failed:" << e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 
     VLOG_ROW << "debug: send broker open writer response: "
@@ -153,13 +153,13 @@ Status BrokerWriter::write(const uint8_t* buf, size_t 
buf_len, size_t* written_l
             std::stringstream ss;
             ss << "Fail to write to broker, broker:" << broker_addr << " 
failed:" << e.what();
             LOG(WARNING) << ss.str();
-            return Status::ThriftRpcError(ss.str());
+            return Status::RpcError(ss.str());
         }
     } catch (apache::thrift::TException& e) {
         std::stringstream ss;
         ss << "Fail to write to broker, broker:" << broker_addr << " failed:" 
<< e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 
     VLOG_ROW << "debug: send broker pwrite response: "
diff --git a/be/src/io/fs/file_reader.h b/be/src/io/fs/file_reader.h
index d0c568d0aa..d8cc1652d0 100644
--- a/be/src/io/fs/file_reader.h
+++ b/be/src/io/fs/file_reader.h
@@ -22,6 +22,7 @@
 #include "common/status.h"
 #include "gutil/macros.h"
 #include "io/fs/path.h"
+#include "util/slice.h"
 
 namespace doris {
 namespace io {
diff --git a/be/src/io/fs/file_system_map.cpp b/be/src/io/fs/file_system_map.cpp
index e685650a06..2467781e53 100644
--- a/be/src/io/fs/file_system_map.cpp
+++ b/be/src/io/fs/file_system_map.cpp
@@ -17,6 +17,8 @@
 
 #include "io/fs/file_system_map.h"
 
+#include <mutex>
+
 namespace doris {
 namespace io {
 
diff --git a/be/src/io/fs/file_writer.h b/be/src/io/fs/file_writer.h
index bbd65e4cbd..804a9f329d 100644
--- a/be/src/io/fs/file_writer.h
+++ b/be/src/io/fs/file_writer.h
@@ -22,6 +22,7 @@
 #include "common/status.h"
 #include "gutil/macros.h"
 #include "io/fs/path.h"
+#include "util/slice.h"
 
 namespace doris {
 namespace io {
diff --git a/be/src/runtime/buffered_block_mgr2.cc 
b/be/src/runtime/buffered_block_mgr2.cc
index fa95e63c05..e610cf3803 100644
--- a/be/src/runtime/buffered_block_mgr2.cc
+++ b/be/src/runtime/buffered_block_mgr2.cc
@@ -721,12 +721,12 @@ Status BufferedBlockMgr2::allocate_scratch_space(int64_t 
block_size, TmpFileMgr:
         // blacklisted so we will not repeatedly log the same error.
         LOG(WARNING) << "Error while allocating temporary file range: " << 
status.get_error_msg()
                      << ". Will try another temporary file.";
-        errs.emplace_back(status.message().data, status.message().size);
+        errs.emplace_back(status.get_error_msg());
     }
     Status err_status = Status::InternalError(
             "No usable temporary files: space could not be allocated on any 
temporary device.");
     for (int i = 0; i < errs.size(); ++i) {
-        err_status = err_status.clone_and_append(errs[i]);
+        err_status.append(errs[i]);
     }
     return err_status;
 }
diff --git a/be/src/runtime/data_stream_sender.h 
b/be/src/runtime/data_stream_sender.h
index 8d00cdbbe3..542164638a 100644
--- a/be/src/runtime/data_stream_sender.h
+++ b/be/src/runtime/data_stream_sender.h
@@ -171,7 +171,7 @@ protected:
                    << ", error_text=" << cntl->ErrorText()
                    << ", client: " << BackendOptions::get_localhost();
                 LOG(WARNING) << ss.str();
-                return Status::ThriftRpcError(ss.str());
+                return Status::RpcError(ss.str());
             }
             return Status::OK();
         }
diff --git a/be/src/util/broker_storage_backend.cpp 
b/be/src/util/broker_storage_backend.cpp
index 0471c5794d..a574c68165 100644
--- a/be/src/util/broker_storage_backend.cpp
+++ b/be/src/util/broker_storage_backend.cpp
@@ -184,7 +184,7 @@ Status BrokerStorageBackend::rename(const std::string& 
orig_name, const std::str
         std::stringstream ss;
         ss << "Fail to rename file: " << orig_name << " to: " << new_name << " 
msg:" << e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 
     LOG(INFO) << "finished to rename file. orig: " << orig_name << ", new: " 
<< new_name;
@@ -264,7 +264,7 @@ Status BrokerStorageBackend::list(const std::string& 
remote_path, bool contain_m
         std::stringstream ss;
         ss << "failed to list files in remote path: " << remote_path << ", 
msg: " << e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 
     return status;
@@ -321,7 +321,7 @@ Status BrokerStorageBackend::rm(const std::string& remote) {
         std::stringstream ss;
         ss << "failed to delete file in remote path: " << remote << ", msg: " 
<< e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 }
 
@@ -384,7 +384,7 @@ Status BrokerStorageBackend::exist(const std::string& path) 
{
         std::stringstream ss;
         ss << "failed to check exist: " << path << ", msg: " << e.what();
         LOG(WARNING) << ss.str();
-        return Status::ThriftRpcError(ss.str());
+        return Status::RpcError(ss.str());
     }
 }
 
diff --git a/be/src/util/thrift_client.cpp b/be/src/util/thrift_client.cpp
index 4ef7c6380c..bc2699f7d9 100644
--- a/be/src/util/thrift_client.cpp
+++ b/be/src/util/thrift_client.cpp
@@ -42,7 +42,7 @@ Status ThriftClientImpl::open() {
         const std::string& err_msg = strings::Substitute("Couldn't open 
transport for $0:$1 ($2)",
                                                          ipaddress(), port(), 
e.what());
         VLOG_CRITICAL << err_msg;
-        return Status::ThriftRpcError(err_msg);
+        return Status::RpcError(err_msg);
     }
     return Status::OK();
 }
diff --git a/be/src/util/thrift_rpc_helper.cpp 
b/be/src/util/thrift_rpc_helper.cpp
index 94ad060250..4241a27fdf 100644
--- a/be/src/util/thrift_rpc_helper.cpp
+++ b/be/src/util/thrift_rpc_helper.cpp
@@ -79,7 +79,7 @@ Status ThriftRpcHelper::rpc(const std::string& ip, const 
int32_t port,
                 
std::chrono::milliseconds(config::thrift_client_retry_interval_ms * 2));
         // just reopen to disable this connection
         client.reopen(timeout_ms);
-        return Status::ThriftRpcError("failed to call frontend service");
+        return Status::RpcError("failed to call frontend service");
     }
     return Status::OK();
 }
diff --git a/be/src/vec/sink/vdata_stream_sender.h 
b/be/src/vec/sink/vdata_stream_sender.h
index 421a0daf3f..3d572366e1 100644
--- a/be/src/vec/sink/vdata_stream_sender.h
+++ b/be/src/vec/sink/vdata_stream_sender.h
@@ -247,7 +247,7 @@ private:
                     "failed to send brpc batch, error={}, error_text={}, 
client: {}",
                     berror(cntl->ErrorCode()), cntl->ErrorText(), 
BackendOptions::get_localhost());
             LOG(WARNING) << err;
-            return Status::ThriftRpcError(err);
+            return Status::RpcError(err);
         }
         return Status::OK();
     }
diff --git a/be/src/vec/sink/vtablet_sink.cpp b/be/src/vec/sink/vtablet_sink.cpp
index 7052f73583..4965562c3c 100644
--- a/be/src/vec/sink/vtablet_sink.cpp
+++ b/be/src/vec/sink/vtablet_sink.cpp
@@ -169,7 +169,7 @@ Status VNodeChannel::add_row(const BlockRow& block_row, 
int64_t tablet_id) {
             std::lock_guard<SpinLock> l(_cancel_msg_lock);
             return Status::InternalError("add row failed. {}", _cancel_msg);
         } else {
-            return st.clone_and_prepend("already stopped, can't add row. 
cancelled/eos: ");
+            return std::move(st.prepend("already stopped, can't add row. 
cancelled/eos: "));
         }
     }
 
diff --git a/be/test/runtime/export_task_mgr_test.cpp 
b/be/test/runtime/export_task_mgr_test.cpp
index b3fc91f5cc..07f7a28683 100644
--- a/be/test/runtime/export_task_mgr_test.cpp
+++ b/be/test/runtime/export_task_mgr_test.cpp
@@ -155,7 +155,7 @@ TEST_F(ExportTaskMgrTest, RunAfterFail) {
 
     // make it finishing
     ExportTaskResult task_result;
-    EXPECT_TRUE(mgr.finish_task(id, Status::ThriftRpcError("Thrift rpc 
error"), task_result).ok());
+    EXPECT_TRUE(mgr.finish_task(id, Status::RpcError("Thrift rpc error"), 
task_result).ok());
     EXPECT_TRUE(mgr.get_task_state(id, &res).ok());
     EXPECT_EQ(TExportState::CANCELLED, res.state);
     EXPECT_EQ(TStatusCode::OK, res.status.status_code);
@@ -207,7 +207,7 @@ TEST_F(ExportTaskMgrTest, FinishUnknownJob) {
 
     // make it finishing
     ExportTaskResult task_result;
-    EXPECT_FALSE(mgr.finish_task(id, Status::ThriftRpcError("Thrift rpc 
error"), task_result).ok());
+    EXPECT_FALSE(mgr.finish_task(id, Status::RpcError("Thrift rpc error"), 
task_result).ok());
     EXPECT_TRUE(mgr.get_task_state(id, &res).ok());
     EXPECT_EQ(TExportState::CANCELLED, res.state);
     EXPECT_EQ(TStatusCode::OK, res.status.status_code);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to