13 #ifndef KUDU_UTIL_STATUS_H_ 
   14 #define KUDU_UTIL_STATUS_H_ 
   24 #ifdef KUDU_HEADERS_NO_STUBS 
   25 #include "kudu/gutil/macros.h" 
   26 #include "kudu/gutil/port.h" 
   28 #include "kudu/client/stubs.h" 
   31 #include "kudu/util/kudu_export.h" 
   32 #include "kudu/util/slice.h" 
   35 #define KUDU_RETURN_NOT_OK(s) do { \ 
   36     const ::kudu::Status& _s = (s);             \ 
   37     if (PREDICT_FALSE(!_s.ok())) return _s;     \ 
   42 #define KUDU_RETURN_NOT_OK_PREPEND(s, msg) do { \ 
   43     const ::kudu::Status& _s = (s);                              \ 
   44     if (PREDICT_FALSE(!_s.ok())) return _s.CloneAndPrepend(msg); \ 
   50 #define KUDU_RETURN_NOT_OK_RET(to_call, to_return) do { \ 
   51     const ::kudu::Status& s = (to_call);                \ 
   52     if (PREDICT_FALSE(!s.ok())) return (to_return);  \ 
   56 #define KUDU_RETURN_NOT_OK_EVAL(s, on_error) do { \ 
   57     const ::kudu::Status& _s = (s); \ 
   58     if (PREDICT_FALSE(!_s.ok())) { \ 
   65 #define KUDU_WARN_NOT_OK(to_call, warning_prefix) do { \ 
   66     const ::kudu::Status& _s = (to_call);              \ 
   67     if (PREDICT_FALSE(!_s.ok())) { \ 
   68       KUDU_LOG(WARNING) << (warning_prefix) << ": " << _s.ToString();  \ 
   73 #define KUDU_LOG_AND_RETURN(level, status) do { \ 
   74     const ::kudu::Status& _s = (status);        \ 
   75     KUDU_LOG(level) << _s.ToString(); \ 
   80 #define KUDU_RETURN_NOT_OK_LOG(s, level, msg) do { \ 
   81     const ::kudu::Status& _s = (s);             \ 
   82     if (PREDICT_FALSE(!_s.ok())) { \ 
   83       KUDU_LOG(level) << "Status: " << _s.ToString() << " " << (msg); \ 
   90 #define KUDU_CHECK_OK_PREPEND(to_call, msg) do { \ 
   91     const ::kudu::Status& _s = (to_call);                   \ 
   92     KUDU_CHECK(_s.ok()) << (msg) << ": " << _s.ToString();  \ 
   97 #define KUDU_CHECK_OK(s) KUDU_CHECK_OK_PREPEND(s, "Bad status") 
  101 #define KUDU_DCHECK_OK_PREPEND(to_call, msg) do { \ 
  102     const ::kudu::Status& _s = (to_call);                   \ 
  103     KUDU_DCHECK(_s.ok()) << (msg) << ": " << _s.ToString();  \ 
  108 #define KUDU_DCHECK_OK(s) KUDU_DCHECK_OK_PREPEND(s, "Bad status") 
  123 #ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS 
  124 #define RETURN_NOT_OK         KUDU_RETURN_NOT_OK 
  125 #define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND 
  126 #define RETURN_NOT_OK_RET     KUDU_RETURN_NOT_OK_RET 
  127 #define RETURN_NOT_OK_EVAL    KUDU_RETURN_NOT_OK_EVAL 
  128 #define WARN_NOT_OK           KUDU_WARN_NOT_OK 
  129 #define LOG_AND_RETURN        KUDU_LOG_AND_RETURN 
  130 #define RETURN_NOT_OK_LOG     KUDU_RETURN_NOT_OK_LOG 
  131 #define CHECK_OK_PREPEND      KUDU_CHECK_OK_PREPEND 
  132 #define CHECK_OK              KUDU_CHECK_OK 
  133 #define DCHECK_OK_PREPEND     KUDU_DCHECK_OK_PREPEND 
  134 #define DCHECK_OK             KUDU_DCHECK_OK 
  138 #define KUDU_CHECK            CHECK 
  139 #define KUDU_DCHECK           DCHECK 
  150   ~
Status() { 
delete[] state_; }
 
  156   Status(
const Status& s);
 
  163   Status& operator=(
const Status& s);
 
  165 #if __cplusplus >= 201103L 
  166   Status(Status&& s) noexcept;
 
  177   Status& operator=(Status&& s) noexcept;
 
  201   Status AndThen(F op) {
 
  225                          int16_t posix_code = -1) {
 
  226     return Status(kNotFound, msg, msg2, posix_code);
 
  228   static Status Corruption(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  229                          int16_t posix_code = -1) {
 
  230     return Status(kCorruption, msg, msg2, posix_code);
 
  232   static Status NotSupported(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  233                          int16_t posix_code = -1) {
 
  234     return Status(kNotSupported, msg, msg2, posix_code);
 
  236   static Status InvalidArgument(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  237                          int16_t posix_code = -1) {
 
  238     return Status(kInvalidArgument, msg, msg2, posix_code);
 
  240   static Status IOError(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  241                          int16_t posix_code = -1) {
 
  242     return Status(kIOError, msg, msg2, posix_code);
 
  244   static Status AlreadyPresent(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  245                          int16_t posix_code = -1) {
 
  246     return Status(kAlreadyPresent, msg, msg2, posix_code);
 
  248   static Status RuntimeError(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  249                          int16_t posix_code = -1) {
 
  250     return Status(kRuntimeError, msg, msg2, posix_code);
 
  252   static Status NetworkError(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  253                          int16_t posix_code = -1) {
 
  254     return Status(kNetworkError, msg, msg2, posix_code);
 
  256   static Status IllegalState(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  257                          int16_t posix_code = -1) {
 
  258     return Status(kIllegalState, msg, msg2, posix_code);
 
  260   static Status NotAuthorized(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  261                          int16_t posix_code = -1) {
 
  262     return Status(kNotAuthorized, msg, msg2, posix_code);
 
  264   static Status Aborted(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  265                          int16_t posix_code = -1) {
 
  266     return Status(kAborted, msg, msg2, posix_code);
 
  268   static Status RemoteError(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  269                          int16_t posix_code = -1) {
 
  270     return Status(kRemoteError, msg, msg2, posix_code);
 
  272   static Status ServiceUnavailable(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  273                          int16_t posix_code = -1) {
 
  274     return Status(kServiceUnavailable, msg, msg2, posix_code);
 
  276   static Status TimedOut(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  277                          int16_t posix_code = -1) {
 
  278     return Status(kTimedOut, msg, msg2, posix_code);
 
  280   static Status Uninitialized(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  281                               int16_t posix_code = -1) {
 
  282     return Status(kUninitialized, msg, msg2, posix_code);
 
  284   static Status ConfigurationError(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  285                                    int16_t posix_code = -1) {
 
  286     return Status(kConfigurationError, msg, msg2, posix_code);
 
  288   static Status Incomplete(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  289                            int64_t posix_code = -1) {
 
  290     return Status(kIncomplete, msg, msg2, posix_code);
 
  292   static Status EndOfFile(
const Slice& msg, 
const Slice& msg2 = Slice(),
 
  293                           int64_t posix_code = -1) {
 
  294     return Status(kEndOfFile, msg, msg2, posix_code);
 
  299   bool ok()
 const { 
return (state_ == NULL); }
 
  357     switch (posix_code()) {
 
  369   std::string ToString() 
const;
 
  373   std::string CodeAsString() 
const;
 
  383   Slice message() 
const;
 
  387   int16_t posix_code() 
const;
 
  411   size_t memory_footprint_excluding_this() 
const;
 
  415   size_t memory_footprint_including_this() 
const;
 
  431     kInvalidArgument = 4,
 
  440     kServiceUnavailable = 13,
 
  443     kConfigurationError = 16,
 
  452   COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
 
  455     return (state_ == NULL) ? kOk : 
static_cast<Code
>(state_[4]);
 
  458   Status(Code code, 
const Slice& msg, 
const Slice& msg2, int16_t posix_code);
 
  459   static const char* CopyState(
const char* s);
 
  463   state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
 
  469   if (state_ != s.state_) {
 
  471     state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
 
  476 #if __cplusplus >= 201103L 
  482   if (state_ != s.state_) {
 
  493 #endif  // KUDU_UTIL_STATUS_H_ 
Status()
Create an object representing success status. 
Definition: status.h:148
 
bool IsNotAuthorized() const 
Definition: status.h:329
 
A representation of an operation's outcome. 
Definition: status.h:145
 
bool IsIllegalState() const 
Definition: status.h:326
 
bool ok() const 
Definition: status.h:299
 
bool IsTimedOut() const 
Definition: status.h:341
 
bool IsRemoteError() const 
Definition: status.h:335
 
bool IsDiskFailure() const 
Definition: status.h:356
 
bool IsServiceUnavailable() const 
Definition: status.h:338
 
bool IsAborted() const 
Definition: status.h:332
 
bool IsUninitialized() const 
Definition: status.h:344
 
bool IsRuntimeError() const 
Definition: status.h:320
 
bool IsAlreadyPresent() const 
Definition: status.h:317
 
bool IsIOError() const 
Definition: status.h:311
 
static Status OK()
Definition: status.h:210
 
A wrapper around externally allocated data. 
Definition: slice.h:47
 
Status & operator=(const Status &s)
Definition: status.h:466
 
bool IsConfigurationError() const 
Definition: status.h:347
 
bool IsInvalidArgument() const 
Definition: status.h:314
 
bool IsCorruption() const 
Definition: status.h:305
 
bool IsEndOfFile() const 
Definition: status.h:353
 
bool IsNotSupported() const 
Definition: status.h:308
 
bool IsNetworkError() const 
Definition: status.h:323
 
bool IsIncomplete() const 
Definition: status.h:350
 
bool IsNotFound() const 
Definition: status.h:302