// Return a success status. static Status OK(){ returnStatus(); }
// Successful, though an existing something was overwritten // Note: using variants of OK status for program logic is discouraged, // but it can be useful for communicating statistical information without // changing public APIs. static Status OkOverwritten(){ returnStatus(kOk, kOverwritten); }
// Return error status of an appropriate type. static Status NotFound(const Slice& msg, const Slice& msg2 = Slice()){ returnStatus(kNotFound, msg, msg2); }
// Fast path for not found without malloc; static Status NotFound(SubCode msg = kNone){ returnStatus(kNotFound, msg); }
// Returns true iff the status indicates that a resource is Busy and // temporarily could not be acquired. boolIsBusy()const{ MarkChecked(); returncode() == kBusy; }
// Returns true iff the status indicated that the operation has Expired. boolIsExpired()const{ MarkChecked(); returncode() == kExpired; }
// Returns true iff the status indicates a TryAgain error. // This usually means that the operation failed, but may succeed if // re-attempted. boolIsTryAgain()const{ MarkChecked(); returncode() == kTryAgain; }
// Returns true iff the status indicates the proposed compaction is too large boolIsCompactionTooLarge()const{ MarkChecked(); returncode() == kCompactionTooLarge; }
// Returns true iff the status indicates Column Family Dropped boolIsColumnFamilyDropped()const{ MarkChecked(); returncode() == kColumnFamilyDropped; }
// Returns true iff the status indicates a NoSpace error // This is caused by an I/O error returning the specific "out of space" // error condition. Stricto sensu, an NoSpace error is an I/O error // with a specific subcode, enabling users to take the appropriate action // if needed boolIsNoSpace()const{ MarkChecked(); return (code() == kIOError) && (subcode() == kNoSpace); }
// Returns true iff the status indicates a memory limit error. There may be // cases where we limit the memory used in certain operations (eg. the size // of a write batch) in order to avoid out of memory exceptions. boolIsMemoryLimit()const{ MarkChecked(); return (code() == kAborted) && (subcode() == kMemoryLimit); }
// Returns true iff the status indicates a PathNotFound error // This is caused by an I/O error returning the specific "no such file or // directory" error condition. A PathNotFound error is an I/O error with // a specific subcode, enabling users to take appropriate action if necessary boolIsPathNotFound()const{ MarkChecked(); return (code() == kIOError || code() == kNotFound) && (subcode() == kPathNotFound); }
// Returns true iff the status indicates manual compaction paused. This // is caused by a call to PauseManualCompaction boolIsManualCompactionPaused()const{ MarkChecked(); return (code() == kIncomplete) && (subcode() == kManualCompactionPaused); }
// Returns true iff the status indicates a TxnNotPrepared error. boolIsTxnNotPrepared()const{ MarkChecked(); return (code() == kInvalidArgument) && (subcode() == kTxnNotPrepared); }
// Returns true iff the status indicates a IOFenced error. boolIsIOFenced()const{ MarkChecked(); return (code() == kIOError) && (subcode() == kIOFenced); }
std::string Status::ToString()const{ #ifdef ROCKSDB_ASSERT_STATUS_CHECKED checked_ = true; #endif// ROCKSDB_ASSERT_STATUS_CHECKED constchar* type = nullptr; switch (code_) { case kOk: return"OK"; case kNotFound: type = "NotFound: "; break; case kCorruption: type = "Corruption: "; break; case kNotSupported: type = "Not implemented: "; break; case kInvalidArgument: type = "Invalid argument: "; break; case kIOError: type = "IO error: "; break; case kMergeInProgress: type = "Merge in progress: "; break; case kIncomplete: type = "Result incomplete: "; break; case kShutdownInProgress: type = "Shutdown in progress: "; break; case kTimedOut: type = "Operation timed out: "; break; case kAborted: type = "Operation aborted: "; break; case kBusy: type = "Resource busy: "; break; case kExpired: type = "Operation expired: "; break; case kTryAgain: type = "Operation failed. Try again.: "; break; case kCompactionTooLarge: type = "Compaction too large: "; break; case kColumnFamilyDropped: type = "Column family dropped: "; break; case kMaxCode: assert(false); break; } char tmp[30]; if (type == nullptr) { // This should not happen since `code_` should be a valid non-`kMaxCode` // member of the `Code` enum. The above switch-statement should have had a // case assigning `type` to a corresponding string. assert(false); snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", static_cast<int>(code())); type = tmp; } std::string result(type); if (subcode_ != kNone) { uint32_t index = static_cast<int32_t>(subcode_); assert(sizeof(msgs) / sizeof(msgs[0]) > index); result.append(msgs[index]); }
if (state_ != nullptr) { if (subcode_ != kNone) { result.append(": "); } result.append(state_); } return result; }