Table of Contents

Class WalFilter

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

Inspects, rewrites or skips write-ahead log records as RocksDb replays them while opening a database. Maps to rocksdb_walfilter_t.

public abstract class WalFilter : RocksDbHandle, IDisposable
Inheritance
WalFilter
Implements
Inherited Members

Remarks

Only used during recovery, so the filter runs on the thread calling Open(DbOptions, string) and never concurrently.

Lifetime: RocksDb stores a raw pointer to the filter in the options and never frees it, so unlike EventListener the wrapper keeps ownership. SetWalFilter(WalFilter) registers the filter with the options so it is disposed alongside them.

Constructors

WalFilter(string)

protected WalFilter(string name)

Parameters

name string

Methods

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().

LogRecordFound(ulong, string, WriteBatch, WriteBatch, ref bool)

Called for each record RocksDb replays, and decides what happens to it.

protected abstract WalProcessingOption LogRecordFound(ulong logNumber, string logFileName, WriteBatch batch, WriteBatch replacementBatch, ref bool batchChanged)

Parameters

logNumber ulong

Number of the log file the record came from.

logFileName string

Name of that log file.

batch WriteBatch

The record as written. Valid only for the duration of this call, and must not be disposed or retained.

replacementBatch WriteBatch

Write a replacement here and set batchChanged to true to have RocksDb apply this instead of batch. Same lifetime rules.

batchChanged bool

Set to true when replacementBatch should be applied in place of the original.

Returns

WalProcessingOption

Remarks

Runs during Open(DbOptions, string) on the calling thread. An exception is reported through UnhandledException and treated as ContinueProcessing, which applies the record unchanged.

OnColumnFamilyLogNumberMap(IReadOnlyDictionary<uint, ulong>, IReadOnlyDictionary<string, uint>)

Called once before replay begins, with the log number RocksDb will recover each column family from, and the id of each column family by name.

protected virtual void OnColumnFamilyLogNumberMap(IReadOnlyDictionary<uint, ulong> logNumbersByColumnFamilyId, IReadOnlyDictionary<string, uint> columnFamilyIdsByName)

Parameters

logNumbersByColumnFamilyId IReadOnlyDictionary<uint, ulong>

The log number each column family is being recovered from, keyed by column family id.

columnFamilyIdsByName IReadOnlyDictionary<string, uint>

Column family ids, keyed by name.

Remarks

Override this when LogRecordFound(ulong, string, WriteBatch, WriteBatch, ref bool) needs to know which column families exist. The default does nothing.