forked from rosedblabs/rosedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
98 lines (80 loc) · 3.74 KB
/
config.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
package rosedb
import (
"github.com/roseduan/rosedb/storage"
"time"
)
// DataIndexMode the data index mode.
type DataIndexMode int
const (
// KeyValueMemMode key and value are both in memory, read operation will be very fast in this mode.
// Because there is no disk seek, just get value from the corresponding data structures in memory.
// This mode is suitable for scenarios where the value are relatively small.
KeyValueMemMode DataIndexMode = iota
// KeyOnlyMemMode only key in memory, there is a disk seek while getting a value.
// Because values are in db file on disk.
KeyOnlyMemMode
)
const (
// DefaultAddr default rosedb server address and port.
DefaultAddr = "127.0.0.1:5200"
// DefaultGrpcAddr grpc server address and port.
DefaultGrpcAddr = "127.0.0.1:5300"
// DefaultDirPath default rosedb data dir.
// Don`t forget to change the path when using.
DefaultDirPath = "/tmp/rosedb"
// DefaultBlockSize default db file size: 16mb.
// If reach the size, db file will never be opened for writing.
DefaultBlockSize = 16 * 1024 * 1024
// DefaultMaxKeySize default max key size: 1mb.
DefaultMaxKeySize = uint32(1 * 1024 * 1024)
// DefaultMaxValueSize default max value size: 8mb.
DefaultMaxValueSize = uint32(8 * 1024 * 1024)
// DefaultMergeThreshold default disk files reclaim threshold: 64.
// This means that it will be reclaimed when there are at least 64 archived files on disk.
DefaultMergeThreshold = 64
// DefaultMergeCheckInterval a timer will be set according to the check interval.
// Then merge operation will execute periodically.
DefaultMergeCheckInterval = time.Hour * 24
// DefaultCacheCapacity default cache capacity: 0, which means we don`t use it by default.
// You can only open the cache in KeyOnlyMemMode, because values are in disk in this mode.
DefaultCacheCapacity = 0
)
// Config the opening options of rosedb.
type Config struct {
Addr string `json:"addr" toml:"addr"` // server address
GrpcAddr string `json:"grpc_addr" toml:"grpc_addr"` // grpc server address
DirPath string `json:"dir_path" toml:"dir_path"` // rosedb dir path of db file
// Deprecated: don`t edit the option, it will be removed in future release.
BlockSize int64 `json:"block_size" toml:"block_size"` // each db file size
RwMethod storage.FileRWMethod `json:"rw_method" toml:"rw_method"` // db file read and write method
IdxMode DataIndexMode `json:"idx_mode" toml:"idx_mode"` // data index mode
MaxKeySize uint32 `json:"max_key_size" toml:"max_key_size"`
MaxValueSize uint32 `json:"max_value_size" toml:"max_value_size"`
// Sync is whether to sync writes from the OS buffer cache through to actual disk.
// If false, and the machine crashes, then some recent writes may be lost.
//
// Note that if it is just the process that crashes (and the machine does not) then no writes will be lost.
//
// The default value is false.
Sync bool `json:"sync" toml:"sync"`
MergeThreshold int `json:"merge_threshold" toml:"merge_threshold"` // threshold to reclaim disk
MergeCheckInterval time.Duration `json:"merge_check_interval"`
CacheCapacity int `json:"cache_capacity" toml:"cache_capacity"`
}
// DefaultConfig get the default config.
func DefaultConfig() Config {
return Config{
Addr: DefaultAddr,
GrpcAddr: DefaultGrpcAddr,
DirPath: DefaultDirPath,
BlockSize: DefaultBlockSize,
RwMethod: storage.FileIO,
IdxMode: KeyOnlyMemMode,
MaxKeySize: DefaultMaxKeySize,
MaxValueSize: DefaultMaxValueSize,
Sync: false,
MergeThreshold: DefaultMergeThreshold,
MergeCheckInterval: DefaultMergeCheckInterval,
CacheCapacity: DefaultCacheCapacity,
}
}