13#ifndef KUDU_UTIL_STATUS_H_
14#define KUDU_UTIL_STATUS_H_
25#ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS
26#include <glog/logging.h>
29#ifdef KUDU_HEADERS_NO_STUBS
30#include "kudu/gutil/macros.h"
31#include "kudu/gutil/port.h"
33#include "kudu/client/stubs.h"
36#include "kudu/util/kudu_export.h"
37#include "kudu/util/slice.h"
40#define KUDU_RETURN_NOT_OK(s) do { \
41 const ::kudu::Status& _s = (s); \
42 if (PREDICT_FALSE(!_s.ok())) return _s; \
47#define KUDU_RETURN_NOT_OK_PREPEND(s, msg) do { \
48 const ::kudu::Status& _s = (s); \
49 if (PREDICT_FALSE(!_s.ok())) return _s.CloneAndPrepend(msg); \
55#define KUDU_RETURN_NOT_OK_RET(to_call, to_return) do { \
56 const ::kudu::Status& s = (to_call); \
57 if (PREDICT_FALSE(!s.ok())) return (to_return); \
61#define KUDU_RETURN_NOT_OK_EVAL(s, on_error) do { \
62 const ::kudu::Status& _s = (s); \
63 if (PREDICT_FALSE(!_s.ok())) { \
70#define KUDU_WARN_NOT_OK(to_call, warning_prefix) do { \
71 const ::kudu::Status& _s = (to_call); \
72 if (PREDICT_FALSE(!_s.ok())) { \
73 KUDU_LOG(WARNING) << (warning_prefix) << ": " << _s.ToString(); \
78#define KUDU_LOG_AND_RETURN(level, status) do { \
79 const ::kudu::Status& _s = (status); \
80 KUDU_LOG(level) << _s.ToString(); \
85#define KUDU_RETURN_NOT_OK_LOG(s, level, msg) do { \
86 const ::kudu::Status& _s = (s); \
87 if (PREDICT_FALSE(!_s.ok())) { \
88 KUDU_LOG(level) << "Status: " << _s.ToString() << " " << (msg); \
95#define KUDU_CHECK_OK_PREPEND(to_call, msg) do { \
96 const ::kudu::Status& _s = (to_call); \
97 KUDU_CHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
102#define KUDU_CHECK_OK(s) KUDU_CHECK_OK_PREPEND(s, "Bad status")
106#define KUDU_DCHECK_OK_PREPEND(to_call, msg) do { \
107 const ::kudu::Status& _s = (to_call); \
108 KUDU_DCHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
113#define KUDU_DCHECK_OK(s) KUDU_DCHECK_OK_PREPEND(s, "Bad status")
119#define KUDU_RETURN_MAIN_NOT_OK(to_call, msg, ret_code) do { \
120 DCHECK_NE(0, (ret_code)) << "non-OK return code should not be 0"; \
121 const ::kudu::Status& _s = (to_call); \
123 const ::kudu::Status& _ss = _s.CloneAndPrepend((msg)); \
124 LOG(ERROR) << _ss.ToString(); \
130#if __cplusplus >= 201703L
138 #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 13)
147 #define KUDU_ATTR_NODISCARD [[nodiscard]]
149 #define KUDU_ATTR_NODISCARD
152 #define KUDU_ATTR_NODISCARD
168#ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS
169#define RETURN_NOT_OK KUDU_RETURN_NOT_OK
170#define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND
171#define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET
172#define RETURN_NOT_OK_EVAL KUDU_RETURN_NOT_OK_EVAL
173#define WARN_NOT_OK KUDU_WARN_NOT_OK
174#define LOG_AND_RETURN KUDU_LOG_AND_RETURN
175#define RETURN_NOT_OK_LOG KUDU_RETURN_NOT_OK_LOG
176#define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND
177#define CHECK_OK KUDU_CHECK_OK
178#define DCHECK_OK_PREPEND KUDU_DCHECK_OK_PREPEND
179#define DCHECK_OK KUDU_DCHECK_OK
180#define RETURN_MAIN_NOT_OK KUDU_RETURN_MAIN_NOT_OK
184#define KUDU_CHECK CHECK
185#define KUDU_DCHECK DCHECK
191class KUDU_EXPORT KUDU_ATTR_NODISCARD
Status {
211#if __cplusplus >= 201103L
347 bool ok()
const {
return (state_ == NULL); }
482 kInvalidArgument = 4,
491 kServiceUnavailable = 13,
494 kConfigurationError = 16,
506 COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
509 return (state_ == NULL) ? kOk :
static_cast<Code
>(state_[4]);
512 Status(Code code,
const Slice& msg,
const Slice& msg2, int16_t posix_code);
513 static const char* CopyState(
const char* s);
517 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
523 if (state_ != s.state_) {
525 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
530#if __cplusplus >= 201103L
536 if (state_ != s.state_) {
A representation of an operation's outcome.
Definition status.h:191
A wrapper around externally allocated data.
Definition slice.h:51
A representation of an operation's outcome.
Definition status.h:191
bool IsInvalidArgument() const
Definition status.h:362
static Status TimedOut(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:320
bool IsRemoteError() const
Definition status.h:383
size_t memory_footprint_including_this() const
bool IsEndOfFile() const
Definition status.h:401
static Status Immutable(const Slice &msg, const Slice &msg2=Slice(), int64_t posix_code=-1)
Definition status.h:340
bool IsTimedOut() const
Definition status.h:389
bool IsUninitialized() const
Definition status.h:392
static Status RuntimeError(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:292
static Status IOError(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:284
int16_t posix_code() const
bool IsAlreadyPresent() const
Definition status.h:365
bool IsCorruption() const
Definition status.h:353
size_t memory_footprint_excluding_this() const
static Status ServiceUnavailable(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:316
static Status Corruption(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:272
bool IsIOError() const
Definition status.h:359
static Status IllegalState(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:300
bool IsAborted() const
Definition status.h:380
static Status Aborted(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:308
std::string CodeAsString() const
static Status NotSupported(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:276
Status CloneAndAppend(const Slice &msg) const
bool IsNotFound() const
Definition status.h:350
bool IsServiceUnavailable() const
Definition status.h:386
bool IsConfigurationError() const
Definition status.h:395
static Status AlreadyPresent(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:288
Status & operator=(const Status &s)
Definition status.h:520
bool IsDiskFailure() const
Definition status.h:407
static Status NotFound(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:268
bool IsNotSupported() const
Definition status.h:356
static Status InvalidArgument(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:280
static Status Incomplete(const Slice &msg, const Slice &msg2=Slice(), int64_t posix_code=-1)
Definition status.h:332
Status CloneAndPrepend(const Slice &msg) const
static Status NetworkError(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:296
static Status Uninitialized(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:324
bool IsIncomplete() const
Definition status.h:398
bool IsNotAuthorized() const
Definition status.h:377
static Status NotAuthorized(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:304
Status()
Create an object representing success status.
Definition status.h:194
bool IsIllegalState() const
Definition status.h:374
bool IsNetworkError() const
Definition status.h:371
bool IsImmutable() const
Definition status.h:404
static Status OK()
Definition status.h:256
bool ok() const
Definition status.h:347
bool IsRuntimeError() const
Definition status.h:368
std::string ToString() const
static Status EndOfFile(const Slice &msg, const Slice &msg2=Slice(), int64_t posix_code=-1)
Definition status.h:336
static Status ConfigurationError(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:328
static Status RemoteError(const Slice &msg, const Slice &msg2=Slice(), int16_t posix_code=-1)
Definition status.h:312