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(); \
67 #define KUDU_CHECK_OK_PREPEND(to_call, msg) do { \
68 const ::kudu::Status& _s = (to_call); \
69 KUDU_CHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
74 #define KUDU_CHECK_OK(s) KUDU_CHECK_OK_PREPEND(s, "Bad status")
89 #ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS
90 #define RETURN_NOT_OK KUDU_RETURN_NOT_OK
91 #define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND
92 #define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET
93 #define WARN_NOT_OK KUDU_WARN_NOT_OK
94 #define LOG_AND_RETURN KUDU_LOG_AND_RETURN
95 #define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND
96 #define CHECK_OK KUDU_CHECK_OK
100 #define KUDU_CHECK CHECK
111 ~
Status() {
delete[] state_; }
117 Status(
const Status& s);
123 void operator=(
const Status& s);
125 #if __cplusplus >= 201103L
136 void operator=(Status&& s);
155 int16_t posix_code = -1) {
156 return Status(kNotFound, msg, msg2, posix_code);
158 static Status Corruption(
const Slice& msg,
const Slice& msg2 = Slice(),
159 int16_t posix_code = -1) {
160 return Status(kCorruption, msg, msg2, posix_code);
162 static Status NotSupported(
const Slice& msg,
const Slice& msg2 = Slice(),
163 int16_t posix_code = -1) {
164 return Status(kNotSupported, msg, msg2, posix_code);
166 static Status InvalidArgument(
const Slice& msg,
const Slice& msg2 = Slice(),
167 int16_t posix_code = -1) {
168 return Status(kInvalidArgument, msg, msg2, posix_code);
170 static Status IOError(
const Slice& msg,
const Slice& msg2 = Slice(),
171 int16_t posix_code = -1) {
172 return Status(kIOError, msg, msg2, posix_code);
174 static Status AlreadyPresent(
const Slice& msg,
const Slice& msg2 = Slice(),
175 int16_t posix_code = -1) {
176 return Status(kAlreadyPresent, msg, msg2, posix_code);
178 static Status RuntimeError(
const Slice& msg,
const Slice& msg2 = Slice(),
179 int16_t posix_code = -1) {
180 return Status(kRuntimeError, msg, msg2, posix_code);
182 static Status NetworkError(
const Slice& msg,
const Slice& msg2 = Slice(),
183 int16_t posix_code = -1) {
184 return Status(kNetworkError, msg, msg2, posix_code);
186 static Status IllegalState(
const Slice& msg,
const Slice& msg2 = Slice(),
187 int16_t posix_code = -1) {
188 return Status(kIllegalState, msg, msg2, posix_code);
190 static Status NotAuthorized(
const Slice& msg,
const Slice& msg2 = Slice(),
191 int16_t posix_code = -1) {
192 return Status(kNotAuthorized, msg, msg2, posix_code);
194 static Status Aborted(
const Slice& msg,
const Slice& msg2 = Slice(),
195 int16_t posix_code = -1) {
196 return Status(kAborted, msg, msg2, posix_code);
198 static Status RemoteError(
const Slice& msg,
const Slice& msg2 = Slice(),
199 int16_t posix_code = -1) {
200 return Status(kRemoteError, msg, msg2, posix_code);
202 static Status ServiceUnavailable(
const Slice& msg,
const Slice& msg2 = Slice(),
203 int16_t posix_code = -1) {
204 return Status(kServiceUnavailable, msg, msg2, posix_code);
206 static Status TimedOut(
const Slice& msg,
const Slice& msg2 = Slice(),
207 int16_t posix_code = -1) {
208 return Status(kTimedOut, msg, msg2, posix_code);
210 static Status Uninitialized(
const Slice& msg,
const Slice& msg2 = Slice(),
211 int16_t posix_code = -1) {
212 return Status(kUninitialized, msg, msg2, posix_code);
214 static Status ConfigurationError(
const Slice& msg,
const Slice& msg2 = Slice(),
215 int16_t posix_code = -1) {
216 return Status(kConfigurationError, msg, msg2, posix_code);
218 static Status Incomplete(
const Slice& msg,
const Slice& msg2 = Slice(),
219 int64_t posix_code = -1) {
220 return Status(kIncomplete, msg, msg2, posix_code);
222 static Status EndOfFile(
const Slice& msg,
const Slice& msg2 = Slice(),
223 int64_t posix_code = -1) {
224 return Status(kEndOfFile, msg, msg2, posix_code);
229 bool ok()
const {
return (state_ == NULL); }
287 std::string ToString()
const;
291 std::string CodeAsString()
const;
301 Slice message()
const;
305 int16_t posix_code()
const;
325 size_t memory_footprint_excluding_this()
const;
329 size_t memory_footprint_including_this()
const;
345 kInvalidArgument = 4,
354 kServiceUnavailable = 13,
357 kConfigurationError = 16,
366 COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
369 return (state_ == NULL) ? kOk :
static_cast<Code
>(state_[4]);
372 Status(Code code,
const Slice& msg,
const Slice& msg2, int16_t posix_code);
373 static const char* CopyState(
const char* s);
377 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
382 if (state_ != s.state_) {
384 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
388 #if __cplusplus >= 201103L
394 if (state_ != s.state_) {
404 #endif // KUDU_UTIL_STATUS_H_
Status()
Create an object representing success status.
Definition: status.h:109
bool IsNotAuthorized() const
Definition: status.h:259
A representation of an operation's outcome.
Definition: status.h:106
bool IsIllegalState() const
Definition: status.h:256
bool ok() const
Definition: status.h:229
bool IsTimedOut() const
Definition: status.h:271
bool IsRemoteError() const
Definition: status.h:265
bool IsServiceUnavailable() const
Definition: status.h:268
bool IsAborted() const
Definition: status.h:262
bool IsUninitialized() const
Definition: status.h:274
bool IsRuntimeError() const
Definition: status.h:250
bool IsAlreadyPresent() const
Definition: status.h:247
bool IsIOError() const
Definition: status.h:241
static Status OK()
Definition: status.h:140
A wrapper around externally allocated data.
Definition: slice.h:43
bool IsConfigurationError() const
Definition: status.h:277
bool IsInvalidArgument() const
Definition: status.h:244
bool IsCorruption() const
Definition: status.h:235
void operator=(const Status &s)
Definition: status.h:379
bool IsEndOfFile() const
Definition: status.h:283
bool IsNotSupported() const
Definition: status.h:238
bool IsNetworkError() const
Definition: status.h:253
bool IsIncomplete() const
Definition: status.h:280
bool IsNotFound() const
Definition: status.h:232