forked from akrylysov/pogreb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
52 lines (45 loc) · 1.32 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
package pogreb
import (
"math"
"time"
"github.com/akrylysov/pogreb/fs"
)
// Options holds the optional DB parameters.
type Options struct {
// BackgroundSyncInterval sets the amount of time between background Sync() calls.
//
// Setting the value to 0 disables the automatic background synchronization.
// Setting the value to -1 makes the DB call Sync() after every write operation.
BackgroundSyncInterval time.Duration
// BackgroundCompactionInterval sets the amount of time between background Compact() calls.
//
// Setting the value to 0 disables the automatic background compaction.
BackgroundCompactionInterval time.Duration
// FileSystem sets the file system implementation.
//
// Default: fs.OSMMap.
FileSystem fs.FileSystem
maxSegmentSize uint32
compactionMinSegmentSize uint32
compactionMinFragmentation float32
}
func (src *Options) copyWithDefaults(path string) *Options {
opts := Options{}
if src != nil {
opts = *src
}
if opts.FileSystem == nil {
opts.FileSystem = fs.OSMMap
}
opts.FileSystem = fs.Sub(opts.FileSystem, path)
if opts.maxSegmentSize == 0 {
opts.maxSegmentSize = math.MaxUint32
}
if opts.compactionMinSegmentSize == 0 {
opts.compactionMinSegmentSize = 32 << 20
}
if opts.compactionMinFragmentation == 0 {
opts.compactionMinFragmentation = 0.5
}
return &opts
}