Class SstFileWriter
- Namespace
- RocksDbNet
- Assembly
- RocksDb.Net.dll
Writes key-value pairs in sorted order to a standalone SST file that can later be ingested into a database via IngestExternalFile(IReadOnlyList<string>, IngestExternalFileOptions). Keys must be added in ascending order.
public sealed class SstFileWriter : RocksDbHandle, IDisposable
- Inheritance
-
SstFileWriter
- Implements
- Inherited Members
Properties
FileSize
Returns the size of the written file in bytes (available after Finish()).
public ulong FileSize { get; }
Property Value
Methods
Create(DbOptions)
Creates a new SstFileWriter using default environment options and the provided database options (for comparator / compression settings).
public static SstFileWriter Create(DbOptions options)
Parameters
optionsDbOptions
Returns
Remarks
The writer keeps a reference to options for its own
lifetime, because RocksDb keeps the comparator and the env out of them by
raw pointer and reads both on every write. That stops them being collected
under a live writer; disposing them yourself while it is open is still your
mistake to avoid.
Create(EnvOptions, DbOptions)
Creates a new SstFileWriter with explicit environment options, for control over how the file is written: direct or memory mapped I/O, preallocation, sync behaviour and rate limiting.
public static SstFileWriter Create(EnvOptions envOptions, DbOptions options)
Parameters
envOptionsEnvOptionsoptionsDbOptions
Returns
Remarks
envOptions is read here and not retained: RocksDb copies
what it needs out of it, so the caller may dispose it once the writer
exists. options is different — the writer keeps a
reference to it, because RocksDb keeps the comparator and the env out of it
by raw pointer and reads both on every write. Do not dispose those while
the writer is open.
Delete(ReadOnlySpan<byte>)
Writes a deletion record for key.
public void Delete(ReadOnlySpan<byte> key)
Parameters
keyReadOnlySpan<byte>
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().
Finish()
Finalizes and closes the SST file. Must be called before ingestion.
public void Finish()
Merge(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Writes a merge operand. Keys must be added in ascending order.
public void Merge(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value)
Parameters
keyReadOnlySpan<byte>valueReadOnlySpan<byte>
Open(string)
Opens filePath for writing. Call before any Put/Merge/Delete.
public void Open(string filePath)
Parameters
filePathstring
Put(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Writes a key-value pair. Keys must be added in ascending order.
public void Put(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value)
Parameters
keyReadOnlySpan<byte>valueReadOnlySpan<byte>