Table of Contents

Class SstFileManager

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

Governs how much disk space a database may use and how fast it may delete files. Maps to rocksdb_sst_file_manager_t.

public sealed class SstFileManager : RocksDbHandle, IDisposable
Inheritance
SstFileManager
Implements
Inherited Members

Remarks

Two problems this solves. A database with no space limit fills the disk and then fails in whatever way the filesystem chooses; with a limit, writes fail with an error the application can handle while the disk still has room. And deleting a large amount of data at once can saturate the disk, starving everything else on it, which the delete rate limits.

Attach it with SstFileManager. RocksDb takes a shared reference, so this object may be disposed once assigned, and the same instance may be shared between databases to give them a common budget.

Properties

CompactionBufferSize

Space reserved above the cap for compaction output, in bytes.

public ulong CompactionBufferSize { set; }

Property Value

ulong

Remarks

A compaction writes its output before deleting its inputs, so it temporarily needs more room than the data occupies. Without this reserve a database at its limit could not compact, and so could never shrink.

Set-only, for the same reason as MaxAllowedSpaceUsage.

DeleteRateBytesPerSecond

How fast files may be deleted, in bytes per second. Zero or negative means no limit.

public long DeleteRateBytesPerSecond { get; set; }

Property Value

long

Remarks

Deleting a large file is cheap for the database and expensive for the disk. Rate-limiting it stops a bulk delete from starving reads.

MaxAllowedSpaceUsage

Caps the total space the database may use, in bytes.

public ulong MaxAllowedSpaceUsage { set; }

Property Value

ulong

Remarks

Once reached, writes fail rather than consuming more space. Zero removes the cap.

Set-only: RocksDb offers no accessor to read the cap back. IsMaxAllowedSpaceReached(bool) answers the question the cap exists for.

MaxTrashDbRatio

The largest fraction of the database that pending deletions may occupy before the rate limit is abandoned and files are deleted immediately.

public double MaxTrashDbRatio { get; set; }

Property Value

double

Remarks

The escape hatch for the delete rate. Without it, a slow rate combined with a large delete could let trash grow without bound.

TotalSize

Total size of the files the manager is tracking, in bytes.

public ulong TotalSize { get; }

Property Value

ulong

TotalTrashSize

Total size of files deleted but not yet removed from disk, in bytes.

public ulong TotalTrashSize { get; }

Property Value

ulong

Remarks

Non-zero when the delete rate is throttling removal. This is space the database has finished with but the disk has not yet reclaimed.

Methods

Create(Env?)

Creates a manager using env for file operations.

public static SstFileManager Create(Env? env = null)

Parameters

env Env

The environment whose filesystem the manager acts on. Pass null for the default.

Returns

SstFileManager

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

IsMaxAllowedSpaceReached(bool)

Whether the space cap has been reached.

public bool IsMaxAllowedSpaceReached(bool includingCompactions = false)

Parameters

includingCompactions bool

When true, also counts the space in-flight compactions are expected to need, so it reports the limit as reached sooner.

Returns

bool