github.com/flower-corp/rosedb@v1.1.2-0.20230117132829-21dc4f7b319a/options.go (about) 1 package rosedb 2 3 import "time" 4 5 // DataIndexMode the data index mode. 6 type DataIndexMode int 7 8 const ( 9 // KeyValueMemMode key and value are both in memory, read operation will be very fast in this mode. 10 // Because there is no disk seek, just get value from the corresponding data structures in memory. 11 // This mode is suitable for scenarios where the value are relatively small. 12 KeyValueMemMode DataIndexMode = iota 13 14 // KeyOnlyMemMode only key in memory, there is a disk seek while getting a value. 15 // Because values are in log file on disk. 16 KeyOnlyMemMode 17 ) 18 19 // IOType represents different types of file io: FileIO(standard file io) and MMap(Memory Map). 20 type IOType int8 21 22 const ( 23 // FileIO standard file io. 24 FileIO IOType = iota 25 // MMap Memory Map. 26 MMap 27 ) 28 29 // Options for opening a db. 30 type Options struct { 31 // DBPath db path, will be created automatically if not exist. 32 DBPath string 33 34 // IndexMode mode of index, support KeyValueMemMode and KeyOnlyMemMode now. 35 // Note that this mode is only for kv pairs, not List, Hash, Set, and ZSet. 36 // Default value is KeyOnlyMemMode. 37 IndexMode DataIndexMode 38 39 // IoType file r/w io type, support FileIO and MMap now. 40 // Default value is FileIO. 41 IoType IOType 42 43 // Sync is whether to sync writes from the OS buffer cache through to actual disk. 44 // If false, and the machine crashes, then some recent writes may be lost. 45 // Note that if it is just the process that crashes (and the machine does not) then no writes will be lost. 46 // Default value is false. 47 Sync bool 48 49 // LogFileGCInterval a background goroutine will execute log file garbage collection periodically according to the interval. 50 // It will pick the log file that meet the conditions for GC, then rewrite the valid data one by one. 51 // Default value is 8 hours. 52 LogFileGCInterval time.Duration 53 54 // LogFileGCRatio if discarded data in log file exceeds this ratio, it can be picked up for compaction(garbage collection) 55 // And if there are many files reached the ratio, we will pick the highest one by one. 56 // The recommended ratio is 0.5, half of the file can be compacted. 57 // Default value is 0.5. 58 LogFileGCRatio float64 59 60 // LogFileSizeThreshold threshold size of each log file, active log file will be closed if reach the threshold. 61 // Important!!! This option must be set to the same value as the first startup. 62 // Default value is 512MB. 63 LogFileSizeThreshold int64 64 65 // DiscardBufferSize a channel will be created to send the older entry size when a key updated or deleted. 66 // Entry size will be saved in the discard file, recording the invalid size in a log file, and be used when log file gc is running. 67 // This option represents the size of that channel. 68 // If you got errors like `send discard chan fail`, you can increase this option to avoid it. 69 DiscardBufferSize int 70 } 71 72 // DefaultOptions default options for opening a RoseDB. 73 func DefaultOptions(path string) Options { 74 return Options{ 75 DBPath: path, 76 IndexMode: KeyOnlyMemMode, 77 IoType: FileIO, 78 Sync: false, 79 LogFileGCInterval: time.Hour * 8, 80 LogFileGCRatio: 0.5, 81 LogFileSizeThreshold: 512 << 20, 82 DiscardBufferSize: 8 << 20, 83 } 84 }