@@ -28,8 +28,7 @@ import (
28
28
)
29
29
30
30
const (
31
- RootPath = EmptyPath
32
- evictionBatchSize = 100
31
+ RootPath = EmptyPath
33
32
// TODO: name better
34
33
rebuildViewSizeFractionOfCacheSize = 50
35
34
minRebuildViewSizePerCommit = 1000
@@ -116,6 +115,9 @@ type MerkleDB interface {
116
115
}
117
116
118
117
type Config struct {
118
+ // The number of nodes that are evicted from the cache and written to
119
+ // disk at a time.
120
+ EvictionBatchSize int
119
121
// The number of changes to the database that we store in memory in order to
120
122
// serve change proofs.
121
123
HistoryLength int
@@ -144,8 +146,9 @@ type merkleDB struct {
144
146
metadataDB database.Database
145
147
146
148
// If a value is nil, the corresponding key isn't in the trie.
147
- nodeCache onEvictCache [path , * node ]
148
- onEvictionErr utils.Atomic [error ]
149
+ nodeCache onEvictCache [path , * node ]
150
+ onEvictionErr utils.Atomic [error ]
151
+ evictionBatchSize int
149
152
150
153
// Stores change lists. Used to serve change proofs and construct
151
154
// historical views of the trie.
@@ -172,12 +175,13 @@ func newDatabase(
172
175
metrics merkleMetrics ,
173
176
) (* merkleDB , error ) {
174
177
trieDB := & merkleDB {
175
- metrics : metrics ,
176
- nodeDB : prefixdb .New (nodePrefix , db ),
177
- metadataDB : prefixdb .New (metadataPrefix , db ),
178
- history : newTrieHistory (config .HistoryLength ),
179
- tracer : config .Tracer ,
180
- childViews : make ([]* trieView , 0 , defaultPreallocationSize ),
178
+ metrics : metrics ,
179
+ nodeDB : prefixdb .New (nodePrefix , db ),
180
+ metadataDB : prefixdb .New (metadataPrefix , db ),
181
+ history : newTrieHistory (config .HistoryLength ),
182
+ tracer : config .Tracer ,
183
+ childViews : make ([]* trieView , 0 , defaultPreallocationSize ),
184
+ evictionBatchSize : config .EvictionBatchSize ,
181
185
}
182
186
183
187
// Note: trieDB.OnEviction is responsible for writing intermediary nodes to
@@ -757,7 +761,7 @@ func (db *merkleDB) onEviction(n *node) error {
757
761
// just [n], so that we don't immediately evict and write another
758
762
// node, because each time this method is called we do a disk write.
759
763
var err error
760
- for removedCount := 0 ; removedCount < evictionBatchSize ; removedCount ++ {
764
+ for removedCount := 0 ; removedCount < db . evictionBatchSize ; removedCount ++ {
761
765
_ , n , exists := db .nodeCache .removeOldest ()
762
766
if ! exists {
763
767
// The cache is empty.
0 commit comments