Skip to content

Commit

Permalink
Merge pull request #666 from ahrtr/check_channel_20240105
Browse files Browse the repository at this point in the history
Move the closing of channel into the same method of creating the channel
  • Loading branch information
ahrtr authored Jan 6, 2024
2 parents 5725474 + 9cec34d commit 288e823
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tx_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ func (tx *Tx) Check(options ...CheckOption) <-chan error {
}

ch := make(chan error)
go tx.check(chkConfig.kvStringer, ch)
go func() {
// Close the channel to signal completion.
defer close(ch)
tx.check(chkConfig, ch)
}()
return ch
}

func (tx *Tx) check(kvStringer KVStringer, ch chan error) {
func (tx *Tx) check(cfg checkConfig, ch chan error) {
// Force loading free list if opened in ReadOnly mode.
tx.db.loadFreelist()

Expand All @@ -57,7 +61,7 @@ func (tx *Tx) check(kvStringer KVStringer, ch chan error) {
}

// Recursively check buckets.
tx.recursivelyCheckBucket(&tx.root, reachable, freed, kvStringer, ch)
tx.recursivelyCheckBucket(&tx.root, reachable, freed, cfg.kvStringer, ch)

// Ensure all pages below high water mark are either reachable or freed.
for i := common.Pgid(0); i < tx.meta.Pgid(); i++ {
Expand All @@ -66,9 +70,6 @@ func (tx *Tx) check(kvStringer KVStringer, ch chan error) {
ch <- fmt.Errorf("page %d: unreachable unfreed", int(i))
}
}

// Close the channel to signal completion.
close(ch)
}

func (tx *Tx) recursivelyCheckBucket(b *Bucket, reachable map[common.Pgid]*common.Page, freed map[common.Pgid]bool,
Expand Down

0 comments on commit 288e823

Please sign in to comment.