Skip to content

Commit 8abd44f

Browse files
author
Dan Laine
authored
Revert "MerkleDB -- add eviction batch size config (#1586)"
This reverts commit 268f5a9.
1 parent 268f5a9 commit 8abd44f

File tree

4 files changed

+130
-65
lines changed

4 files changed

+130
-65
lines changed

x/merkledb/db.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import (
2828
)
2929

3030
const (
31-
RootPath = EmptyPath
31+
RootPath = EmptyPath
32+
evictionBatchSize = 100
3233
// TODO: name better
3334
rebuildViewSizeFractionOfCacheSize = 50
3435
minRebuildViewSizePerCommit = 1000
@@ -115,9 +116,6 @@ type MerkleDB interface {
115116
}
116117

117118
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
121119
// The number of changes to the database that we store in memory in order to
122120
// serve change proofs.
123121
HistoryLength int
@@ -146,9 +144,8 @@ type merkleDB struct {
146144
metadataDB database.Database
147145

148146
// If a value is nil, the corresponding key isn't in the trie.
149-
nodeCache onEvictCache[path, *node]
150-
onEvictionErr utils.Atomic[error]
151-
evictionBatchSize int
147+
nodeCache onEvictCache[path, *node]
148+
onEvictionErr utils.Atomic[error]
152149

153150
// Stores change lists. Used to serve change proofs and construct
154151
// historical views of the trie.
@@ -175,13 +172,12 @@ func newDatabase(
175172
metrics merkleMetrics,
176173
) (*merkleDB, error) {
177174
trieDB := &merkleDB{
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,
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),
185181
}
186182

187183
// Note: trieDB.OnEviction is responsible for writing intermediary nodes to
@@ -761,7 +757,7 @@ func (db *merkleDB) onEviction(n *node) error {
761757
// just [n], so that we don't immediately evict and write another
762758
// node, because each time this method is called we do a disk write.
763759
var err error
764-
for removedCount := 0; removedCount < db.evictionBatchSize; removedCount++ {
760+
for removedCount := 0; removedCount < evictionBatchSize; removedCount++ {
765761
_, n, exists := db.nodeCache.removeOldest()
766762
if !exists {
767763
// The cache is empty.

x/merkledb/db_test.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strconv"
1111
"testing"
1212

13-
"github.com/prometheus/client_golang/prometheus"
1413
"github.com/stretchr/testify/require"
1514

1615
"github.com/ava-labs/avalanchego/database"
@@ -27,16 +26,6 @@ func newNoopTracer() trace.Tracer {
2726
return tracer
2827
}
2928

30-
func newDefaultConfig() Config {
31-
return Config{
32-
EvictionBatchSize: 100,
33-
HistoryLength: 100,
34-
NodeCacheSize: 1_000,
35-
Reg: prometheus.NewRegistry(),
36-
Tracer: newNoopTracer(),
37-
}
38-
}
39-
4029
func Test_MerkleDB_Get_Safety(t *testing.T) {
4130
db, err := getBasicDB()
4231
require.NoError(t, err)
@@ -97,7 +86,11 @@ func Test_MerkleDB_DB_Load_Root_From_DB(t *testing.T) {
9786
db, err := New(
9887
context.Background(),
9988
rdb,
100-
newDefaultConfig(),
89+
Config{
90+
Tracer: newNoopTracer(),
91+
HistoryLength: 100,
92+
NodeCacheSize: 100,
93+
},
10194
)
10295
require.NoError(err)
10396

@@ -119,7 +112,11 @@ func Test_MerkleDB_DB_Load_Root_From_DB(t *testing.T) {
119112
db, err = New(
120113
context.Background(),
121114
rdb,
122-
newDefaultConfig(),
115+
Config{
116+
Tracer: newNoopTracer(),
117+
HistoryLength: 100,
118+
NodeCacheSize: 100,
119+
},
123120
)
124121
require.NoError(err)
125122
reloadedRoot, err := db.GetMerkleRoot(context.Background())
@@ -135,13 +132,14 @@ func Test_MerkleDB_DB_Rebuild(t *testing.T) {
135132

136133
initialSize := 10_000
137134

138-
config := newDefaultConfig()
139-
config.NodeCacheSize = initialSize
140-
141135
db, err := New(
142136
context.Background(),
143137
rdb,
144-
config,
138+
Config{
139+
Tracer: newNoopTracer(),
140+
HistoryLength: 100,
141+
NodeCacheSize: initialSize,
142+
},
145143
)
146144
require.NoError(err)
147145

@@ -169,7 +167,10 @@ func Test_MerkleDB_Failed_Batch_Commit(t *testing.T) {
169167
db, err := New(
170168
context.Background(),
171169
memDB,
172-
newDefaultConfig(),
170+
Config{
171+
Tracer: newNoopTracer(),
172+
HistoryLength: 300,
173+
},
173174
)
174175
require.NoError(t, err)
175176

@@ -189,7 +190,11 @@ func Test_MerkleDB_Value_Cache(t *testing.T) {
189190
db, err := New(
190191
context.Background(),
191192
memDB,
192-
newDefaultConfig(),
193+
Config{
194+
Tracer: newNoopTracer(),
195+
HistoryLength: 300,
196+
NodeCacheSize: minCacheSize,
197+
},
193198
)
194199
require.NoError(t, err)
195200

@@ -810,7 +815,11 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest) {
810815
dbTrie, err := newDatabase(
811816
context.Background(),
812817
memdb.New(),
813-
newDefaultConfig(),
818+
Config{
819+
Tracer: newNoopTracer(),
820+
HistoryLength: 0,
821+
NodeCacheSize: minCacheSize,
822+
},
814823
&mockMetrics{},
815824
)
816825
require.NoError(err)

x/sync/client_test.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/golang/mock/gomock"
14-
"github.com/prometheus/client_golang/prometheus"
1514

1615
"github.com/stretchr/testify/require"
1716

@@ -28,16 +27,6 @@ import (
2827
syncpb "github.com/ava-labs/avalanchego/proto/pb/sync"
2928
)
3029

31-
func newDefaultDBConfig() merkledb.Config {
32-
return merkledb.Config{
33-
EvictionBatchSize: 100,
34-
HistoryLength: defaultRequestKeyLimit,
35-
NodeCacheSize: defaultRequestKeyLimit,
36-
Reg: prometheus.NewRegistry(),
37-
Tracer: newNoopTracer(),
38-
}
39-
}
40-
4130
func sendRangeRequest(
4231
t *testing.T,
4332
db SyncableDB,
@@ -388,14 +377,21 @@ func TestGetChangeProof(t *testing.T) {
388377
trieDB, err := merkledb.New(
389378
context.Background(),
390379
memdb.New(),
391-
newDefaultDBConfig(),
380+
merkledb.Config{
381+
Tracer: newNoopTracer(),
382+
HistoryLength: defaultRequestKeyLimit,
383+
NodeCacheSize: defaultRequestKeyLimit,
384+
},
392385
)
393386
require.NoError(t, err)
394-
395387
verificationDB, err := merkledb.New(
396388
context.Background(),
397389
memdb.New(),
398-
newDefaultDBConfig(),
390+
merkledb.Config{
391+
Tracer: newNoopTracer(),
392+
HistoryLength: defaultRequestKeyLimit,
393+
NodeCacheSize: defaultRequestKeyLimit,
394+
},
399395
)
400396
require.NoError(t, err)
401397
startRoot, err := trieDB.GetMerkleRoot(context.Background())

0 commit comments

Comments
 (0)