Skip to content

Commit

Permalink
test: fix pathdb unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Sep 13, 2024
1 parent d3f0d83 commit d573f5c
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,16 @@ func (nf *nodebufferlist) commit(root common.Hash, id uint64, block uint64, node
defer nf.mux.Unlock()

if nf.useBase.Load() {
nf.checkFlushing()
for {
if nf.isFlushing.Swap(true) {
time.Sleep(time.Duration(DefaultBackgroundFlushInterval) * time.Second)
log.Info("waiting base node buffer to be flushed to disk")
continue
} else {
break
}
}
defer nf.isFlushing.Store(false)

nf.baseMux.Lock()
defer nf.baseMux.Unlock()
Expand Down Expand Up @@ -550,7 +559,16 @@ func (nf *nodebufferlist) getAllNodes() map[common.Hash]map[string]*trienode.Nod

// getLayers return the size of cached difflayers.
func (nf *nodebufferlist) getLayers() uint64 {
nf.checkFlushing()
for {
if nf.isFlushing.Swap(true) {
time.Sleep(time.Duration(DefaultBackgroundFlushInterval) * time.Second)
log.Info("waiting base node buffer to be flushed to disk")
continue
} else {
break
}
}
defer nf.isFlushing.Store(false)

nf.mux.RLock()
nf.baseMux.RLock()
Expand Down Expand Up @@ -852,20 +870,6 @@ func (nf *nodebufferlist) report() {
log.Info("node buffer list info", context...)
}

func (nf *nodebufferlist) checkFlushing() {
for {
if nf.isFlushing.Swap(true) {
time.Sleep(time.Duration(DefaultBackgroundFlushInterval) * time.Second)
log.Info("waiting base node buffer to be flushed to disk")
continue
} else {
break
}
}
defer nf.isFlushing.Store(false)
return
}

var _ layer = &proposedBlockReader{}

// proposedBlockReader implements the layer interface used to read the status of proposed
Expand Down

0 comments on commit d573f5c

Please sign in to comment.