Skip to content

Commit 113e09c

Browse files
authored
Merge pull request #17 from lochjin/v1.10.21-qng
Pick ethereum ethereum#26245 ethereum#26251
2 parents 9a99756 + dba8946 commit 113e09c

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

core/rawdb/freezer.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,30 +321,35 @@ func (f *Freezer) Sync() error {
321321
return nil
322322
}
323323

324-
// validate checks that every table has the same length.
324+
// validate checks that every table has the same boundary.
325325
// Used instead of `repair` in readonly mode.
326326
func (f *Freezer) validate() error {
327327
if len(f.tables) == 0 {
328328
return nil
329329
}
330330
var (
331-
length uint64
332-
name string
331+
head uint64
332+
tail uint64
333+
name string
333334
)
334-
// Hack to get length of any table
335+
// Hack to get boundary of any table
335336
for kind, table := range f.tables {
336-
length = atomic.LoadUint64(&table.items)
337+
head = atomic.LoadUint64(&table.items)
338+
tail = atomic.LoadUint64(&table.itemHidden)
337339
name = kind
338340
break
339341
}
340-
// Now check every table against that length
342+
// Now check every table against those boundaries.
341343
for kind, table := range f.tables {
342-
items := atomic.LoadUint64(&table.items)
343-
if length != items {
344-
return fmt.Errorf("freezer tables %s and %s have differing lengths: %d != %d", kind, name, items, length)
344+
if head != atomic.LoadUint64(&table.items) {
345+
return fmt.Errorf("freezer tables %s and %s have differing head: %d != %d", kind, name, atomic.LoadUint64(&table.items), head)
346+
}
347+
if tail != atomic.LoadUint64(&table.itemHidden) {
348+
return fmt.Errorf("freezer tables %s and %s have differing tail: %d != %d", kind, name, atomic.LoadUint64(&table.itemHidden), tail)
345349
}
346350
}
347-
atomic.StoreUint64(&f.frozen, length)
351+
atomic.StoreUint64(&f.frozen, head)
352+
atomic.StoreUint64(&f.tail, tail)
348353
return nil
349354
}
350355

core/rawdb/freezer_table.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,20 @@ func (t *freezerTable) advanceHead() error {
875875
// Sync pushes any pending data from memory out to disk. This is an expensive
876876
// operation, so use it with care.
877877
func (t *freezerTable) Sync() error {
878-
if err := t.index.Sync(); err != nil {
879-
return err
880-
}
881-
if err := t.meta.Sync(); err != nil {
882-
return err
878+
t.lock.Lock()
879+
defer t.lock.Unlock()
880+
881+
var err error
882+
trackError := func(e error) {
883+
if e != nil && err == nil {
884+
err = e
885+
}
883886
}
884-
return t.head.Sync()
887+
888+
trackError(t.index.Sync())
889+
trackError(t.meta.Sync())
890+
trackError(t.head.Sync())
891+
return err
885892
}
886893

887894
// DumpIndex is a debug print utility function, mainly for testing. It can also

0 commit comments

Comments
 (0)