forked from rosedblabs/rosedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
76 lines (62 loc) · 2.75 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
package rosedb
import (
"github.com/roseduan/rosedb/storage"
)
// 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 the value is in db file.
KeyOnlyMemMode
)
const (
// DefaultAddr default rosedb server address and port.
DefaultAddr = "127.0.0.1:5200"
// DefaultDirPath default rosedb data dir.
DefaultDirPath = "/tmp/rosedb_server"
// DefaultBlockSize default db file size: 16mb.
// If reach the size, db file will never opening for writing.
DefaultBlockSize = 16 * 1024 * 1024
// DefaultMaxKeySize default max key size: 128 bytes.
DefaultMaxKeySize = uint32(128)
// DefaultMaxValueSize default max value size: 1mb.
DefaultMaxValueSize = uint32(1 * 1024 * 1024)
// DefaultReclaimThreshold default disk reclaim threshold: at least 4 archived db files.
DefaultReclaimThreshold = 4
)
// Config the config options of rosedb.
type Config struct {
Addr string `json:"addr" toml:"addr"` // server address
DirPath string `json:"dir_path" toml:"dir_path"` // rosedb dir path of db file
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"`
ReclaimThreshold int `json:"reclaim_threshold" toml:"reclaim_threshold"` // threshold to reclaim disk
}
// DefaultConfig get the default config.
func DefaultConfig() Config {
return Config{
Addr: DefaultAddr,
DirPath: DefaultDirPath,
BlockSize: DefaultBlockSize,
RwMethod: storage.FileIO,
IdxMode: KeyValueMemMode,
MaxKeySize: DefaultMaxKeySize,
MaxValueSize: DefaultMaxValueSize,
Sync: false,
ReclaimThreshold: DefaultReclaimThreshold,
}
}