Skip to content

Commit

Permalink
Merge pull request #17 from lochjin/v1.10.21-qng
Browse files Browse the repository at this point in the history
  • Loading branch information
dindinw authored Nov 28, 2022
2 parents 9a99756 + dba8946 commit 113e09c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
25 changes: 15 additions & 10 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,30 +321,35 @@ func (f *Freezer) Sync() error {
return nil
}

// validate checks that every table has the same length.
// validate checks that every table has the same boundary.
// Used instead of `repair` in readonly mode.
func (f *Freezer) validate() error {
if len(f.tables) == 0 {
return nil
}
var (
length uint64
name string
head uint64
tail uint64
name string
)
// Hack to get length of any table
// Hack to get boundary of any table
for kind, table := range f.tables {
length = atomic.LoadUint64(&table.items)
head = atomic.LoadUint64(&table.items)
tail = atomic.LoadUint64(&table.itemHidden)
name = kind
break
}
// Now check every table against that length
// Now check every table against those boundaries.
for kind, table := range f.tables {
items := atomic.LoadUint64(&table.items)
if length != items {
return fmt.Errorf("freezer tables %s and %s have differing lengths: %d != %d", kind, name, items, length)
if head != atomic.LoadUint64(&table.items) {
return fmt.Errorf("freezer tables %s and %s have differing head: %d != %d", kind, name, atomic.LoadUint64(&table.items), head)
}
if tail != atomic.LoadUint64(&table.itemHidden) {
return fmt.Errorf("freezer tables %s and %s have differing tail: %d != %d", kind, name, atomic.LoadUint64(&table.itemHidden), tail)
}
}
atomic.StoreUint64(&f.frozen, length)
atomic.StoreUint64(&f.frozen, head)
atomic.StoreUint64(&f.tail, tail)
return nil
}

Expand Down
19 changes: 13 additions & 6 deletions core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,20 @@ func (t *freezerTable) advanceHead() error {
// Sync pushes any pending data from memory out to disk. This is an expensive
// operation, so use it with care.
func (t *freezerTable) Sync() error {
if err := t.index.Sync(); err != nil {
return err
}
if err := t.meta.Sync(); err != nil {
return err
t.lock.Lock()
defer t.lock.Unlock()

var err error
trackError := func(e error) {
if e != nil && err == nil {
err = e
}
}
return t.head.Sync()

trackError(t.index.Sync())
trackError(t.meta.Sync())
trackError(t.head.Sync())
return err
}

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

0 comments on commit 113e09c

Please sign in to comment.