Skip to main content

Overview

The Status class encapsulates the result of an operation. It may indicate success or an error with an associated error message. Multiple threads can invoke const methods on a Status without external synchronization.

Status Codes

Code Enum

SubCode Enum

Severity Enum

Creating Status Objects

Success Status

Status
Returns a success status

Error Status Constructors

NotFound

Corruption

Indicates data corruption detected.

NotSupported

Operation is not supported by this implementation.

InvalidArgument

Invalid arguments provided to the operation.

IOError

Incomplete

Operation did not complete (e.g., compaction was aborted).

ShutdownInProgress

Aborted

Operation was aborted.

Busy

Resource is busy and temporarily could not be acquired.

TimedOut

TryAgain

Operation failed but may succeed if re-attempted.

Specialized Error Constructors

NoSpace

Out of disk space error (IOError with kNoSpace subcode).

MemoryLimit

Memory limit exceeded (Aborted with kMemoryLimit subcode).

SpaceLimit

Space limit exceeded (IOError with kSpaceLimit subcode).

PathNotFound

File or directory not found (IOError with kPathNotFound subcode).

Checking Status

ok

bool
Returns true if the status indicates success

Error Type Checking

IsNotFound

Returns true if status indicates a NotFound error.

IsCorruption

Returns true if status indicates a Corruption error.

IsNotSupported

Returns true if status indicates a NotSupported error.

IsInvalidArgument

Returns true if status indicates an InvalidArgument error.

IsIOError

Returns true if status indicates an IOError.

IsIncomplete

Returns true if status indicates Incomplete.

IsShutdownInProgress

IsTimedOut

IsAborted

IsBusy

IsTryAgain

Specialized Error Checking

IsNoSpace

Returns true if status indicates an out-of-space I/O error.

IsMemoryLimit

Returns true if status indicates memory limit error.

IsPathNotFound

Returns true if status indicates path not found error.

IsManualCompactionPaused

Returns true if manual compaction was paused.

Accessing Status Information

code

Code
Returns the primary status code

subcode

SubCode
Returns the status subcode for additional error context

severity

Severity
Returns the error severity level

getState

const char*
Returns a C-style string containing the error message

ToString

std::string
Returns a string representation suitable for printing. Returns “OK” for success.

Status Manipulation

UpdateIfOk

Status
Status to potentially adopt
Status&
Returns reference to this Status (allows chaining)
Override this status with another, unless this status is already non-ok. Left-most error takes precedence.

CopyAppendMessage

Create a new Status by appending additional message to an existing Status.

Unchecked Status Handling

PermitUncheckedError

Explicitly mark that you are intentionally ignoring this error. Makes it easy to search for error swallowing.
When ROCKSDB_ASSERT_STATUS_CHECKED is defined, Status objects must be checked before being destroyed, otherwise the program will abort.

Common Usage Patterns

Basic Error Handling

Multiple Operations

Accumulating Errors

Retrying on Specific Errors