Skip to content

Commit

Permalink
fix: fix pbss async node buffer force flush buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Feb 10, 2025
1 parent afe4ba0 commit 705d4ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion triedb/pathdb/asyncnodebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (a *asyncnodebuffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWri

if force {
for {
if atomic.LoadUint64(&a.background.immutable) == 1 {
if atomic.LoadUint64(&a.background.immutable) == 1 || atomic.LoadUint64(&a.current.immutable) == 1 {
time.Sleep(time.Duration(DefaultBackgroundFlushInterval) * time.Second)
log.Info("Waiting background memory table flushed into disk for forcing flush node buffer")
continue
Expand Down
13 changes: 9 additions & 4 deletions triedb/pathdb/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ func TestDatabaseRollback(t *testing.T) {

// Verify state histories
tester := newTester(t, 0, false, 32)
bottom := tester.db.tree.bottom()
if err := bottom.buffer.flush(tester.db.diskdb, tester.db.freezer, bottom.nodes, bottom.id, true); err != nil {
t.Fatalf("Failed to force flush: %v", err)
}
defer tester.release()

if err := tester.verifyHistory(); err != nil {
Expand Down Expand Up @@ -520,17 +524,18 @@ func TestDatabaseRecoverable(t *testing.T) {
}
}

// TODO(joey): fail when using asyncbuffer
//
//nolint:unused
func testDisable(t *testing.T) {
func TestDisable(t *testing.T) {
// Redefine the diff layer depth allowance for faster testing.
maxDiffLayers = 4
defer func() {
maxDiffLayers = 128
}()

tester := newTester(t, 0, false, 32)
bottom := tester.db.tree.bottom()
if err := bottom.buffer.flush(tester.db.diskdb, tester.db.freezer, nil, bottom.id, true); err != nil {
t.Fatalf("Failed to force flush: %v", err)
}
defer tester.release()

stored := crypto.Keccak256Hash(rawdb.ReadAccountTrieNode(tester.db.diskdb, nil))
Expand Down

0 comments on commit 705d4ab

Please sign in to comment.