diff --git a/__debug_bin b/__debug_bin new file mode 100755 index 000000000..6144a6947 Binary files /dev/null and b/__debug_bin differ diff --git a/batch.go b/batch.go index 53528284d..77dd046a5 100644 --- a/batch.go +++ b/batch.go @@ -16,10 +16,13 @@ type BatchWithFlusher struct { var _ dbm.Batch = &BatchWithFlusher{} // Ethereum has found that commit of 100KB is optimal, ref ethereum/go-ethereum#15115 -// var defaultFlushThreshold = 100000 +var DefaultFlushThreshold = 100000 // NewBatchWithFlusher returns new BatchWithFlusher wrapping the passed in batch func NewBatchWithFlusher(db dbm.DB, flushThreshold int) *BatchWithFlusher { + if flushThreshold <= 0 { + panic("flushThreshold can't be zero or negative") + } return &BatchWithFlusher{ db: db, batch: db.NewBatchWithSize(flushThreshold), diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index d37862428..f2edfb6d7 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -27,7 +27,7 @@ func randBytes(length int) []byte { } func prepareTree(b *testing.B, db db.DB, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) { - t, err := iavl.NewMutableTreeWithOpts(db, size, nil, false, log.NewNopLogger()) + t, err := iavl.NewMutableTreeWithOpts(db, size, nil, false, log.NewNopLogger(), iavl.DefaultFlushThreshold) require.NoError(b, err) keys := make([][]byte, size) diff --git a/immutable_tree.go b/immutable_tree.go index 04adf20fb..f16f5860a 100644 --- a/immutable_tree.go +++ b/immutable_tree.go @@ -38,7 +38,8 @@ func NewImmutableTreeWithOpts(db dbm.DB, cacheSize int, opts *Options, skipFastS return &ImmutableTree{ logger: lg, // NodeDB-backed Tree. - ndb: newNodeDB(db, cacheSize, opts, lg), + // flushthreshold is 0 since there's no batch commit action. + ndb: newNodeDB(db, cacheSize, opts, lg, 0), skipFastStorageUpgrade: skipFastStorageUpgrade, } } diff --git a/import.go b/import.go index 8e177de5b..1a9977dfe 100644 --- a/import.go +++ b/import.go @@ -48,7 +48,7 @@ func newImporter(tree *MutableTree, version int64) (*Importer, error) { return &Importer{ tree: tree, version: version, - batch: tree.ndb.db.NewBatch(), + batch: NewBatch(tree.ndb.db, tree.ndb.flushThreshold), stack: make([]*Node, 0, 8), nonces: make([]int32, version+1), }, nil @@ -84,7 +84,7 @@ func (i *Importer) writeNode(node *Node) error { return err } i.batch.Close() - i.batch = i.tree.ndb.db.NewBatch() + i.batch = NewBatch(i.tree.ndb.db, i.tree.ndb.flushThreshold) i.batchSize = 0 } diff --git a/iterator_test.go b/iterator_test.go index 4b94409c6..3d6196f62 100644 --- a/iterator_test.go +++ b/iterator_test.go @@ -369,7 +369,7 @@ func TestNodeIterator_Success(t *testing.T) { } func TestNodeIterator_WithEmptyRoot(t *testing.T) { - itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil, log.NewNopLogger())) + itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil, log.NewNopLogger(), 0)) require.NoError(t, err) require.False(t, itr.Valid()) } diff --git a/mutable_tree.go b/mutable_tree.go index a55f54bef..e76fb081c 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -46,12 +46,12 @@ type MutableTree struct { // NewMutableTree returns a new tree with the specified cache size and datastore. func NewMutableTree(db dbm.DB, cacheSize int, skipFastStorageUpgrade bool, lg log.Logger) (*MutableTree, error) { - return NewMutableTreeWithOpts(db, cacheSize, nil, skipFastStorageUpgrade, lg) + return NewMutableTreeWithOpts(db, cacheSize, nil, skipFastStorageUpgrade, lg, DefaultFlushThreshold) } // NewMutableTreeWithOpts returns a new tree with the specified options. -func NewMutableTreeWithOpts(db dbm.DB, cacheSize int, opts *Options, skipFastStorageUpgrade bool, lg log.Logger) (*MutableTree, error) { - ndb := newNodeDB(db, cacheSize, opts, lg) +func NewMutableTreeWithOpts(db dbm.DB, cacheSize int, opts *Options, skipFastStorageUpgrade bool, lg log.Logger, flushThreshold int) (*MutableTree, error) { + ndb := newNodeDB(db, cacheSize, opts, lg, flushThreshold) head := &ImmutableTree{ndb: ndb, skipFastStorageUpgrade: skipFastStorageUpgrade} return &MutableTree{ diff --git a/mutable_tree_test.go b/mutable_tree_test.go index c7f045937..d59e13a79 100644 --- a/mutable_tree_test.go +++ b/mutable_tree_test.go @@ -258,7 +258,7 @@ func TestMutableTree_LoadVersion_Empty(t *testing.T) { func TestMutableTree_InitialVersion(t *testing.T) { memDB := db.NewMemDB() - tree, err := NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 9}, false, log.NewNopLogger()) + tree, err := NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 9}, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) _, err = tree.Set([]byte("a"), []byte{0x01}) @@ -274,20 +274,20 @@ func TestMutableTree_InitialVersion(t *testing.T) { assert.EqualValues(t, 10, version) // Reloading the tree with the same initial version is fine - tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 9}, false, log.NewNopLogger()) + tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 9}, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) version, err = tree.Load() require.NoError(t, err) assert.EqualValues(t, 10, version) // Reloading the tree with an initial version beyond the lowest should error - tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 10}, false, log.NewNopLogger()) + tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 10}, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) _, err = tree.Load() require.Error(t, err) // Reloading the tree with a lower initial version is fine, and new versions can be produced - tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 3}, false, log.NewNopLogger()) + tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 3}, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) version, err = tree.Load() require.NoError(t, err) @@ -813,7 +813,7 @@ func TestUpgradeStorageToFast_DbErrorConstructor_Failure(t *testing.T) { expectedError := errors.New("some db error") dbMock.EXPECT().Get(gomock.Any()).Return(nil, expectedError).Times(1) - dbMock.EXPECT().NewBatch().Return(nil).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(nil).Times(1) dbMock.EXPECT().ReverseIterator(gomock.Any(), gomock.Any()).Return(rIterMock, nil).Times(1) tree, err := NewMutableTree(dbMock, 0, false, log.NewNopLogger()) @@ -835,12 +835,12 @@ func TestUpgradeStorageToFast_DbErrorEnableFastStorage_Failure(t *testing.T) { rIterMock.EXPECT().Key().Return(nodeKeyFormat.Key(1)) rIterMock.EXPECT().Close().Return(nil).Times(1) - expectedError := errors.New("some db error") + expectedError := errors.New("some error") batchMock := mock.NewMockBatch(ctrl) dbMock.EXPECT().Get(gomock.Any()).Return(nil, nil).Times(1) - dbMock.EXPECT().NewBatch().Return(batchMock).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(batchMock).Times(1) dbMock.EXPECT().ReverseIterator(gomock.Any(), gomock.Any()).Return(rIterMock, nil).Times(1) iterMock := mock.NewMockIterator(ctrl) @@ -849,6 +849,7 @@ func TestUpgradeStorageToFast_DbErrorEnableFastStorage_Failure(t *testing.T) { iterMock.EXPECT().Valid().Times(2) iterMock.EXPECT().Close() + batchMock.EXPECT().GetByteSize().Return(100, nil).Times(1) batchMock.EXPECT().Set(gomock.Any(), gomock.Any()).Return(expectedError).Times(1) tree, err := NewMutableTree(dbMock, 0, false, log.NewNopLogger()) @@ -889,7 +890,7 @@ func TestFastStorageReUpgradeProtection_NoForceUpgrade_Success(t *testing.T) { batchMock := mock.NewMockBatch(ctrl) dbMock.EXPECT().Get(gomock.Any()).Return(expectedStorageVersion, nil).Times(1) - dbMock.EXPECT().NewBatch().Return(batchMock).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(batchMock).Times(1) dbMock.EXPECT().ReverseIterator(gomock.Any(), gomock.Any()).Return(rIterMock, nil).Times(1) // called to get latest version tree, err := NewMutableTree(dbMock, 0, false, log.NewNopLogger()) @@ -937,7 +938,7 @@ func TestFastStorageReUpgradeProtection_ForceUpgradeFirstTime_NoForceSecondTime_ // dbMock represents the underlying database under the hood of nodeDB dbMock.EXPECT().Get(gomock.Any()).Return(expectedStorageVersion, nil).Times(1) - dbMock.EXPECT().NewBatch().Return(batchMock).Times(3) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(batchMock).Times(3) dbMock.EXPECT().ReverseIterator(gomock.Any(), gomock.Any()).Return(rIterMock, nil).Times(1) // called to get latest version startFormat := fastKeyFormat.Key() endFormat := fastKeyFormat.Key() @@ -956,6 +957,7 @@ func TestFastStorageReUpgradeProtection_ForceUpgradeFirstTime_NoForceSecondTime_ updatedExpectedStorageVersion := make([]byte, len(expectedStorageVersion)) copy(updatedExpectedStorageVersion, expectedStorageVersion) updatedExpectedStorageVersion[len(updatedExpectedStorageVersion)-1]++ + batchMock.EXPECT().GetByteSize().Return(100, nil).Times(2) batchMock.EXPECT().Delete(fastKeyFormat.Key(fastNodeKeyToDelete)).Return(nil).Times(1) batchMock.EXPECT().Set(metadataKeyFormat.Key([]byte(storageVersionKey)), updatedExpectedStorageVersion).Return(nil).Times(1) batchMock.EXPECT().Write().Return(nil).Times(2) @@ -1438,7 +1440,7 @@ func TestMutableTree_InitialVersion_FirstVersion(t *testing.T) { initialVersion := int64(1000) tree, err := NewMutableTreeWithOpts(db, 0, &Options{ InitialVersion: uint64(initialVersion), - }, true, log.NewNopLogger()) + }, true, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) _, err = tree.Set([]byte("hello"), []byte("world")) diff --git a/nodedb.go b/nodedb.go index c1bfd6304..236c2e6a7 100644 --- a/nodedb.go +++ b/nodedb.go @@ -70,9 +70,10 @@ type nodeDB struct { latestVersion int64 // Latest version of nodeDB. nodeCache cache.Cache // Cache for nodes in the regular tree that consists of key-value pairs at any version. fastNodeCache cache.Cache // Cache for nodes in the fast index that represents only key-value pairs at the latest version. + flushThreshold int } -func newNodeDB(db dbm.DB, cacheSize int, opts *Options, lg log.Logger) *nodeDB { +func newNodeDB(db dbm.DB, cacheSize int, opts *Options, lg log.Logger, flushThreshold int) *nodeDB { if opts == nil { o := DefaultOptions() opts = &o @@ -87,7 +88,7 @@ func newNodeDB(db dbm.DB, cacheSize int, opts *Options, lg log.Logger) *nodeDB { return &nodeDB{ logger: lg, db: db, - batch: db.NewBatch(), + batch: NewBatch(db, flushThreshold), opts: *opts, firstVersion: 0, latestVersion: 0, // initially invalid @@ -95,6 +96,7 @@ func newNodeDB(db dbm.DB, cacheSize int, opts *Options, lg log.Logger) *nodeDB { fastNodeCache: cache.New(fastNodeCacheSize), versionReaders: make(map[int64]uint32, 8), storageVersion: string(storeVersion), + flushThreshold: flushThreshold, } } @@ -135,6 +137,14 @@ func (ndb *nodeDB) GetNode(nk *NodeKey) (*Node, error) { return node, nil } +func NewBatch(db dbm.DB, flushThreshold int) dbm.Batch { + if flushThreshold == 0 { + return db.NewBatch() + } else { + return NewBatchWithFlusher(db, flushThreshold) + } +} + func (ndb *nodeDB) GetFastNode(key []byte) (*fastnode.Node, error) { if !ndb.hasUpgradedToFastStorage() { return nil, errors.New("storage version is not fast") @@ -351,7 +361,7 @@ func (ndb *nodeDB) writeBatch() error { return err } - ndb.batch = ndb.db.NewBatch() + ndb.batch = NewBatch(ndb.db, ndb.flushThreshold) return nil } @@ -642,7 +652,7 @@ func (ndb *nodeDB) Commit() error { } ndb.batch.Close() - ndb.batch = ndb.db.NewBatch() + ndb.batch = NewBatch(ndb.db, ndb.flushThreshold) return nil } diff --git a/nodedb_test.go b/nodedb_test.go index 4f14c68c1..aaf409b3d 100644 --- a/nodedb_test.go +++ b/nodedb_test.go @@ -46,9 +46,9 @@ func TestNewNoDbStorage_StorageVersionInDb_Success(t *testing.T) { dbMock := mock.NewMockDB(ctrl) dbMock.EXPECT().Get(gomock.Any()).Return([]byte(expectedVersion), nil).Times(1) - dbMock.EXPECT().NewBatch().Return(nil).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(nil).Times(1) - ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) require.Equal(t, expectedVersion, ndb.storageVersion) } @@ -59,9 +59,9 @@ func TestNewNoDbStorage_ErrorInConstructor_DefaultSet(t *testing.T) { dbMock := mock.NewMockDB(ctrl) dbMock.EXPECT().Get(gomock.Any()).Return(nil, errors.New("some db error")).Times(1) - dbMock.EXPECT().NewBatch().Return(nil).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(nil).Times(1) - ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) require.Equal(t, expectedVersion, ndb.getStorageVersion()) } @@ -72,9 +72,9 @@ func TestNewNoDbStorage_DoesNotExist_DefaultSet(t *testing.T) { dbMock := mock.NewMockDB(ctrl) dbMock.EXPECT().Get(gomock.Any()).Return(nil, nil).Times(1) - dbMock.EXPECT().NewBatch().Return(nil).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(nil).Times(1) - ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) require.Equal(t, expectedVersion, ndb.getStorageVersion()) } @@ -83,7 +83,7 @@ func TestSetStorageVersion_Success(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) require.Equal(t, defaultStorageVersionValue, ndb.getStorageVersion()) err := ndb.setFastStorageVersionToBatch() @@ -106,7 +106,7 @@ func TestSetStorageVersion_DBFailure_OldKept(t *testing.T) { expectedFastCacheVersion := 2 dbMock.EXPECT().Get(gomock.Any()).Return([]byte(defaultStorageVersionValue), nil).Times(1) - dbMock.EXPECT().NewBatch().Return(batchMock).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(batchMock).Times(1) // rIterMock is used to get the latest version from disk. We are mocking that rIterMock returns latestTreeVersion from disk rIterMock.EXPECT().Valid().Return(true).Times(1) @@ -114,9 +114,10 @@ func TestSetStorageVersion_DBFailure_OldKept(t *testing.T) { rIterMock.EXPECT().Close().Return(nil).Times(1) dbMock.EXPECT().ReverseIterator(gomock.Any(), gomock.Any()).Return(rIterMock, nil).Times(1) + batchMock.EXPECT().GetByteSize().Return(100, nil).Times(1) batchMock.EXPECT().Set(metadataKeyFormat.Key([]byte(storageVersionKey)), []byte(fastStorageVersionValue+fastStorageVersionDelimiter+strconv.Itoa(expectedFastCacheVersion))).Return(errors.New(expectedErrorMsg)).Times(1) - ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) require.Equal(t, defaultStorageVersionValue, ndb.getStorageVersion()) err := ndb.setFastStorageVersionToBatch() @@ -135,9 +136,9 @@ func TestSetStorageVersion_InvalidVersionFailure_OldKept(t *testing.T) { invalidStorageVersion := fastStorageVersionValue + fastStorageVersionDelimiter + "1" + fastStorageVersionDelimiter + "2" dbMock.EXPECT().Get(gomock.Any()).Return([]byte(invalidStorageVersion), nil).Times(1) - dbMock.EXPECT().NewBatch().Return(batchMock).Times(1) + dbMock.EXPECT().NewBatchWithSize(gomock.Any()).Return(batchMock).Times(1) - ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(dbMock, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) require.Equal(t, invalidStorageVersion, ndb.getStorageVersion()) err := ndb.setFastStorageVersionToBatch() @@ -148,7 +149,7 @@ func TestSetStorageVersion_InvalidVersionFailure_OldKept(t *testing.T) { func TestSetStorageVersion_FastVersionFirst_VersionAppended(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.storageVersion = fastStorageVersionValue ndb.latestVersion = 100 @@ -159,7 +160,7 @@ func TestSetStorageVersion_FastVersionFirst_VersionAppended(t *testing.T) { func TestSetStorageVersion_FastVersionSecond_VersionAppended(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 storageVersionBytes := []byte(fastStorageVersionValue) @@ -173,7 +174,7 @@ func TestSetStorageVersion_FastVersionSecond_VersionAppended(t *testing.T) { func TestSetStorageVersion_SameVersionTwice(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 storageVersionBytes := []byte(fastStorageVersionValue) @@ -193,7 +194,7 @@ func TestSetStorageVersion_SameVersionTwice(t *testing.T) { // Test case where version is incorrect and has some extra garbage at the end func TestShouldForceFastStorageUpdate_DefaultVersion_True(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.storageVersion = defaultStorageVersionValue ndb.latestVersion = 100 @@ -204,7 +205,7 @@ func TestShouldForceFastStorageUpdate_DefaultVersion_True(t *testing.T) { func TestShouldForceFastStorageUpdate_FastVersion_Greater_True(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 ndb.storageVersion = fastStorageVersionValue + fastStorageVersionDelimiter + strconv.Itoa(int(ndb.latestVersion+1)) @@ -215,7 +216,7 @@ func TestShouldForceFastStorageUpdate_FastVersion_Greater_True(t *testing.T) { func TestShouldForceFastStorageUpdate_FastVersion_Smaller_True(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 ndb.storageVersion = fastStorageVersionValue + fastStorageVersionDelimiter + strconv.Itoa(int(ndb.latestVersion-1)) @@ -226,7 +227,7 @@ func TestShouldForceFastStorageUpdate_FastVersion_Smaller_True(t *testing.T) { func TestShouldForceFastStorageUpdate_FastVersion_Match_False(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 ndb.storageVersion = fastStorageVersionValue + fastStorageVersionDelimiter + strconv.Itoa(int(ndb.latestVersion)) @@ -237,7 +238,7 @@ func TestShouldForceFastStorageUpdate_FastVersion_Match_False(t *testing.T) { func TestIsFastStorageEnabled_True(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 ndb.storageVersion = fastStorageVersionValue + fastStorageVersionDelimiter + strconv.Itoa(int(ndb.latestVersion)) @@ -246,7 +247,7 @@ func TestIsFastStorageEnabled_True(t *testing.T) { func TestIsFastStorageEnabled_False(t *testing.T) { db := db.NewMemDB() - ndb := newNodeDB(db, 0, nil, log.NewNopLogger()) + ndb := newNodeDB(db, 0, nil, log.NewNopLogger(), DefaultFlushThreshold) ndb.latestVersion = 100 ndb.storageVersion = defaultStorageVersionValue @@ -383,7 +384,7 @@ func TestNodeDB_traverseOrphans(t *testing.T) { func makeAndPopulateMutableTree(tb testing.TB) *MutableTree { memDB := db.NewMemDB() - tree, err := NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 9}, false, log.NewNopLogger()) + tree, err := NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 9}, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(tb, err) for i := 0; i < 1e4; i++ { diff --git a/proof_iavl_test.go b/proof_iavl_test.go index 8c77097ee..dbc208e73 100644 --- a/proof_iavl_test.go +++ b/proof_iavl_test.go @@ -10,7 +10,7 @@ import ( ) func TestProofOp(t *testing.T) { - tree, err := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil, false, log.NewNopLogger()) + tree, err := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) keys := []byte{0x0a, 0x11, 0x2e, 0x32, 0x50, 0x72, 0x99, 0xa1, 0xe4, 0xf7} // 10 total. for _, ikey := range keys { diff --git a/testutils_test.go b/testutils_test.go index 2370b36b4..28180b1b4 100644 --- a/testutils_test.go +++ b/testutils_test.go @@ -43,7 +43,7 @@ func b2i(bz []byte) int { // Construct a MutableTree func getTestTree(cacheSize int) (*MutableTree, error) { - return NewMutableTreeWithOpts(db.NewMemDB(), cacheSize, nil, false, log.NewNopLogger()) + return NewMutableTreeWithOpts(db.NewMemDB(), cacheSize, nil, false, log.NewNopLogger(), DefaultFlushThreshold) } // Convenience for a new node diff --git a/tree_random_test.go b/tree_random_test.go index 22c0d237f..3026c1ba6 100644 --- a/tree_random_test.go +++ b/tree_random_test.go @@ -80,7 +80,7 @@ func testRandomOperations(t *testing.T, randSeed int64) { if !(r.Float64() < cacheChance) { cacheSize = 0 } - tree, err = NewMutableTreeWithOpts(levelDB, cacheSize, options, false, log.NewNopLogger()) + tree, err = NewMutableTreeWithOpts(levelDB, cacheSize, options, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) version, err = tree.Load() require.NoError(t, err) diff --git a/tree_test.go b/tree_test.go index 4042254e0..0d34fb9c2 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1535,7 +1535,7 @@ func BenchmarkTreeLoadAndDelete(b *testing.B) { func TestLoadVersionForOverwritingCase2(t *testing.T) { require := require.New(t) - tree, _ := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil, false, log.NewNopLogger()) + tree, _ := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil, false, log.NewNopLogger(), DefaultFlushThreshold) for i := byte(0); i < 20; i++ { tree.Set([]byte{i}, []byte{i}) @@ -1597,7 +1597,7 @@ func TestLoadVersionForOverwritingCase2(t *testing.T) { func TestLoadVersionForOverwritingCase3(t *testing.T) { require := require.New(t) - tree, err := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil, false, log.NewNopLogger()) + tree, err := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(err) for i := byte(0); i < 20; i++ { @@ -1856,7 +1856,7 @@ func TestNodeCacheStatisic(t *testing.T) { opts := &Options{Stat: stat} db, err := db.NewDB("test", db.MemDBBackend, "") require.NoError(t, err) - mt, err := NewMutableTreeWithOpts(db, tc.cacheSize, opts, false, log.NewNopLogger()) + mt, err := NewMutableTreeWithOpts(db, tc.cacheSize, opts, false, log.NewNopLogger(), DefaultFlushThreshold) require.NoError(t, err) for i := 0; i < numKeyVals; i++ {