Table of Contents

Class CreateBackupOptions

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

Options for a single CreateNewBackup(RocksDb, CreateBackupOptions) call. Maps to rocksdb_create_backup_options_t.

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

Remarks

The two callbacks are the reason this type is disposable in its own right. Unlike RocksDb's other callback registrations, these take no destructor, so nothing on the native side ever tells managed code the callback is finished with. This class therefore owns the GCHandle that roots each delegate and frees it on dispose.

Constructors

CreateBackupOptions()

public CreateBackupOptions()

Properties

AtomicFlush

If true, the pre-backup flush covers every column family atomically, so the backup is consistent across them.

public bool AtomicFlush { get; set; }

Property Value

bool

BackgroundThreadCpuPriority

Priority for the copy threads. Only applied when DecreaseBackgroundThreadCpuPriority is true.

public CpuPriority BackgroundThreadCpuPriority { get; set; }

Property Value

CpuPriority

DecreaseBackgroundThreadCpuPriority

If true, the copy threads run at BackgroundThreadCpuPriority instead of the default priority, keeping a backup from competing with foreground work.

public bool DecreaseBackgroundThreadCpuPriority { get; set; }

Property Value

bool

FlushBeforeBackup

If true, memtables are flushed before the backup is taken.

public bool FlushBeforeBackup { get; set; }

Property Value

bool

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

SetExcludeFilesCallback(Func<string, bool>?)

Installs a callback that decides which files to leave out of the backup.

public CreateBackupOptions SetExcludeFilesCallback(Func<string, bool>? shouldExclude)

Parameters

shouldExclude Func<string, bool>

Called once per candidate file with its path relative to the database directory. Return true to exclude the file. Runs on backup copy threads, so it must be thread-safe. An exception is caught, reported, and treated as "do not exclude", since wrongly excluding a file would leave an incomplete backup. Pass null to remove a previously installed callback.

Returns

CreateBackupOptions

Remarks

Requires SchemaVersion to be 2 or higher. RocksDb fails the backup with an "exclude_files_callback requires schema_version >= 2" error otherwise.

A backup taken with exclusions can only be restored by supplying the other directories holding the excluded files.

SetProgressCallback(Action?)

Installs a callback invoked as the backup progresses, roughly every CallbackTriggerIntervalSize bytes.

public CreateBackupOptions SetProgressCallback(Action? onProgress)

Parameters

onProgress Action

Called on a backup copy thread, and on several of them concurrently when MaxBackgroundOperations is above one, so it must be thread-safe. An exception is caught and reported through UnhandledException rather than reaching native code. Pass null to remove a previously installed callback.

Returns

CreateBackupOptions