-
Notifications
You must be signed in to change notification settings - Fork 36
/
options.go
84 lines (70 loc) · 2.4 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
package wal
import "os"
type Option func(*Options)
// Options represents the configuration options for a Write-Ahead Log (WAL).
type Options struct {
// DirPath specifies the directory path where the WAL segment files will be stored.
DirPath string
// SegmentSize specifies the maximum size of each segment file in bytes.
SegmentSize int64
// SegmentFileExt specifies the file extension of the segment files.
// The file extension must start with a dot ".", default value is ".SEG".
// It is used to identify the different types of files in the directory.
// Now it is used by rosedb to identify the segment files and hint files.
// Not a common usage for most users.
SegmentFileExt string
// 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.
Sync bool
// BytesPerSync specifies the number of bytes to write before calling fsync.
BytesPerSync uint32
}
const (
B = 1
KB = 1024 * B
MB = 1024 * KB
GB = 1024 * MB
)
var DefaultOptions = Options{
DirPath: os.TempDir(),
SegmentSize: GB,
SegmentFileExt: ".SEG",
Sync: false,
BytesPerSync: 0,
}
// WithDirPath sets the directory path where the WAL segment files will be stored.
func WithDirPath(dir string) Option {
return func(o *Options) {
o.DirPath = dir
}
}
// WithSegmentSize sets the maximum size of each segment file in bytes.
func WithSegmentSize(size int64) Option {
return func(o *Options) {
o.SegmentSize = size
}
}
// WithSegmentFileExt sets the file extension of the segment files.
func WithSegmentFileExt(ext string) Option {
return func(o *Options) {
o.SegmentFileExt = ext
}
}
// WithSync sets the whether to synchronize writes through os buffer cache and down onto the actual disk.
func WithSync(sync bool) Option {
return func(o *Options) {
o.Sync = sync
}
}
// WithBytesPerSync sets the number of bytes to write before calling fsync.
func WithBytesPerSync(bytesPerSync uint32) Option {
return func(o *Options) {
o.BytesPerSync = bytesPerSync
}
}