Skip to content

Commit

Permalink
feat: journal nodebufferlist snapshot data for journal file recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Nov 24, 2024
1 parent 1901f6d commit 6528148
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewFreezer(datadir string, namespace string, readonly, writeTrieNode bool,
// Create the tables.
for name, disableSnappy := range tables {
if name == stateHistoryTrieNodesData && !writeTrieNode {
log.Info("Not create trie node data")
log.Info("Not create trie node data in freezer db")
continue
}
table, err := newTable(datadir, name, readMeter, writeMeter, sizeGauge, maxTableSize, disableSnappy, readonly)
Expand Down
26 changes: 4 additions & 22 deletions triedb/pathdb/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ func (db *Database) loadDiskLayer(r *rlp.Stream, journalTypeForReader JournalTyp
return nil, fmt.Errorf("invalid state id: stored %d resolved %d", stored, id)
}

log.Info("load disk layer decode info", "stored id", stored, "root", root)

var nodes map[common.Hash]map[string]*trienode.Node
var nodesArray []nblJournalData

Expand All @@ -357,19 +359,7 @@ func (db *Database) loadDiskLayer(r *rlp.Stream, journalTypeForReader JournalTyp
if err := journalBuf.Decode(&encoded); err != nil {
return nil, fmt.Errorf("failed to load disk nodes: %v", err)
}
nodes = make(map[common.Hash]map[string]*trienode.Node)
// todo: use flatten function
for _, entry := range encoded {
subset := make(map[string]*trienode.Node)
for _, n := range entry.Nodes {
if len(n.Blob) > 0 {
subset[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob)
} else {
subset[string(n.Path)] = trienode.NewDeleted()
}
}
nodes[entry.Owner] = subset
}
nodes = flattenTrieNodes(encoded)
}

if journalTypeForReader == JournalFileType {
Expand Down Expand Up @@ -531,15 +521,7 @@ func (dl *diskLayer) journal(w io.Writer, journalType JournalType) error {
}
log.Info("Journal file and node buffer list", "multi layer nodes count", len(nodes))
} else {
bufferNodes := dl.buffer.getAllNodes()
nodes := make([]journalNodes, 0, len(bufferNodes))
for owner, subset := range bufferNodes {
entry := journalNodes{Owner: owner}
for path, node := range subset {
entry.Nodes = append(entry.Nodes, journalNode{Path: []byte(path), Blob: node.Blob})
}
nodes = append(nodes, entry)
}
nodes := compressTrieNodes(dl.buffer.getAllNodes())
if err := rlp.Encode(journalBuf, nodes); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func (nf *nodebufferlist) recoverJournalData(nodesArray []nblJournalData) {
mdl := newMultiDifflayer(nf.limit, nodesArray[i].size, nodesArray[i].root, flattenTrieNodes(nodesArray[i].nodes), nodesArray[i].layers)
nf.pushFront(mdl)
}
nf.count = uint64(length)
nf.count = uint64(length) - 1
log.Info("recover journal data", "nf count", nf.count, "node array", len(nodesArray))
}

Expand Down

0 comments on commit 6528148

Please sign in to comment.