Configuration Reference

July 24, 2026 ยท View on GitHub

ZoneTreeFactory<TKey, TValue> owns the configuration used to create or open a tree. Configure components and options before calling an open method.

Factory Entry Points

PurposeAPI
data and WAL locationSetDataDirectory, SetWriteAheadLogDirectory
key behaviorSetComparer, SetKeyHasher, SetKeySerializer
value behaviorSetValueSerializer, deletion delegates
mutable segmentSetMutableSegmentMaxItemCount, SetMutableSegmentBloomFilterBitsPerItem
persistent segmentsSetDiskSegmentMaxItemCount, SetDiskSegmentCompressionBlockSize
grouped optionsConfigure, ConfigureWriteAheadLogOptions, ConfigureDiskSegmentOptions
providersSetRandomAccessDeviceManager, SetWriteAheadLogProvider, SetTransactionLog
openingCreate, Open, OpenOrCreate, transactional variants

Known key/value types receive default serializers and, where applicable, comparers and key hashers. Custom types require explicit compatible components; a key hasher is required only when the mutable-segment Bloom filter is enabled.

Core Defaults

OptionDefaultValidated range or meaning
MutableSegmentMaxItemCount1_000_000at least 1_000
MutableSegmentBloomFilterBitsPerItem80..64; 0 disables
DiskSegmentMaxItemCount20_000_000at least 10_000
mutable B+Tree lock modeNodeLevelMonitordefined BTreeLockMode value
mutable B+Tree node size128at least 16
mutable B+Tree leaf size128at least 16
single-segment garbage collection on loaddisabledboolean
unsafe numeric option valuesdisabledboolean; does not bypass required-component or enum validation

The public property identifiers BTreeLockMode, BTreeNodeSize, and BTreeLeafSize configure ZoneTree's mutable B+Tree.

Key Components

ComponentContract
Comparerdefines key equality and total order
KeyHashercomparer-equal keys must hash equally
KeySerializerdefines persisted key bytes
ValueSerializerdefines persisted value bytes
deletion delegatesdefine and create deletion markers

Mutable-Segment Bloom Filter

The filter is sized from MutableSegmentMaxItemCount and MutableSegmentBloomFilterBitsPerItem. Allocation rounds up to a power of two and is capped at 2^30 bits.

using var zoneTree = new ZoneTreeFactory<long, string>()
    .SetMutableSegmentMaxItemCount(500_000)
    .SetMutableSegmentBloomFilterBitsPerItem(8)
    .OpenOrCreate();

Use 0 bits per item to disable the filter and remove the key-hasher requirement. A larger value is not free: it increases memory and does not eliminate comparer-based lookup after a possible match.

See mutable-segment Bloom filters for sizing, false-positive behavior, and hasher requirements.

WAL Defaults

OptionDefaultValidated range or meaning
WriteAheadLogModeAsyncCompresseddefined mode
CompressionBlockSize256 KB256 KB..16 MB
CompressionMethodZstdcompatible method/level pair
CompressionLevelZstd level 0method-specific
async empty-queue poll interval100 msnon-negative
sync-compressed tail writerenabledboolean
sync-compressed tail writer interval500 msnon-negative
incremental backupdisabledused by transactional-log compaction

WAL options apply when new WALs are created. Existing WALs retain their stored options. The modes have different caller acknowledgment and failure boundaries; read WAL modes before changing them.

Disk-Segment Defaults

OptionDefaultValidated range or meaning
DiskSegmentModeMultiPartDiskSegmentdefined mode
CompressionBlockSize4 MB1 MB..64 MB
CompressionMethodZstdcompatible method/level pair
CompressionLevelZstd level 0method-specific
MinimumRecordCount1_500_000at least 1_000
MaximumRecordCount3_000_000at least 2_000; must exceed minimum
DefaultSparseArrayStepSize1024non-negative; 0 disables
KeyCacheSize1024non-negative; 0 disables
ValueCacheSize1024non-negative; 0 disables
key cache record lifetime10_000 msnon-negative
value cache record lifetime10_000 msnon-negative
MaterializedEntryCacheSize4096 chunks/blocknon-negative; 0 disables
SearchHintPrefetchSize16 entriesnon-negative; 0 disables

Materialized chunks contain 16 aligned entries, so the default permits at most 65,536 cached materialized positions in one decompressed block. Actual memory depends on key/value shape and accessed positions.

using var zoneTree = new ZoneTreeFactory<long, string>()
    .ConfigureDiskSegmentOptions(options =>
    {
        options.DefaultSparseArrayStepSize = 512;
        options.MaterializedEntryCacheSize = 2048;
        options.SearchHintPrefetchSize = 16;
    })
    .OpenOrCreate();

The active disk-segment options are persisted in ZoneTree metadata. Individual segment files also retain the physical format information required to read their stored representation.

Iterator Defaults

OptionDefaultMeaning
IteratorTypeAutoRefreshrefresh behavior
IncludeDeletedRecordsfalsehide deletion markers
ContributeToTheBlockCachefalseavoid warming shared blocks during scans
DiskSegmentPrefetchSize0values below 2 disable prefetch

Iterator options are per iterator and are not persisted.

Maintainer Defaults

The maintainer owns runtime jobs and cache cleanup rather than persisted tree options. Important defaults include a one-minute inactive block lifetime and a 30-second inactive-block cleanup interval.

using var maintainer = zoneTree.CreateMaintainer();

maintainer.BlockCacheLifeTime = TimeSpan.FromMinutes(1);
maintainer.InactiveBlockCacheCleanupInterval = TimeSpan.FromSeconds(30);

These settings apply to a created maintainer. The zoneTree.Maintenance API exposes state, events, and operations for custom maintenance policy.

Validation

The factory validates required components, enum values, compression compatibility, numeric ranges, multipart bounds, and a common case-insensitive string comparer/hasher mismatch.

AllowUnsafeOptionValues bypasses numeric range checks for advanced or test configurations. It does not make invalid component combinations safe and should not be a production tuning shortcut.

Complete Configuration Example

using ZoneTree;
using ZoneTree.Options;
using ZoneTree.WAL;

using var zoneTree = new ZoneTreeFactory<long, string>()
    .SetDataDirectory("data/app")
    .SetMutableSegmentMaxItemCount(500_000)
    .SetMutableSegmentBloomFilterBitsPerItem(8)
    .ConfigureWriteAheadLogOptions(options =>
    {
        options.WriteAheadLogMode = WriteAheadLogMode.AsyncCompressed;
    })
    .ConfigureDiskSegmentOptions(options =>
    {
        options.DiskSegmentMode = DiskSegmentMode.MultiPartDiskSegment;
        options.MaterializedEntryCacheSize = 4096;
        options.SearchHintPrefetchSize = 16;
    })
    .OpenOrCreate();

using var maintainer = zoneTree.CreateMaintainer();

See disk-segment tuning, read-path caching, and key components.