Options

December 31, 2025 ยท View on GitHub

About options see here for detail.

ArgumentsCommentType
DirDir represents Open the database located in which dir.string
EntryIdxModeEntryIdxMode represents using which mode to index the entries. EntryIdxMode includes three options: HintKeyValAndRAMIdxMode,HintKeyAndRAMIdxMode and HintBPTSparseIdxMode. HintKeyValAndRAMIdxMode represents ram index (key and value) mode, HintKeyAndRAMIdxMode represents ram index (only key) mode and HintBPTSparseIdxMode represents b+ tree sparse index mode.EntryIdxMode
RWModeRWMode represents the read and write mode. RWMode includes two options: FileIO and MMap. FileIO represents the read and write mode using standard I/O. And MMap represents the read and write mode using mmap.RWMode
SegmentSizeNutsDB will truncate data file if the active file is larger than SegmentSize. Current version default SegmentSize is 8MB,but you can custom it. The defaultSegmentSize becomes 256MB when the version is greater than 0.8.0.

Once set, it cannot be changed. see caveats--limitations for detail.
int64
NodeNumNodeNum represents the node number.Default NodeNum is 1. NodeNum range [1,1023] .int64
SyncEnableSyncEnable represents if call Sync() function. if SyncEnable is false, high write performance but potential data loss likely. if SyncEnable is true, slower but persistent.bool
MaxFdNumsInCacheMaxFdNumsInCache represents the max numbers of fd in cache.int
CleanFdsCacheThresholdCleanFdsCacheThreshold represents the maximum threshold for recycling fd (0-1).float64
BufferSizeOfRecoveryBufferSizeOfRecovery represents the buffer size of recovery reader.int
GCWhenCloseGCWhenClose represents initiative GC when calling db.Close(). Nutsdb doesn't
immediately trigger GC on db.Close() by default.
bool
CommitBufferSizeCommitBufferSize represent the size of memory preallocated for transaction. Nutsdb will preallocate memory and reducing the number of memory allocations.int64
ErrorHandlerErrorHandler handles an error that occur during transaction.ErrorHandler
LessFuncLessFunc represents func to sort keys. Nutsdb sorts keys in lexicographical order by default.LessFunc
MergeIntervalMergeInterval represent the interval for automatic merges, with 0 meaning automatic merging is disabled. Default interval is 2 hours.time.Duration
MaxBatchCountMaxBatchCount represents max entries in batch.int64
MaxBatchSizeMaxBatchSize represents max batch size in bytes.int64
MaxWriteRecordCountMaxWriteRecordCount represents max write record number.int64
HintKeyAndRAMIdxCacheSizeCache size for HintKeyAndRAMIdxMode. When set to 0, caching is disabled.int
TTLConfigConfigure TTL scanning and batching behavior. BatchSize=100, BatchTimeout=1s, QueueSize=1000 by default. Also includes timing wheel settings: EnableTimingWheel=true, WheelSlotDuration=1s, WheelSize=3600.struct
EnableHintFileEnable/disable hint file feature.bool
EnableMergeV2Enable/disable Merge V2 algorithm.bool
ListImplSpecifies the implementation type for List data structure (default: ListImplBTree).ListImplementationType
EnableWatchEnableWatch toggles the watch feature. If EnableWatch is true, the watch feature will be enabled. The watch feature will be disabled by default.bool

Default Options

Recommend to use the DefaultOptions. Unless you know what you're doing.

var DefaultOptions = func() Options {
    return Options{
        EntryIdxMode:              HintKeyValAndRAMIdxMode,
        SegmentSize:               defaultSegmentSize,
        NodeNum:                   1,
        RWMode:                    FileIO,
        SyncEnable:                true,
        MaxFdNumsInCache:          0,
        CleanFdsCacheThreshold:    0,
        BufferSizeOfRecovery:      0,
        CommitBufferSize:          4 * MB,
        MergeInterval:             2 * time.Hour,
        MaxBatchSize:              (15 * defaultSegmentSize / 4) / 100,
        MaxBatchCount:             (15 * defaultSegmentSize / 4) / 100 / 100,
        MaxWriteRecordCount:       0,
        HintKeyAndRAMIdxCacheSize: 0,
        TTLConfig:                 ttl.DefaultConfig(),
        EnableHintFile:            false,
        EnableMergeV2:             false,
        ListImpl:                  ListImplementationType(ListImplBTree),
        EnableWatch:               false,
    }
}()