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(); \ 142 #ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS 143 #define RETURN_NOT_OK KUDU_RETURN_NOT_OK 144 #define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND 145 #define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET 146 #define RETURN_NOT_OK_EVAL KUDU_RETURN_NOT_OK_EVAL 147 #define WARN_NOT_OK KUDU_WARN_NOT_OK 148 #define LOG_AND_RETURN KUDU_LOG_AND_RETURN 149 #define RETURN_NOT_OK_LOG KUDU_RETURN_NOT_OK_LOG 150 #define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND 151 #define CHECK_OK KUDU_CHECK_OK 152 #define DCHECK_OK_PREPEND KUDU_DCHECK_OK_PREPEND 153 #define DCHECK_OK KUDU_DCHECK_OK 154 #define RETURN_MAIN_NOT_OK KUDU_RETURN_MAIN_NOT_OK 158 #define KUDU_CHECK CHECK 159 #define KUDU_DCHECK DCHECK 170 ~
Status() {
delete[] state_; }
185 #if __cplusplus >= 201103L 245 int16_t posix_code = -1) {
246 return Status(kNotFound, msg, msg2, posix_code);
249 int16_t posix_code = -1) {
250 return Status(kCorruption, msg, msg2, posix_code);
253 int16_t posix_code = -1) {
254 return Status(kNotSupported, msg, msg2, posix_code);
257 int16_t posix_code = -1) {
258 return Status(kInvalidArgument, msg, msg2, posix_code);
261 int16_t posix_code = -1) {
262 return Status(kIOError, msg, msg2, posix_code);
265 int16_t posix_code = -1) {
266 return Status(kAlreadyPresent, msg, msg2, posix_code);
269 int16_t posix_code = -1) {
270 return Status(kRuntimeError, msg, msg2, posix_code);
273 int16_t posix_code = -1) {
274 return Status(kNetworkError, msg, msg2, posix_code);
277 int16_t posix_code = -1) {
278 return Status(kIllegalState, msg, msg2, posix_code);
281 int16_t posix_code = -1) {
282 return Status(kNotAuthorized, msg, msg2, posix_code);
285 int16_t posix_code = -1) {
286 return Status(kAborted, msg, msg2, posix_code);
289 int16_t posix_code = -1) {
290 return Status(kRemoteError, msg, msg2, posix_code);
293 int16_t posix_code = -1) {
294 return Status(kServiceUnavailable, msg, msg2, posix_code);
297 int16_t posix_code = -1) {
298 return Status(kTimedOut, msg, msg2, posix_code);
301 int16_t posix_code = -1) {
302 return Status(kUninitialized, msg, msg2, posix_code);
305 int16_t posix_code = -1) {
306 return Status(kConfigurationError, msg, msg2, posix_code);
309 int64_t posix_code = -1) {
310 return Status(kIncomplete, msg, msg2, posix_code);
313 int64_t posix_code = -1) {
314 return Status(kEndOfFile, msg, msg2, posix_code);
319 bool ok()
const {
return (state_ == NULL); }
377 switch (posix_code()) {
389 std::string ToString()
const;
393 std::string CodeAsString()
const;
403 Slice message()
const;
407 int16_t posix_code()
const;
431 size_t memory_footprint_excluding_this()
const;
435 size_t memory_footprint_including_this()
const;
451 kInvalidArgument = 4,
460 kServiceUnavailable = 13,
463 kConfigurationError = 16,
472 COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
475 return (state_ == NULL) ? kOk :
static_cast<Code
>(state_[4]);
479 static const char* CopyState(
const char* s);
483 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
489 if (state_ != s.state_) {
491 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
496 #if __cplusplus >= 201103L 502 if (state_ != s.state_) {
513 #endif // KUDU_UTIL_STATUS_H_ Status()
Create an object representing success status.
Definition: status.h:168
bool IsNotAuthorized() const
Definition: status.h:349
A representation of an operation's outcome.
Definition: status.h:165
bool IsIllegalState() const
Definition: status.h:346
Definition: callbacks.h:28
bool ok() const
Definition: status.h:319
bool IsTimedOut() const
Definition: status.h:361
bool IsRemoteError() const
Definition: status.h:355
bool IsDiskFailure() const
Definition: status.h:376
bool IsServiceUnavailable() const
Definition: status.h:358
bool IsAborted() const
Definition: status.h:352
bool IsUninitialized() const
Definition: status.h:364
bool IsRuntimeError() const
Definition: status.h:340
bool IsAlreadyPresent() const
Definition: status.h:337
bool IsIOError() const
Definition: status.h:331
static Status OK()
Definition: status.h:230
A wrapper around externally allocated data.
Definition: slice.h:51
Status & operator=(const Status &s)
Definition: status.h:486
bool IsConfigurationError() const
Definition: status.h:367
bool IsInvalidArgument() const
Definition: status.h:334
bool IsCorruption() const
Definition: status.h:325
bool IsEndOfFile() const
Definition: status.h:373
bool IsNotSupported() const
Definition: status.h:328
bool IsNetworkError() const
Definition: status.h:343
bool IsIncomplete() const
Definition: status.h:370
bool IsNotFound() const
Definition: status.h:322