Skip to main content
TransactionDB provides transaction support with ACID guarantees for RocksDB. It extends the base DB interface with transactional capabilities including snapshot isolation, conflict detection, and two-phase commit.

Opening a TransactionDB

Open

Opens a TransactionDB similar to DB::Open().
const Options&
Database options including block cache, compression, etc.
const TransactionDBOptions&
Transaction-specific options including lock timeout, write policy, and deadlock detection.
const std::string&
Path to the database directory.
TransactionDB**
Output parameter for the opened TransactionDB instance.
Status
Returns OK on success, or an error status if the database cannot be opened.

Transaction Management

BeginTransaction

Starts a new transaction.
const WriteOptions&
Write options for the transaction.
const TransactionOptions&
Transaction-specific options including snapshot settings, lock timeout, and deadlock detection.
Transaction*
Optional transaction handle to reuse instead of allocating a new one.
Transaction*
Returns a pointer to the new transaction. Caller is responsible for deletion.

GetTransactionByName

Retrieves a transaction by its name.

GetAllPreparedTransactions

Retrieves all prepared transactions (for two-phase commit).

Lock Management

GetLockStatusData

Returns the set of all locks held, mapped by column family ID.

GetDeadlockInfoBuffer

Retrieves information about detected deadlocks.

SetDeadlockInfoBufferSize

Sets the number of latest deadlocks to track.

Snapshot Management

CreateTimestampedSnapshot

Creates a snapshot and assigns a timestamp to it.

GetTimestampedSnapshot

Retrieves the snapshot corresponding to the given timestamp.

ReleaseTimestampedSnapshotsOlderThan

Releases timestamped snapshots older than or equal to the specified timestamp.

Options and Configuration

TransactionDBOptions

int64_t
Maximum number of keys that can be locked per column family. -1 means no limit.
int64_t
Default wait timeout in milliseconds when a transaction attempts to lock a key.
TxnDBWritePolicy
When to write data: WRITE_COMMITTED (default), WRITE_PREPARED, or WRITE_UNPREPARED.

TransactionOptions

bool
Whether to automatically set a snapshot at transaction start.
bool
Whether to check for deadlocks before acquiring locks.

Example

Write Policies

WRITE_COMMITTED

Default policy. Data is written at commit time, providing the strongest consistency guarantees.

WRITE_PREPARED

Experimental. Data is written during the prepare phase of two-phase commit.

WRITE_UNPREPARED

Experimental. Data is written before the prepare phase to support large transactions.

See Also