-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
47 lines (41 loc) · 1.73 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package lazydb
import (
"github.com/billsjc123/LazyDB/ds"
"github.com/billsjc123/LazyDB/logfile"
"time"
)
const (
defaultMaxLogFileSize int64 = 512 << 20
defaultLogFileMergeInterval time.Duration = time.Hour * 8
defaultIOType logfile.IOType = logfile.FileIO
)
type DBConfig struct {
DBPath string // Directory path for storing log files on disk.
HashIndexShardCount int64 // default 32
MaxLogFileSize int64 // Max capacity of a log file.
LogFileMergeInterval time.Duration // Max time interval for merging log files.
// IOType
// Only support FileIO at the moment
IOType logfile.IOType
// DiscardBufferSize a channel will be created to send the older entry size when a key updated or deleted.
// 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.
// This option represents the size of that channel.
// If you got errors like `send discard chan fail`, you can increase this option to avoid it.
DiscardBufferSize int
// LogFileGCRatio if discarded data in log file exceeds this ratio, it can be picked up for compaction(garbage collection)
// And if there are many files reached the ratio, we will pick the highest one by one.
// The recommended ratio is 0.5, half of the file can be compacted.
// Default value is 0.5.
LogFileGCRatio float64
}
func DefaultDBConfig(path string) DBConfig {
return DBConfig{
DBPath: path,
HashIndexShardCount: ds.DefaultShardCount,
MaxLogFileSize: defaultMaxLogFileSize,
LogFileMergeInterval: defaultLogFileMergeInterval,
IOType: defaultIOType,
DiscardBufferSize: 8 << 20,
LogFileGCRatio: 0.5,
}
}