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")
98 #ifdef KUDU_HEADERS_USE_SHORT_STATUS_MACROS
99 #define RETURN_NOT_OK KUDU_RETURN_NOT_OK
100 #define RETURN_NOT_OK_PREPEND KUDU_RETURN_NOT_OK_PREPEND
101 #define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET
102 #define WARN_NOT_OK KUDU_WARN_NOT_OK
103 #define LOG_AND_RETURN KUDU_LOG_AND_RETURN
104 #define RETURN_NOT_OK_LOG KUDU_RETURN_NOT_OK_LOG
105 #define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND
106 #define CHECK_OK KUDU_CHECK_OK
110 #define KUDU_CHECK CHECK
121 ~
Status() {
delete[] state_; }
127 Status(
const Status& s);
133 void operator=(
const Status& s);
135 #if __cplusplus >= 201103L
146 void operator=(Status&& s);
165 int16_t posix_code = -1) {
166 return Status(kNotFound, msg, msg2, posix_code);
168 static Status Corruption(
const Slice& msg,
const Slice& msg2 = Slice(),
169 int16_t posix_code = -1) {
170 return Status(kCorruption, msg, msg2, posix_code);
172 static Status NotSupported(
const Slice& msg,
const Slice& msg2 = Slice(),
173 int16_t posix_code = -1) {
174 return Status(kNotSupported, msg, msg2, posix_code);
176 static Status InvalidArgument(
const Slice& msg,
const Slice& msg2 = Slice(),
177 int16_t posix_code = -1) {
178 return Status(kInvalidArgument, msg, msg2, posix_code);
180 static Status IOError(
const Slice& msg,
const Slice& msg2 = Slice(),
181 int16_t posix_code = -1) {
182 return Status(kIOError, msg, msg2, posix_code);
184 static Status AlreadyPresent(
const Slice& msg,
const Slice& msg2 = Slice(),
185 int16_t posix_code = -1) {
186 return Status(kAlreadyPresent, msg, msg2, posix_code);
188 static Status RuntimeError(
const Slice& msg,
const Slice& msg2 = Slice(),
189 int16_t posix_code = -1) {
190 return Status(kRuntimeError, msg, msg2, posix_code);
192 static Status NetworkError(
const Slice& msg,
const Slice& msg2 = Slice(),
193 int16_t posix_code = -1) {
194 return Status(kNetworkError, msg, msg2, posix_code);
196 static Status IllegalState(
const Slice& msg,
const Slice& msg2 = Slice(),
197 int16_t posix_code = -1) {
198 return Status(kIllegalState, msg, msg2, posix_code);
200 static Status NotAuthorized(
const Slice& msg,
const Slice& msg2 = Slice(),
201 int16_t posix_code = -1) {
202 return Status(kNotAuthorized, msg, msg2, posix_code);
204 static Status Aborted(
const Slice& msg,
const Slice& msg2 = Slice(),
205 int16_t posix_code = -1) {
206 return Status(kAborted, msg, msg2, posix_code);
208 static Status RemoteError(
const Slice& msg,
const Slice& msg2 = Slice(),
209 int16_t posix_code = -1) {
210 return Status(kRemoteError, msg, msg2, posix_code);
212 static Status ServiceUnavailable(
const Slice& msg,
const Slice& msg2 = Slice(),
213 int16_t posix_code = -1) {
214 return Status(kServiceUnavailable, msg, msg2, posix_code);
216 static Status TimedOut(
const Slice& msg,
const Slice& msg2 = Slice(),
217 int16_t posix_code = -1) {
218 return Status(kTimedOut, msg, msg2, posix_code);
220 static Status Uninitialized(
const Slice& msg,
const Slice& msg2 = Slice(),
221 int16_t posix_code = -1) {
222 return Status(kUninitialized, msg, msg2, posix_code);
224 static Status ConfigurationError(
const Slice& msg,
const Slice& msg2 = Slice(),
225 int16_t posix_code = -1) {
226 return Status(kConfigurationError, msg, msg2, posix_code);
228 static Status Incomplete(
const Slice& msg,
const Slice& msg2 = Slice(),
229 int64_t posix_code = -1) {
230 return Status(kIncomplete, msg, msg2, posix_code);
232 static Status EndOfFile(
const Slice& msg,
const Slice& msg2 = Slice(),
233 int64_t posix_code = -1) {
234 return Status(kEndOfFile, msg, msg2, posix_code);
239 bool ok()
const {
return (state_ == NULL); }
297 std::string ToString()
const;
301 std::string CodeAsString()
const;
311 Slice message()
const;
315 int16_t posix_code()
const;
335 size_t memory_footprint_excluding_this()
const;
339 size_t memory_footprint_including_this()
const;
355 kInvalidArgument = 4,
364 kServiceUnavailable = 13,
367 kConfigurationError = 16,
376 COMPILE_ASSERT(
sizeof(Code) == 4, code_enum_size_is_part_of_abi);
379 return (state_ == NULL) ? kOk :
static_cast<Code
>(state_[4]);
382 Status(Code code,
const Slice& msg,
const Slice& msg2, int16_t posix_code);
383 static const char* CopyState(
const char* s);
387 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
392 if (state_ != s.state_) {
394 state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
398 #if __cplusplus >= 201103L
404 if (state_ != s.state_) {
414 #endif // KUDU_UTIL_STATUS_H_
Status()
Create an object representing success status.
Definition: status.h:119
bool IsNotAuthorized() const
Definition: status.h:269
A representation of an operation's outcome.
Definition: status.h:116
bool IsIllegalState() const
Definition: status.h:266
bool ok() const
Definition: status.h:239
bool IsTimedOut() const
Definition: status.h:281
bool IsRemoteError() const
Definition: status.h:275
bool IsServiceUnavailable() const
Definition: status.h:278
bool IsAborted() const
Definition: status.h:272
bool IsUninitialized() const
Definition: status.h:284
bool IsRuntimeError() const
Definition: status.h:260
bool IsAlreadyPresent() const
Definition: status.h:257
bool IsIOError() const
Definition: status.h:251
static Status OK()
Definition: status.h:150
A wrapper around externally allocated data.
Definition: slice.h:43
bool IsConfigurationError() const
Definition: status.h:287
bool IsInvalidArgument() const
Definition: status.h:254
bool IsCorruption() const
Definition: status.h:245
void operator=(const Status &s)
Definition: status.h:389
bool IsEndOfFile() const
Definition: status.h:293
bool IsNotSupported() const
Definition: status.h:248
bool IsNetworkError() const
Definition: status.h:263
bool IsIncomplete() const
Definition: status.h:290
bool IsNotFound() const
Definition: status.h:242