Skip to content

Commit

Permalink
fix: recover node buffer list trie nodes for graceful kill
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Nov 15, 2024
1 parent 166b96b commit 443bfd8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion triedb/pathdb/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (db *Database) loadLayers() layer {
if err == nil {
return head
}
log.Error("print load journal error", "error", err)
// journal is not matched(or missing) with the persistent state, discard
// it. Display log for discarding journal, but try to avoid showing
// useless information when the db is created from scratch.
Expand Down Expand Up @@ -368,9 +369,11 @@ func (db *Database) loadDiskLayer(r *rlp.Stream, journalTypeForReader JournalTyp
return nil, err
}

if db.config.TrieNodeBufferType == NodeBufferList {
if db.config.TrieNodeBufferType == NodeBufferList && !db.useBase {
recoveredRoot, recoveredStateID, _ := nb.getLatestStatus()
if recoveredRoot != root && recoveredStateID != id {
log.Error("unequal state root and state id")
fmt.Println("recoveredRoot, root, recoveredStateID, id", recoveredRoot, root, recoveredStateID, id)
return nil, errors.New("Unmatched root and state id with recovered")
}

Expand Down
6 changes: 3 additions & 3 deletions triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ func newNodeBufferList(
log.Crit("Use unopened freezer db to recover node buffer list")
}

err := nf.recoverNodeBufferList(db, freezer)
if err != nil {
if err := nf.recoverNodeBufferList(freezer); err != nil {
log.Error("Failed to recover node buffer list", "error", err)
return nil, err
}
Expand All @@ -154,7 +153,7 @@ func newNodeBufferList(
}

// recoverNodeBufferList recovers node buffer list
func (nf *nodebufferlist) recoverNodeBufferList(db ethdb.Database, freezer *rawdb.ResettableFreezer) error {
func (nf *nodebufferlist) recoverNodeBufferList(freezer *rawdb.ResettableFreezer) error {
head, err := freezer.Ancients()
if err != nil {
log.Error("Failed to get freezer ancients", "error", err)
Expand All @@ -165,6 +164,7 @@ func (nf *nodebufferlist) recoverNodeBufferList(db ethdb.Database, freezer *rawd
log.Error("Failed to get freezer tail", "error", err)
return err
}
fmt.Println()
log.Info("Ancient db meta info", "persistent_state_id", nf.persistID, "head_state_id", head,
"tail_state_id", tail, "waiting_recover_num", head-nf.persistID)

Expand Down

0 comments on commit 443bfd8

Please sign in to comment.