mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
stop and close iterator
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
cd6b23b3a2
commit
b34e366bb4
1 changed files with 5 additions and 8 deletions
|
|
@ -61,7 +61,7 @@ type stateSizeGenerator struct {
|
||||||
|
|
||||||
// Generator state
|
// Generator state
|
||||||
running bool
|
running bool
|
||||||
abort chan chan struct{}
|
abort chan struct{}
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
|
|
||||||
// Metrics state
|
// Metrics state
|
||||||
|
|
@ -74,7 +74,7 @@ func newStateSizeGenerator(db ethdb.KeyValueStore, sdb Database, root common.Has
|
||||||
return &stateSizeGenerator{
|
return &stateSizeGenerator{
|
||||||
db: db,
|
db: db,
|
||||||
sdb: sdb,
|
sdb: sdb,
|
||||||
abort: make(chan chan struct{}),
|
abort: make(chan struct{}),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
metrics: &StateSizeMetrics{Root: root},
|
metrics: &StateSizeMetrics{Root: root},
|
||||||
}
|
}
|
||||||
|
|
@ -95,9 +95,7 @@ func (g *stateSizeGenerator) stop() {
|
||||||
if !g.running {
|
if !g.running {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ch := make(chan struct{})
|
close(g.abort)
|
||||||
g.abort <- ch
|
|
||||||
<-ch
|
|
||||||
g.running = false
|
g.running = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,10 +154,9 @@ func (g *stateSizeGenerator) initializeMetrics() {
|
||||||
count++
|
count++
|
||||||
bytes += uint64(len(iter.Key()) + len(iter.Value()))
|
bytes += uint64(len(iter.Key()) + len(iter.Value()))
|
||||||
|
|
||||||
// Check for abort
|
|
||||||
select {
|
select {
|
||||||
case abort := <-g.abort:
|
case <-g.abort:
|
||||||
close(abort)
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue