forked from cosmos/iavl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
130 lines (105 loc) · 3.08 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package iavl
import "sync/atomic"
// Statisc about db runtime state
type Statistics struct {
// Each time GetNode operation hit cache
cacheHitCnt uint64
// Each time GetNode and GetFastNode operation miss cache
cacheMissCnt uint64
// Each time GetFastNode operation hit cache
fastCacheHitCnt uint64
// Each time GetFastNode operation miss cache
fastCacheMissCnt uint64
}
func (stat *Statistics) IncCacheHitCnt() {
if stat == nil {
return
}
atomic.AddUint64(&stat.cacheHitCnt, 1)
}
func (stat *Statistics) IncCacheMissCnt() {
if stat == nil {
return
}
atomic.AddUint64(&stat.cacheMissCnt, 1)
}
func (stat *Statistics) IncFastCacheHitCnt() {
if stat == nil {
return
}
atomic.AddUint64(&stat.fastCacheHitCnt, 1)
}
func (stat *Statistics) IncFastCacheMissCnt() {
if stat == nil {
return
}
atomic.AddUint64(&stat.fastCacheMissCnt, 1)
}
func (stat *Statistics) GetCacheHitCnt() uint64 {
return atomic.LoadUint64(&stat.cacheHitCnt)
}
func (stat *Statistics) GetCacheMissCnt() uint64 {
return atomic.LoadUint64(&stat.cacheMissCnt)
}
func (stat *Statistics) GetFastCacheHitCnt() uint64 {
return atomic.LoadUint64(&stat.fastCacheHitCnt)
}
func (stat *Statistics) GetFastCacheMissCnt() uint64 {
return atomic.LoadUint64(&stat.fastCacheMissCnt)
}
func (stat *Statistics) Reset() {
atomic.StoreUint64(&stat.cacheHitCnt, 0)
atomic.StoreUint64(&stat.cacheMissCnt, 0)
atomic.StoreUint64(&stat.fastCacheHitCnt, 0)
atomic.StoreUint64(&stat.fastCacheMissCnt, 0)
}
// Options define tree options.
type Options struct {
// Sync synchronously flushes all writes to storage, using e.g. the fsync syscall.
// Disabling this significantly improves performance, but can lose data on e.g. power loss.
Sync bool
// InitialVersion specifies the initial version number. If any versions already exist below
// this, an error is returned when loading the tree. Only used for the initial SaveVersion()
// call.
InitialVersion uint64
// When Stat is not nil, statistical logic needs to be executed
Stat *Statistics
// Ethereum has found that commit of 100KB is optimal, ref ethereum/go-ethereum#15115
FlushThreshold int
// AsyncPruning is a flag to enable async pruning
AsyncPruning bool
}
// DefaultOptions returns the default options for IAVL.
func DefaultOptions() Options {
return Options{FlushThreshold: 100000}
}
// SyncOption sets the Sync option.
func SyncOption(sync bool) Option {
return func(opts *Options) {
opts.Sync = sync
}
}
// InitialVersionOption sets the initial version for the tree.
func InitialVersionOption(iv uint64) Option {
return func(opts *Options) {
opts.InitialVersion = iv
}
}
// StatOption sets the Statistics for the tree.
func StatOption(stats *Statistics) Option {
return func(opts *Options) {
opts.Stat = stats
}
}
// FlushThresholdOption sets the FlushThreshold for the batcher.
func FlushThresholdOption(ft int) Option {
return func(opts *Options) {
opts.FlushThreshold = ft
}
}
// AsyncPruningOption sets the AsyncPruning for the tree.
func AsyncPruningOption(asyncPruning bool) Option {
return func(opts *Options) {
opts.AsyncPruning = asyncPruning
}
}