-
Notifications
You must be signed in to change notification settings - Fork 233
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
fix: avoid data race when setting memdb footprint hook #621
Conversation
/cc @sticnarf |
How does it avoid the race? Will the read at |
Signed-off-by: ekexium <[email protected]>
21fe69b
to
3bdebcf
Compare
Well I have no idea how it works :(. But the race test passes. Maybe use CAS instead? |
Signed-off-by: ekexium <[email protected]>
internal/unionstore/memdb.go
Outdated
db.allocator.memChangeHook = innerHook | ||
db.vlog.memChangeHook = innerHook | ||
atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(&db.allocator.memChangeHook)), nil, unsafe.Pointer(&innerHook)) | ||
atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(&db.vlog.memChangeHook)), nil, unsafe.Pointer(&innerHook)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we skip the second CAS if the first fails? Then, we won't assign different hooks for allocator and vlog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we can but I think it unnecessary. By design they are always set together.
Signed-off-by: ekexium <[email protected]>
No description provided.