Skip to content

Commit

Permalink
resolve the data race on accessing tx stats
Browse files Browse the repository at this point in the history
Refer to #213

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Oct 22, 2023
1 parent 66e2075 commit 01d412e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func (b *Bucket) Writable() bool {
// Do not use a cursor after the transaction is closed.
func (b *Bucket) Cursor() *Cursor {
// Update transaction statistics.
// Note that `Cursor()` may be called by multiple readonly
// transactions concurrently, so we need to hold the lock
// `statlock` when updating the stats.
b.tx.db.statlock.Lock()
b.tx.stats.CursorCount++
b.tx.db.statlock.Unlock()

// Allocate and return a cursor.
return &Cursor{
Expand Down

0 comments on commit 01d412e

Please sign in to comment.