forked from lotusdblabs/lotusdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
135 lines (110 loc) · 4.63 KB
/
options.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package lotusdb
import (
"os"
"time"
)
const (
// DefaultColumnFamilyName default cf name, we will create a default column family when opening a db.
DefaultColumnFamilyName = "cf_default"
separator = string(os.PathSeparator)
lockFileName = "FLOCK"
)
// DefaultOptions default options for opening a LotusDB.
func DefaultOptions(path string) Options {
return Options{
DBPath: path,
CfOpts: DefaultColumnFamilyOptions(DefaultColumnFamilyName),
}
}
// DefaultColumnFamilyOptions default options for opening a column family.
func DefaultColumnFamilyOptions(name string) ColumnFamilyOptions {
return ColumnFamilyOptions{
CfName: name,
MemtableSize: 64 << 20,
MemtableNums: 5,
MemSpaceWaitTimeout: time.Millisecond * 100,
FlushBatchSize: 100000,
WalMMap: false,
ValueLogFileSize: 1024 << 20,
ValueLogMmap: false,
ValueLogGCRatio: 0.5,
ValueLogGCInterval: time.Minute * 10,
}
}
// Options for opening a db.
type Options struct {
// DBPath db path, will be created automatically if not exist.
DBPath string
// CfOpts options for column family.
CfOpts ColumnFamilyOptions
}
// ColumnFamilyOptions for column family.
type ColumnFamilyOptions struct {
// CfName column family name, can`t be nil.
CfName string
// DirPath dir path for column family, default value is db path+CfName .
// will be created automatically if not exist.
DirPath string
// MemtableSize represents the maximum size in bytes for a memtable.
// It means that each memtable will occupy so much memory.
// Default value is 64MB.
MemtableSize uint32
// MemtableNums represents maximum number of memtables to keep in memory before flushing.
// Default value is 5.
MemtableNums int
// MemSpaceWaitTimeout represents timeout for waiting enough memtable space to write.
// In this scenario will wait: memtable has reached the maximum nums, and has no time to be flushed into disk.
// Default value is 100ms.
MemSpaceWaitTimeout time.Duration
// IndexerDir dir path to store index meta data, default value is dir path.
IndexerDir string
// FlushBatchSize Since we use b+tree to store index info on disk right now.
// We need flush data to b+tree in batches, which can minimize random IO and reduce write amplification.
// Default value is 100000.
FlushBatchSize int
// WalMMap represents whether to use memory map for reading and writing on WAL.
// Setting false means to use standard file io.
// Default value is false.
WalMMap bool
// WalBytesFlush can be used to smooth out write I/Os over time. Users shouldn't rely on it for persistency guarantee.
// Default value is 0, turned off.
WalBytesFlush uint32
// ValueLogDir dir path to store value log file, default value is dir path.
ValueLogDir string
// ValueLogFileSize size of a single value log file.
// Default value is 1GB.
ValueLogFileSize int64
// ValueLogMmap similar to WalMMap, default value is false.
ValueLogMmap bool
// ValueLogGCRatio if discarded data in value log 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.
ValueLogGCRatio float64
// ValueLogGCInterval a background groutine will check and do gc periodically according to the interval.
// If you don`t want value log file be compacted, set it a Zero time.
// Default value is 10 minutes.
ValueLogGCInterval time.Duration
}
// WriteOptions set optional params for PutWithOptions and DeleteWithOptions.
// If use Put and Delete (without options), that means to use the default values.
type WriteOptions struct {
// Sync is whether to synchronize writes through os buffer cache and down onto the actual disk.
// Setting sync is required for durability of a single write operation, but also results in slower writes.
//
// If false, and the machine crashes, then some recent writes may be lost.
// Note that if it is just the process that crashes (machine does not) then no writes will be lost.
//
// In other words, Sync being false has the same semantics as a write
// system call. Sync being true means write followed by fsync.
// Default value is false.
Sync bool
// DisableWal if true, writes will not first go to the write ahead log, and the write may get lost after a crash.
// Setting true only if don`t care about the data loss.
// Default value is false.
DisableWal bool
// ExpiredAt time to live for the specified key, must be a time.Unix value.
// It will be ignored if it`s not a positive number.
// Default value is 0.
ExpiredAt int64
}