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 3bdebcf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/unionstore/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,14 @@ func (db *MemDB) RemoveFromBuffer(key []byte) {

// SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows.
func (db *MemDB) SetMemoryFootprintChangeHook(hook func(uint64)) {
innerHook := func() {
hook(db.allocator.capacity + db.vlog.capacity)
if db.allocator.memChangeHook == nil {
// always set together
innerHook := func() {
hook(db.allocator.capacity + db.vlog.capacity)
}
db.allocator.memChangeHook = innerHook
db.vlog.memChangeHook = innerHook
}
db.allocator.memChangeHook = innerHook
db.vlog.memChangeHook = innerHook
}

// Mem returns the current memory footprint
Expand Down

0 comments on commit 3bdebcf

Please sign in to comment.