Skip to content

Commit

Permalink
move the invariant properties into a common method
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Dec 31, 2023
1 parent c1eb992 commit b18e793
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tx_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ func (tx *Tx) recursivelyCheckBucket(b *Bucket, reachable map[common.Pgid]*commo
return
}

// Check every page used by this bucket.
b.tx.forEachPage(b.RootPage(), func(p *common.Page, _ int, stack []common.Pgid) {
verifyPageReachable(p, tx.meta.Pgid(), stack, reachable, freed, ch)
})

tx.recursivelyCheckPageKeyOrder(b.RootPage(), kvStringer.KeyToString, ch)
tx.checkInvariantProperties(b.RootPage(), reachable, freed, kvStringer, ch)

// Check each bucket within this bucket.
_ = b.ForEachBucket(func(k []byte) error {
Expand All @@ -94,6 +89,15 @@ func (tx *Tx) recursivelyCheckBucket(b *Bucket, reachable map[common.Pgid]*commo
})
}

func (tx *Tx) checkInvariantProperties(pageId common.Pgid, reachable map[common.Pgid]*common.Page, freed map[common.Pgid]bool,
kvStringer KVStringer, ch chan error) {
tx.forEachPage(pageId, func(p *common.Page, _ int, stack []common.Pgid) {
verifyPageReachable(p, tx.meta.Pgid(), stack, reachable, freed, ch)
})

tx.recursivelyCheckPageKeyOrder(pageId, kvStringer.KeyToString, ch)
}

func verifyPageReachable(p *common.Page, hwm common.Pgid, stack []common.Pgid, reachable map[common.Pgid]*common.Page, freed map[common.Pgid]bool, ch chan error) {
if p.Id() > hwm {
ch <- fmt.Errorf("page %d: out of bounds: %d (stack: %v)", int(p.Id()), int(hwm), stack)
Expand Down

0 comments on commit b18e793

Please sign in to comment.