Patch for concurrent iterator & others (onto v1.11.6) #386

Closed
roysc wants to merge 1565 commits from v1.11.6-statediff-v5 into master
2 changed files with 8 additions and 1 deletions
Showing only changes of commit bb9f9ccf4f - Show all commits

View File

@ -197,7 +197,11 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
} }
// Freezer is consistent with the key-value database, permit combining the two // Freezer is consistent with the key-value database, permit combining the two
if !frdb.readonly { if !frdb.readonly {
go frdb.freeze(db) frdb.wg.Add(1)
go func() {
frdb.freeze(db)
frdb.wg.Done()
}()
} }
return &freezerdb{ return &freezerdb{
KeyValueStore: db, KeyValueStore: db,

View File

@ -84,6 +84,7 @@ type freezer struct {
trigger chan chan struct{} // Manual blocking freeze trigger, test determinism trigger chan chan struct{} // Manual blocking freeze trigger, test determinism
quit chan struct{} quit chan struct{}
wg sync.WaitGroup
closeOnce sync.Once closeOnce sync.Once
} }
@ -145,6 +146,8 @@ func (f *freezer) Close() error {
var errs []error var errs []error
f.closeOnce.Do(func() { f.closeOnce.Do(func() {
close(f.quit) close(f.quit)
// Wait for any background freezing to stop
f.wg.Wait()
for _, table := range f.tables { for _, table := range f.tables {
if err := table.Close(); err != nil { if err := table.Close(); err != nil {
errs = append(errs, err) errs = append(errs, err)