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_WARN_NOT_OK(to_call, warning_prefix) do { \
57 const ::kudu::Status& _s = (to_call); \
58 if (PREDICT_FALSE(!_s.ok())) { \
59 KUDU_LOG(WARNING) << (warning_prefix) << ": " << _s.ToString(); \
64 #define KUDU_LOG_AND_RETURN(level, status) do { \
65 const ::kudu::Status& _s = (status); \
66 KUDU_LOG(level) << _s.ToString(); \
71 #define KUDU_RETURN_NOT_OK_LOG(s, level, msg) do { \
72 const ::kudu::Status& _s = (s); \
73 if (PREDICT_FALSE(!_s.ok())) { \
74 KUDU_LOG(level) << "Status: " << _s.ToString() << " " << (msg); \
81 #define KUDU_CHECK_OK_PREPEND(to_call, msg) do { \
82 const ::kudu::Status& _s = (to_call); \
83 KUDU_CHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
88 #define KUDU_CHECK_OK(s) KUDU_CHECK_OK_PREPEND(s, "Bad status")
92 #define KUDU_DCHECK_OK_PREPEND(to_call, msg) do { \
93 const ::kudu::Status& _s = (to_call); \
94 KUDU_DCHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
99 #define KUDU_DCHECK_OK(s) KUDU_DCHECK_OK_PREPEND(s, "Bad status")
114 #ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS
115 #define RETURN_NOT_OK KUDU_RETURN_NOT_OK
116 #define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND
117 #define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET
118 #define WARN_NOT_OK KUDU_WARN_NOT_OK
119 #define LOG_AND_RETURN KUDU_LOG_AND_RETURN
120 #define RETURN_NOT_OK_LOG KUDU_RETURN_NOT_OK_LOG
121 #define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND
122 #define CHECK_OK KUDU_CHECK_OK
123 #define DCHECK_OK_PREPEND KUDU_DCHECK_OK_PREPEND
124 #define DCHECK_OK KUDU_DCHECK_OK
128 #define KUDU_CHECK CHECK
129 #define KUDU_DCHECK DCHECK
140 ~
Status() {
delete[] state_; }
146 Status(
const Status& s);
153 Status& operator=(
const Status& s);
155 #if __cplusplus >= 201103L
167 Status& operator=(Status&& s);
191 Status AndThen(F op) {
215 int16_t posix_code = -1) {
216 return Status(kNotFound, msg, msg2, posix_code);
218 static Status Corruption(
const Slice& msg,
const Slice& msg2 = Slice(),
219 int16_t posix_code = -1) {
220 return Status(kCorruption, msg, msg2, posix_code);
222 static Status NotSupported(
const Slice& msg,
const Slice& msg2 = Slice(),
223 int16_t posix_code = -1) {
224 return Status(kNotSupported, msg, msg2, posix_code);
226 static Status InvalidArgument(
const Slice& msg,
const Slice& msg2 = Slice(),
227 int16_t posix_code = -1) {
228 return Status(kInvalidArgument, msg, msg2, posix_code);
230 static Status IOError(
const Slice& msg,
const Slice& msg2 = Slice(),
231 int16_t posix_code = -1) {
232 return Status(kIOError, msg, msg2, posix_code);
234 static Status AlreadyPresent(
const Slice& msg,
const Slice& msg2 = Slice(),
235 int16_t posix_code = -1) {
236 return Status(kAlreadyPresent, msg, msg2, posix_code);
238 static Status RuntimeError(
const Slice& msg,
const Slice& msg2 = Slice(),
239 int16_t posix_code = -1) {
240 return Status(kRuntimeError, msg, msg2, posix_code);
242 static Status NetworkError(
const Slice& msg,
const Slice& msg2 = Slice(),
243 int16_t posix_code = -1) {
244 return Status(kNetworkError, msg, msg2, posix_code);
246 static Status IllegalState(
const Slice& msg,
const Slice& msg2 = Slice(),
247 int16_t posix_code = -1) {
248 return Status(kIllegalState, msg, msg2, posix_code);
250 static Status NotAuthorized(
const Slice& msg,
const Slice& msg2 = Slice(),
251 int16_t posix_code = -1) {
252 return Status(kNotAuthorized, msg, msg2, posix_code);
254 static Status Aborted(
const Slice& msg,
const Slice& msg2 = Slice(),
255 int16_t posix_code = -1) {
256 return Status(kAborted, msg, msg2, posix_code);
258 static Status RemoteError(
const Slice& msg,
const Slice& msg2 = Slice(),
259 int16_t posix_code = -1) {
260 return Status(kRemoteError, msg, msg2, posix_code);
262 static Status ServiceUnavailable(
const Slice& msg,
const Slice& msg2 = Slice(),
263 int16_t posix_code = -1) {
264 return Status(kServiceUnavailable, msg, msg2, posix_code);
266 static Status TimedOut(
const Slice& msg,
const Slice& msg2 = Slice(),
267 int16_t posix_code = -1) {
268 return Status(kTimedOut, msg, msg2, posix_code);
270 static Status Uninitialized(
const Slice& msg,
const Slice& msg2 = Slice(),
271 int16_t posix_code = -1) {
272 return Status(kUninitialized, msg, msg2, posix_code);
274 static Status ConfigurationError(
const Slice& msg,
const Slice& msg2 = Slice(),
275 int16_t posix_code = -1) {
276 return Status(kConfigurationError, msg, msg2, posix_code);
278 static Status Incomplete(
const Slice& msg,
const Slice& msg2 = Slice(),
279 int64_t posix_code = -1) {
280 return Status(kIncomplete, msg, msg2, posix_code);
282 static Status EndOfFile(
const Slice& msg,
const Slice& msg2 = Slice(),
283 int64_t posix_code = -1) {
284 return Status(kEndOfFile, msg, msg2, posix_code);
289 bool ok()
const {
return (state_ == NULL); }
347 switch (posix_code()) {
359 std::string ToString()
const;
363 std::string CodeAsString()
const;
373 Slice message()
const;
377 int16_t posix_code()
const;
401 size_t memory_footprint_excluding_this()
const;
405 size_t memory_footprint_including_this()
const;
421 kInvalidArgument = 4,
430 kServiceUnavailable = 13,
433 kConfigurationError = 16,
442 COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
445 return (state_ == NULL) ? kOk :
static_cast<Code
>(state_[4]);
448 Status(Code code,
const Slice& msg,
const Slice& msg2, int16_t posix_code);
449 static const char* CopyState(
const char* s);
453 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
459 if (state_ != s.state_) {
461 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
466 #if __cplusplus >= 201103L
472 if (state_ != s.state_) {
483 #endif // KUDU_UTIL_STATUS_H_
Status()
Create an object representing success status.
Definition: status.h:138
bool IsNotAuthorized() const
Definition: status.h:319
A representation of an operation's outcome.
Definition: status.h:135
bool IsIllegalState() const
Definition: status.h:316
bool ok() const
Definition: status.h:289
bool IsTimedOut() const
Definition: status.h:331
bool IsRemoteError() const
Definition: status.h:325
bool IsDiskFailure() const
Definition: status.h:346
bool IsServiceUnavailable() const
Definition: status.h:328
bool IsAborted() const
Definition: status.h:322
bool IsUninitialized() const
Definition: status.h:334
bool IsRuntimeError() const
Definition: status.h:310
bool IsAlreadyPresent() const
Definition: status.h:307
bool IsIOError() const
Definition: status.h:301
static Status OK()
Definition: status.h:200
A wrapper around externally allocated data.
Definition: slice.h:47
Status & operator=(const Status &s)
Definition: status.h:456
bool IsConfigurationError() const
Definition: status.h:337
bool IsInvalidArgument() const
Definition: status.h:304
bool IsCorruption() const
Definition: status.h:295
bool IsEndOfFile() const
Definition: status.h:343
bool IsNotSupported() const
Definition: status.h:298
bool IsNetworkError() const
Definition: status.h:313
bool IsIncomplete() const
Definition: status.h:340
bool IsNotFound() const
Definition: status.h:292