Skip to content

Commit

Permalink
fix: avoid data race when setting memdb footprint hook
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <eke@fastmail.com>
  • Loading branch information
ekexium committed Nov 23, 2022
1 parent e9db9e6 commit 21fe69b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/unionstore/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,11 @@ func (db *MemDB) SetMemoryFootprintChangeHook(hook func(uint64)) {
innerHook := func() {
hook(db.allocator.capacity + db.vlog.capacity)
}
db.allocator.memChangeHook = innerHook
db.vlog.memChangeHook = innerHook
if db.allocator.memChangeHook == nil {
// always set together
db.allocator.memChangeHook = innerHook
db.vlog.memChangeHook = innerHook
}
}

// Mem returns the current memory footprint
Expand Down

0 comments on commit 21fe69b

Please sign in to comment.