13 #ifndef KUDU_UTIL_STATUS_H_ 14 #define KUDU_UTIL_STATUS_H_ 19 #ifdef KUDU_HEADERS_NO_STUBS 20 #include "kudu/gutil/macros.h" 21 #include "kudu/gutil/port.h" 23 #include "kudu/client/stubs.h" 26 #include "kudu/util/kudu_export.h" 27 #include "kudu/util/slice.h" 30 #define KUDU_RETURN_NOT_OK(s) do { \ 31 const ::kudu::Status& _s = (s); \ 32 if (PREDICT_FALSE(!_s.ok())) return _s; \ 37 #define KUDU_RETURN_NOT_OK_PREPEND(s, msg) do { \ 38 const ::kudu::Status& _s = (s); \ 39 if (PREDICT_FALSE(!_s.ok())) return _s.CloneAndPrepend(msg); \ 45 #define KUDU_RETURN_NOT_OK_RET(to_call, to_return) do { \ 46 const ::kudu::Status& s = (to_call); \ 47 if (PREDICT_FALSE(!s.ok())) return (to_return); \ 51 #define KUDU_WARN_NOT_OK(to_call, warning_prefix) do { \ 52 const ::kudu::Status& _s = (to_call); \ 53 if (PREDICT_FALSE(!_s.ok())) { \ 54 KUDU_LOG(WARNING) << (warning_prefix) << ": " << _s.ToString(); \ 59 #define KUDU_LOG_AND_RETURN(level, status) do { \ 60 const ::kudu::Status& _s = (status); \ 61 KUDU_LOG(level) << _s.ToString(); \ 66 #define KUDU_RETURN_NOT_OK_LOG(s, level, msg) do { \ 67 const ::kudu::Status& _s = (s); \ 68 if (PREDICT_FALSE(!_s.ok())) { \ 69 KUDU_LOG(level) << "Status: " << _s.ToString() << " " << (msg); \ 76 #define KUDU_CHECK_OK_PREPEND(to_call, msg) do { \ 77 const ::kudu::Status& _s = (to_call); \ 78 KUDU_CHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \ 83 #define KUDU_CHECK_OK(s) KUDU_CHECK_OK_PREPEND(s, "Bad status") 87 #define KUDU_DCHECK_OK_PREPEND(to_call, msg) do { \ 88 const ::kudu::Status& _s = (to_call); \ 89 KUDU_DCHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \ 94 #define KUDU_DCHECK_OK(s) KUDU_DCHECK_OK_PREPEND(s, "Bad status") 109 #ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS 110 #define RETURN_NOT_OK KUDU_RETURN_NOT_OK 111 #define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND 112 #define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET 113 #define WARN_NOT_OK KUDU_WARN_NOT_OK 114 #define LOG_AND_RETURN KUDU_LOG_AND_RETURN 115 #define RETURN_NOT_OK_LOG KUDU_RETURN_NOT_OK_LOG 116 #define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND 117 #define CHECK_OK KUDU_CHECK_OK 118 #define DCHECK_OK_PREPEND KUDU_DCHECK_OK_PREPEND 119 #define DCHECK_OK KUDU_DCHECK_OK 123 #define KUDU_CHECK CHECK 124 #define KUDU_DCHECK DCHECK 135 ~
Status() {
delete[] state_; }
150 #if __cplusplus >= 201103L 181 int16_t posix_code = -1) {
182 return Status(kNotFound, msg, msg2, posix_code);
185 int16_t posix_code = -1) {
186 return Status(kCorruption, msg, msg2, posix_code);
189 int16_t posix_code = -1) {
190 return Status(kNotSupported, msg, msg2, posix_code);
193 int16_t posix_code = -1) {
194 return Status(kInvalidArgument, msg, msg2, posix_code);
197 int16_t posix_code = -1) {
198 return Status(kIOError, msg, msg2, posix_code);
201 int16_t posix_code = -1) {
202 return Status(kAlreadyPresent, msg, msg2, posix_code);
205 int16_t posix_code = -1) {
206 return Status(kRuntimeError, msg, msg2, posix_code);
209 int16_t posix_code = -1) {
210 return Status(kNetworkError, msg, msg2, posix_code);
213 int16_t posix_code = -1) {
214 return Status(kIllegalState, msg, msg2, posix_code);
217 int16_t posix_code = -1) {
218 return Status(kNotAuthorized, msg, msg2, posix_code);
221 int16_t posix_code = -1) {
222 return Status(kAborted, msg, msg2, posix_code);
225 int16_t posix_code = -1) {
226 return Status(kRemoteError, msg, msg2, posix_code);
229 int16_t posix_code = -1) {
230 return Status(kServiceUnavailable, msg, msg2, posix_code);
233 int16_t posix_code = -1) {
234 return Status(kTimedOut, msg, msg2, posix_code);
237 int16_t posix_code = -1) {
238 return Status(kUninitialized, msg, msg2, posix_code);
241 int16_t posix_code = -1) {
242 return Status(kConfigurationError, msg, msg2, posix_code);
245 int64_t posix_code = -1) {
246 return Status(kIncomplete, msg, msg2, posix_code);
249 int64_t posix_code = -1) {
250 return Status(kEndOfFile, msg, msg2, posix_code);
255 bool ok()
const {
return (state_ == NULL); }
313 std::string ToString()
const;
317 std::string CodeAsString()
const;
327 Slice message()
const;
331 int16_t posix_code()
const;
351 size_t memory_footprint_excluding_this()
const;
355 size_t memory_footprint_including_this()
const;
371 kInvalidArgument = 4,
380 kServiceUnavailable = 13,
383 kConfigurationError = 16,
392 COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
395 return (state_ == NULL) ? kOk :
static_cast<Code
>(state_[4]);
399 static const char* CopyState(
const char* s);
403 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
409 if (state_ != s.state_) {
411 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
416 #if __cplusplus >= 201103L 422 if (state_ != s.state_) {
433 #endif // KUDU_UTIL_STATUS_H_ Status()
Create an object representing success status.
Definition: status.h:133
bool IsNotAuthorized() const
Definition: status.h:285
A representation of an operation's outcome.
Definition: status.h:130
bool IsIllegalState() const
Definition: status.h:282
Definition: callbacks.h:28
bool ok() const
Definition: status.h:255
bool IsTimedOut() const
Definition: status.h:297
bool IsRemoteError() const
Definition: status.h:291
bool IsServiceUnavailable() const
Definition: status.h:294
bool IsAborted() const
Definition: status.h:288
bool IsUninitialized() const
Definition: status.h:300
bool IsRuntimeError() const
Definition: status.h:276
bool IsAlreadyPresent() const
Definition: status.h:273
bool IsIOError() const
Definition: status.h:267
static Status OK()
Definition: status.h:166
A wrapper around externally allocated data.
Definition: slice.h:43
Status & operator=(const Status &s)
Definition: status.h:406
bool IsConfigurationError() const
Definition: status.h:303
bool IsInvalidArgument() const
Definition: status.h:270
bool IsCorruption() const
Definition: status.h:261
bool IsEndOfFile() const
Definition: status.h:309
bool IsNotSupported() const
Definition: status.h:264
bool IsNetworkError() const
Definition: status.h:279
bool IsIncomplete() const
Definition: status.h:306
bool IsNotFound() const
Definition: status.h:258