Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the closing of channel into the same method of creating the channel #666

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading