-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
60 lines (49 loc) · 1.08 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
package walx
import (
"time"
)
const (
DefaultFsyncThresholdInBytes = 64 * 1024
DefaultSegmentCacheSize = 4
DefaultSegmentSize = 1 * 1024 * 1024 * 1024
)
type HookData struct {
Index uint64
Data []byte
WriteTime time.Duration
FSyncCalled bool
FSyncTime time.Duration
}
type Hook func(data HookData)
type options struct {
fsyncThreshold int
segmentCacheSize int
segmentSize int
hook Hook
}
func newOptions() *options {
return &options{
fsyncThreshold: DefaultFsyncThresholdInBytes,
segmentCacheSize: DefaultSegmentCacheSize,
segmentSize: DefaultSegmentSize,
hook: func(data HookData) {
},
}
}
type Option func(o *options)
func SegmentsCachePolicy(inMemSegmentsCount int, segmentSizeInBytes int) Option {
return func(o *options) {
o.segmentCacheSize = inMemSegmentsCount
o.segmentSize = segmentSizeInBytes
}
}
func FsyncThreshold(thresholdInBytes int) Option {
return func(o *options) {
o.fsyncThreshold = thresholdInBytes
}
}
func WithHook(hook Hook) Option {
return func(o *options) {
o.hook = hook
}
}