github.com/rosedblabs/rosedb/v2@v2.3.7-0.20240423093736-a89ea823e5b9/options.go (about) 1 package rosedb 2 3 import "os" 4 5 // Options specifies the options for opening a database. 6 type Options struct { 7 // DirPath specifies the directory path where the WAL segment files will be stored. 8 DirPath string 9 10 // SegmentSize specifies the maximum size of each segment file in bytes. 11 SegmentSize int64 12 13 // BlockCache specifies the size of the block cache in number of bytes. 14 // A block cache is used to store recently accessed data blocks, improving read performance. 15 // If BlockCache is set to 0, no block cache will be used. 16 BlockCache uint32 17 18 // Sync is whether to synchronize writes through os buffer cache and down onto the actual disk. 19 // Setting sync is required for durability of a single write operation, but also results in slower writes. 20 // 21 // If false, and the machine crashes, then some recent writes may be lost. 22 // Note that if it is just the process that crashes (machine does not) then no writes will be lost. 23 // 24 // In other words, Sync being false has the same semantics as a write 25 // system call. Sync being true means write followed by fsync. 26 Sync bool 27 28 // BytesPerSync specifies the number of bytes to write before calling fsync. 29 BytesPerSync uint32 30 31 // WatchQueueSize the cache length of the watch queue. 32 // if the size greater than 0, which means enable the watch. 33 WatchQueueSize uint64 34 35 // AutoMergeEnable enable the auto merge. 36 // auto merge will be triggered when cron expr is satisfied. 37 // cron expression follows the standard cron expression. 38 // e.g. "0 0 * * *" means merge at 00:00:00 every day. 39 // it also supports seconds optionally. 40 // when enable the second field, the cron expression will be like this: "0/10 * * * * *" (every 10 seconds). 41 // when auto merge is enabled, the db will be closed and reopened after merge done. 42 // do not set this shecule too frequently, it will affect the performance. 43 // refer to https://en.wikipedia.org/wiki/Cron 44 AutoMergeCronExpr string 45 } 46 47 // BatchOptions specifies the options for creating a batch. 48 type BatchOptions struct { 49 // Sync has the same semantics as Options.Sync. 50 Sync bool 51 // ReadOnly specifies whether the batch is read only. 52 ReadOnly bool 53 } 54 55 const ( 56 B = 1 57 KB = 1024 * B 58 MB = 1024 * KB 59 GB = 1024 * MB 60 ) 61 62 var DefaultOptions = Options{ 63 DirPath: tempDBDir(), 64 SegmentSize: 1 * GB, 65 BlockCache: 0, 66 Sync: false, 67 BytesPerSync: 0, 68 WatchQueueSize: 0, 69 AutoMergeCronExpr: "", 70 } 71 72 var DefaultBatchOptions = BatchOptions{ 73 Sync: true, 74 ReadOnly: false, 75 } 76 77 func tempDBDir() string { 78 dir, _ := os.MkdirTemp("", "rosedb-temp") 79 return dir 80 }