From d573f5c85f7afddcfcce3b7e42d7ef9ca4117c5e Mon Sep 17 00:00:00 2001 From: VM Date: Fri, 13 Sep 2024 10:48:57 +0800 Subject: [PATCH] test: fix pathdb unit test --- triedb/pathdb/nodebufferlist.go | 36 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/triedb/pathdb/nodebufferlist.go b/triedb/pathdb/nodebufferlist.go index 056b48f74d..2ada782d24 100644 --- a/triedb/pathdb/nodebufferlist.go +++ b/triedb/pathdb/nodebufferlist.go @@ -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() @@ -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() @@ -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