Skip to content

Commit

Permalink
test: close nodebuffer in db close
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Apr 10, 2024
1 parent 65d6474 commit 2f5a1bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions trie/triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func (db *Database) Close() error {
// Release the memory held by clean cache.
db.tree.bottom().resetCache()

db.tree.bottom().buffer.waitAndStopFlushing()
// Close the attached state history freezer.
if db.freezer == nil {
return nil
Expand Down
13 changes: 11 additions & 2 deletions trie/triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func newNodeBufferList(
persistID: rawdb.ReadPersistentStateID(db),
stopCh: make(chan struct{}),
}
//go nf.loop()
go nf.loop()

log.Info("new node buffer list", "proposed block interval", nf.wpBlocks,
"reserve multi difflayers", nf.rsevMdNum, "difflayers in multidifflayer", nf.dlInMd,
Expand Down Expand Up @@ -335,7 +335,16 @@ func (nf *nodebufferlist) getLayers() uint64 {

// waitAndStopFlushing will block unit writing the trie nodes of trienodebuffer to disk.
func (nf *nodebufferlist) waitAndStopFlushing() {
close(nf.stopCh)
nf.mux.Lock()
nf.baseMux.Lock()
nf.flushMux.Lock()
defer nf.mux.Unlock()
defer nf.baseMux.Unlock()
defer nf.flushMux.Unlock()
if nf.stopCh != nil {
close(nf.stopCh)
nf.stopCh = nil
}
nf.stopFlushing.Store(true)
for nf.isFlushing.Load() {
time.Sleep(time.Second)
Expand Down

0 comments on commit 2f5a1bb

Please sign in to comment.