Table of Contents

Class CompactionFilter

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

User-defined compaction filter. Override Filter(int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, out byte[]?) to inspect or modify key-value pairs during table-file creation (compaction / flush).

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

Remarks

Lifetime: Dispose it whenever you like. Attaching it through CompactionFilter registers a hold, so disposing while the database is open defers the release instead of performing it. The usual using shape is safe.

Thread safety: When a single instance is registered and multi-threaded compaction is active, Filter(int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, out byte[]?) may be called from multiple threads concurrently. Either make your override thread-safe or use CompactionFilterFactory to create a separate instance per compaction job.

Constructors

CompactionFilter(string)

Creates a compaction filter with the given name.

protected CompactionFilter(string name)

Parameters

name string

Identifies the filter in RocksDb's logs and options output. Not enforced on reopen.

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

DisposeUnmanagedResources()

Releases unmanaged resources used by the current instance.

protected override void DisposeUnmanagedResources()

Remarks

Protected for the same reason as DisposeHandle().

Filter(int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, out byte[]?)

Called for each key-value pair during table-file creation.

protected abstract FilterDecision Filter(int level, ReadOnlySpan<byte> key, ReadOnlySpan<byte> existingValue, out byte[]? newValue)

Parameters

level int

The SST level of the file being created.

key ReadOnlySpan<byte>

The key. The span is valid only for the duration of this call; copy the data if you need it beyond the call.

existingValue ReadOnlySpan<byte>

The current value. Valid only for the duration of this call.

newValue byte[]

Output: when returning ChangeValue, set this to the replacement value. Ignored for other decisions.

Returns

FilterDecision

Keep, Remove, or ChangeValue.