]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/include/rocksdb/io_status.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / io_status.h
index ea13d3bc529a9a320933b85b9446bb422f7b61c8..0bf5e939a694916ae665ab6df5f0a48c3e513629 100644 (file)
 #pragma once
 
 #include <string>
+
 #include "rocksdb/slice.h"
 #ifdef OS_WIN
 #include <string.h>
 #endif
 #include <cstring>
+
 #include "status.h"
 
 namespace ROCKSDB_NAMESPACE {
@@ -28,7 +30,7 @@ class IOStatus : public Status {
   using Code = Status::Code;
   using SubCode = Status::SubCode;
 
-  enum IOErrorScope {
+  enum IOErrorScope : unsigned char {
     kIOErrorScopeFileSystem,
     kIOErrorScopeFile,
     kIOErrorScopeRange,
@@ -42,26 +44,20 @@ class IOStatus : public Status {
   // Copy the specified status.
   IOStatus(const IOStatus& s);
   IOStatus& operator=(const IOStatus& s);
-  IOStatus(IOStatus&& s)
-#if !(defined _MSC_VER) || ((defined _MSC_VER) && (_MSC_VER >= 1900))
-      noexcept
-#endif
-      ;
-  IOStatus& operator=(IOStatus&& s)
-#if !(defined _MSC_VER) || ((defined _MSC_VER) && (_MSC_VER >= 1900))
-      noexcept
-#endif
-      ;
+  IOStatus(IOStatus&& s) noexcept;
+  IOStatus& operator=(IOStatus&& s) noexcept;
   bool operator==(const IOStatus& rhs) const;
   bool operator!=(const IOStatus& rhs) const;
 
   void SetRetryable(bool retryable) { retryable_ = retryable; }
   void SetDataLoss(bool data_loss) { data_loss_ = data_loss; }
-  void SetScope(IOErrorScope scope) { scope_ = scope; }
+  void SetScope(IOErrorScope scope) {
+    scope_ = static_cast<unsigned char>(scope);
+  }
 
   bool GetRetryable() const { return retryable_; }
   bool GetDataLoss() const { return data_loss_; }
-  IOErrorScope GetScope() const { return scope_; }
+  IOErrorScope GetScope() const { return static_cast<IOErrorScope>(scope_); }
 
   // Return a success status.
   static IOStatus OK() { return IOStatus(); }
@@ -131,21 +127,22 @@ class IOStatus : public Status {
     return IOStatus(kIOError, kIOFenced, msg, msg2);
   }
 
+  static IOStatus Aborted(SubCode msg = kNone) {
+    return IOStatus(kAborted, msg);
+  }
+  static IOStatus Aborted(const Slice& msg, const Slice& msg2 = Slice()) {
+    return IOStatus(kAborted, msg, msg2);
+  }
+
   // Return a string representation of this status suitable for printing.
   // Returns the string "OK" for success.
   // std::string ToString() const;
 
  private:
   friend IOStatus status_to_io_status(Status&&);
-  bool retryable_;
-  bool data_loss_;
-  IOErrorScope scope_;
 
   explicit IOStatus(Code _code, SubCode _subcode = kNone)
-      : Status(_code, _subcode),
-        retryable_(false),
-        data_loss_(false),
-        scope_(kIOErrorScopeFileSystem) {}
+      : Status(_code, _subcode, false, false, kIOErrorScopeFileSystem) {}
 
   IOStatus(Code _code, SubCode _subcode, const Slice& msg, const Slice& msg2);
   IOStatus(Code _code, const Slice& msg, const Slice& msg2)
@@ -154,10 +151,7 @@ class IOStatus : public Status {
 
 inline IOStatus::IOStatus(Code _code, SubCode _subcode, const Slice& msg,
                           const Slice& msg2)
-    : Status(_code, _subcode),
-      retryable_(false),
-      data_loss_(false),
-      scope_(kIOErrorScopeFileSystem) {
+    : Status(_code, _subcode, false, false, kIOErrorScopeFileSystem) {
   assert(code_ != kOk);
   assert(subcode_ != kMaxSubCode);
   const size_t len1 = msg.size();
@@ -171,7 +165,7 @@ inline IOStatus::IOStatus(Code _code, SubCode _subcode, const Slice& msg,
     memcpy(result + len1 + 2, msg2.data(), len2);
   }
   result[size] = '\0';  // null terminator for C style string
-  state_ = result;
+  state_.reset(result);
 }
 
 inline IOStatus::IOStatus(const IOStatus& s) : Status(s.code_, s.subcode_) {
@@ -181,7 +175,7 @@ inline IOStatus::IOStatus(const IOStatus& s) : Status(s.code_, s.subcode_) {
   retryable_ = s.retryable_;
   data_loss_ = s.data_loss_;
   scope_ = s.scope_;
-  state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_);
+  state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_.get());
 }
 inline IOStatus& IOStatus::operator=(const IOStatus& s) {
   // The following condition catches both aliasing (when this == &s),
@@ -196,25 +190,16 @@ inline IOStatus& IOStatus::operator=(const IOStatus& s) {
     retryable_ = s.retryable_;
     data_loss_ = s.data_loss_;
     scope_ = s.scope_;
-    delete[] state_;
-    state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_);
+    state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_.get());
   }
   return *this;
 }
 
-inline IOStatus::IOStatus(IOStatus&& s)
-#if !(defined _MSC_VER) || ((defined _MSC_VER) && (_MSC_VER >= 1900))
-    noexcept
-#endif
-    : IOStatus() {
+inline IOStatus::IOStatus(IOStatus&& s) noexcept : IOStatus() {
   *this = std::move(s);
 }
 
-inline IOStatus& IOStatus::operator=(IOStatus&& s)
-#if !(defined _MSC_VER) || ((defined _MSC_VER) && (_MSC_VER >= 1900))
-    noexcept
-#endif
-{
+inline IOStatus& IOStatus::operator=(IOStatus&& s) noexcept {
   if (this != &s) {
 #ifdef ROCKSDB_ASSERT_STATUS_CHECKED
     s.checked_ = true;
@@ -228,9 +213,7 @@ inline IOStatus& IOStatus::operator=(IOStatus&& s)
     data_loss_ = s.data_loss_;
     scope_ = s.scope_;
     s.scope_ = kIOErrorScopeFileSystem;
-    delete[] state_;
-    state_ = nullptr;
-    std::swap(state_, s.state_);
+    state_ = std::move(s.state_);
   }
   return *this;
 }
@@ -252,18 +235,10 @@ inline bool IOStatus::operator!=(const IOStatus& rhs) const {
 }
 
 inline IOStatus status_to_io_status(Status&& status) {
-  if (status.ok()) {
-    // Fast path
-    return IOStatus::OK();
-  } else {
-    const char* state = status.getState();
-    if (state) {
-      return IOStatus(status.code(), status.subcode(),
-                      Slice(state, strlen(status.getState()) + 1), Slice());
-    } else {
-      return IOStatus(status.code(), status.subcode());
-    }
-  }
+  IOStatus io_s;
+  Status& s = io_s;
+  s = std::move(status);
+  return io_s;
 }
 
 }  // namespace ROCKSDB_NAMESPACE