-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
79 lines (65 loc) · 2.26 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
package baradb
import "github.com/saint-yellow/baradb/index"
// Options represents options of a DB engine instance
type DBOptions struct {
// Directory of a DB engine instance where data files are stored in
Directory string
// Maximum size of every single data file (uint: Byte).
//
// It should be greater than 0.
MaxDataFileSize int64
// SyncWrites indicates whether persist data after writing
SyncWrites bool
// IndexType indicates the type of the index of the DB engine
IndexType index.IndexType
// SyncThreshold indicates a threshold for persisting data.
//
// It should equals 0 or be greater than 0 (uint: Byte).
//
// When the DB engine wrote bytes more than this threshold, the DB engine will sync the wirtten bytes to the acitve data file.
SyncThreshold uint
// MMapAtStartup indicates whether load memory mapping while starting up the DB engine
MMapAtStartup bool
// MergenceThreshold indicates a threshold for merging data.
//
// When proportion of the invalid data in the DB engine is greater than this threshold,
// the DB engine will merge all its data.
//
// The value of this threshold should be between 0 and 1.
//
// If the value is 0, then this threshold is disabled and the DB engine will not merge its data.
MergenceThreshold float64
}
// checkDBOptions return nil if all DB options are valid and a certain error otherwise.
func checkDBOptions(options DBOptions) error {
if options.Directory == "" {
return ErrDirectoryIsEmpty
}
if options.MaxDataFileSize <= 0 {
return ErrMaxDataFileSizeIsNegative
}
if options.MergenceThreshold < 0 || options.MergenceThreshold > 1 {
return ErrInvalidMergenceThreshold
}
return nil
}
// WriteBatchOptions options for batch writing
type WriteBatchOptions struct {
MaxBatchNumber int // Maximum amount of data in one batch
SyncWrites bool // Sync data after writing if true
}
var (
// DefaultDBOptions Default options for launching DB engine
DefaultDBOptions = DBOptions{
Directory: "/tmp/baradb",
MaxDataFileSize: 512 * 1024 * 1024,
SyncWrites: false,
IndexType: index.ARtree,
MMapAtStartup: false,
}
// DefaultWriteBatchOptions Default options for batch writing
DefaultWriteBatchOptions = WriteBatchOptions{
MaxBatchNumber: 100,
SyncWrites: true,
}
)