Class TransactionDb
- Namespace
- RocksDbNet
- Assembly
- RocksDb.Net.dll
A database that supports transactions with per-key locking and conflict
detection. Maps to rocksdb_transactiondb_t.
public sealed class TransactionDb : RocksDbHandle, IDisposable
- Inheritance
-
TransactionDb
- Implements
- Inherited Members
Remarks
Every write takes locks, whether it goes through a Transaction or straight through this object. A second writer touching a locked key waits for the lock timeout and then fails, or fails at once if deadlock detection spots a cycle.
This is a separate type from RocksDb rather than a subclass, because RocksDb gives a transaction database a different native type with a different close, and genuinely no compaction, ingestion, range deletion or column family dropping. A subclass would inherit a dozen members that do not exist here.
Like RocksDb, opening takes ownership of the DbOptions and disposes it when the database closes. The TransactionDbOptions are copied, so those may be disposed immediately.
Properties
ColumnFamilyNames
Names of the column families this database knows about.
public IReadOnlyCollection<string> ColumnFamilyNames { get; }
Property Value
Remarks
The default family is always in here, whether or not it was named when the database was opened. It used to drop out: the backing dictionary is empty for a database opened without an explicit family list, so the default name was reported only while the dictionary stayed empty, and creating a family afterwards replaced it in the listing rather than adding to it. The family still existed and GetColumnFamily(string) still resolved it, so the listing disagreed with the lookup — including in the "Known families" message that lookup throws.
Methods
BeginTransaction(WriteOptions?, TransactionOptions?)
Begins a transaction.
public Transaction BeginTransaction(WriteOptions? writeOptions = null, TransactionOptions? transactionOptions = null)
Parameters
writeOptionsWriteOptionstransactionOptionsTransactionOptions
Returns
Remarks
Dispose the returned transaction, whether or not it is committed. Committing and rolling back do not release it; they only decide what happens to its writes.
CreateColumnFamily(DbOptions, string)
Creates a column family and returns its handle.
public ColumnFamilyHandle CreateColumnFamily(DbOptions options, string name)
Parameters
Returns
Delete(ReadOnlySpan<byte>, ColumnFamilyHandle, WriteOptions?)
Deletes a key.
public void Delete(ReadOnlySpan<byte> key, ColumnFamilyHandle cf, WriteOptions? options = null)
Parameters
keyReadOnlySpan<byte>cfColumnFamilyHandleoptionsWriteOptions
Delete(ReadOnlySpan<byte>, WriteOptions?)
Deletes a key.
public void Delete(ReadOnlySpan<byte> key, WriteOptions? options = null)
Parameters
keyReadOnlySpan<byte>optionsWriteOptions
Delete(string, WriteOptions?)
Deletes a key.
public void Delete(string key, WriteOptions? options = null)
Parameters
keystringoptionsWriteOptions
DisposeHandle()
Releases the native handle. Called during disposal.
protected override void DisposeHandle()
Remarks
Protected rather than public: it destroys the native object without marking this instance disposed or clearing the handle, so calling it from outside and then disposing normally would free the same pointer twice. It was the most Dispose-looking member on the type. Callers want Dispose().
DisposeUnmanagedResources()
Releases unmanaged resources used by the current instance.
protected override void DisposeUnmanagedResources()
Remarks
Protected for the same reason as DisposeHandle().
Flush(ColumnFamilyHandle, FlushOptions?)
Flushes the memtable to disk.
public void Flush(ColumnFamilyHandle cf, FlushOptions? options = null)
Parameters
cfColumnFamilyHandleoptionsFlushOptions
Flush(FlushOptions?)
Flushes the memtable to disk.
public void Flush(FlushOptions? options = null)
Parameters
optionsFlushOptions
FlushWal(FlushWalOptions)
Flushes the write-ahead log, with control over the rate limiter priority as well as syncing.
public void FlushWal(FlushWalOptions options)
Parameters
optionsFlushWalOptions
Remarks
The counterpart to FlushWal(FlushWalOptions), which this type was missing even though the C API has it.
FlushWal(bool)
Flushes the write-ahead log.
public void FlushWal(bool sync)
Parameters
syncboolWhether to fsync the file as well. Flushing without syncing hands the buffer to the operating system and nothing more.
Remarks
There is no default, and there used to be one that disagreed with FlushWal(bool). See that method for why both now require the argument.
Get(ReadOnlySpan<byte>, ColumnFamilyHandle, ReadOptions?)
Reads a key, or returns null if it is absent.
public byte[]? Get(ReadOnlySpan<byte> key, ColumnFamilyHandle cf, ReadOptions? options = null)
Parameters
keyReadOnlySpan<byte>cfColumnFamilyHandleoptionsReadOptions
Returns
- byte[]
Get(ReadOnlySpan<byte>, ReadOptions?)
Reads a key, or returns null if it is absent.
public byte[]? Get(ReadOnlySpan<byte> key, ReadOptions? options = null)
Parameters
keyReadOnlySpan<byte>optionsReadOptions
Returns
- byte[]
GetColumnFamily(string)
Returns the handle for the column family called name.
public ColumnFamilyHandle GetColumnFamily(string name)
Parameters
namestring
Returns
Exceptions
- KeyNotFoundException
No such column family is known.
GetPinned(ReadOnlySpan<byte>, ColumnFamilyHandle, ReadOptions?)
Reads a key without copying the value into managed memory, or returns null if it is absent.
public PinnableSlice? GetPinned(ReadOnlySpan<byte> key, ColumnFamilyHandle cf, ReadOptions? options = null)
Parameters
keyReadOnlySpan<byte>cfColumnFamilyHandleoptionsReadOptions
Returns
GetPinned(ReadOnlySpan<byte>, ReadOptions?)
Reads a key without copying the value into managed memory, or returns null if it is absent.
public PinnableSlice? GetPinned(ReadOnlySpan<byte> key, ReadOptions? options = null)
Parameters
keyReadOnlySpan<byte>optionsReadOptions
Returns
GetProperty(string)
Reads a string-valued RocksDb property.
public string? GetProperty(string propertyName)
Parameters
propertyNamestring
Returns
GetPropertyInt(string)
Reads an integer-valued RocksDb property.
public ulong? GetPropertyInt(string propertyName)
Parameters
propertyNamestring
Returns
GetString(string, ColumnFamilyHandle, ReadOptions?)
Reads a UTF-8 key as a string, or null if absent.
public string? GetString(string key, ColumnFamilyHandle cf, ReadOptions? options = null)
Parameters
keystringcfColumnFamilyHandleoptionsReadOptions
Returns
GetString(string, ReadOptions?)
Reads a UTF-8 key as a string, or null if absent.
public string? GetString(string key, ReadOptions? options = null)
Parameters
keystringoptionsReadOptions
Returns
Merge(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ColumnFamilyHandle, WriteOptions?)
Applies a merge operation to a key.
public void Merge(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value, ColumnFamilyHandle cf, WriteOptions? options = null)
Parameters
keyReadOnlySpan<byte>valueReadOnlySpan<byte>cfColumnFamilyHandleoptionsWriteOptions
Merge(ReadOnlySpan<byte>, ReadOnlySpan<byte>, WriteOptions?)
Applies a merge operation to a key.
public void Merge(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value, WriteOptions? options = null)
Parameters
keyReadOnlySpan<byte>valueReadOnlySpan<byte>optionsWriteOptions
NewIterator(ColumnFamilyHandle, ReadOptions?)
Creates an iterator over the default column family.
public Iterator NewIterator(ColumnFamilyHandle cf, ReadOptions? options = null)
Parameters
cfColumnFamilyHandleoptionsReadOptions
Returns
NewIterator(ReadOptions?)
Creates an iterator over the default column family.
public Iterator NewIterator(ReadOptions? options = null)
Parameters
optionsReadOptions
Returns
NewSnapshot()
Takes a point-in-time snapshot.
public Snapshot NewSnapshot()
Returns
Open(DbOptions, TransactionDbOptions, string)
Opens, or creates, a transaction database at path.
public static TransactionDb Open(DbOptions options, TransactionDbOptions transactionDbOptions, string path)
Parameters
optionsDbOptionstransactionDbOptionsTransactionDbOptionspathstring
Returns
Open(DbOptions, TransactionDbOptions, string, IReadOnlyList<ColumnFamilyDescriptor>)
Opens, or creates, a transaction database with the given column families.
public static TransactionDb Open(DbOptions options, TransactionDbOptions transactionDbOptions, string path, IReadOnlyList<ColumnFamilyDescriptor> columnFamilies)
Parameters
optionsDbOptionstransactionDbOptionsTransactionDbOptionspathstringcolumnFamiliesIReadOnlyList<ColumnFamilyDescriptor>
Returns
Put(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ColumnFamilyHandle, WriteOptions?)
Writes a key and value, taking the same locks a transaction would.
public void Put(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value, ColumnFamilyHandle cf, WriteOptions? options = null)
Parameters
keyReadOnlySpan<byte>valueReadOnlySpan<byte>cfColumnFamilyHandleoptionsWriteOptions
Put(ReadOnlySpan<byte>, ReadOnlySpan<byte>, WriteOptions?)
Writes a key and value, taking the same locks a transaction would.
public void Put(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value, WriteOptions? options = null)
Parameters
keyReadOnlySpan<byte>valueReadOnlySpan<byte>optionsWriteOptions
Put(string, string, ColumnFamilyHandle, WriteOptions?)
Writes a UTF-8 key and value.
public void Put(string key, string value, ColumnFamilyHandle cf, WriteOptions? options = null)
Parameters
keystringvaluestringcfColumnFamilyHandleoptionsWriteOptions
Put(string, string, WriteOptions?)
Writes a UTF-8 key and value.
public void Put(string key, string value, WriteOptions? options = null)
Parameters
keystringvaluestringoptionsWriteOptions
TryGetColumnFamily(string, out ColumnFamilyHandle?)
Looks up a column family handle, returning false rather than throwing when there is none.
public bool TryGetColumnFamily(string name, out ColumnFamilyHandle? columnFamily)
Parameters
namestringcolumnFamilyColumnFamilyHandle
Returns
Write(WriteBatch, WriteOptions?)
Applies a write batch atomically.
public void Write(WriteBatch batch, WriteOptions? options = null)
Parameters
batchWriteBatchoptionsWriteOptions