Skip to content

Commit

Permalink
move the closing of channel into the same method of creating the channel
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 5, 2024
1 parent 5725474 commit 9cec34d
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 9cec34d

Please sign in to comment.