-
Notifications
You must be signed in to change notification settings - Fork 652
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
Perform unmap when mlock fails or both meta pages corrupted #433
Conversation
Signed-off-by: Benjamin Wang <[email protected]>
Signed-off-by: Benjamin Wang <[email protected]>
db.go
Outdated
defer func() { | ||
if err != nil { | ||
// TODO(ahrtr): add log to print the error if unmap somehow fails. | ||
_ = db.munmap() |
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.
Thanks @ahrtr, overall looks good!
I'm wondering about the failure modes here reading through the man page: https://linux.die.net/man/2/munmap
it kinda looks to me that most of these errors should also be fatal, so I wouldn't even just log them but directly error out of the process. wdyt?
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.
or at the very least, wrap the already existing err
with the new one
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.
Updated.
LGTM |
tests/failpoint/db_failpoint_test.go
Outdated
@@ -1,6 +1,8 @@ | |||
package failpoint | |||
|
|||
import ( | |||
"fmt" | |||
"go.etcd.io/bbolt/internal/btesting" |
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.
minor issue: please move it into third group.
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.
Good catch. Thank you @fuweid
We may want to enhance the workflow to detect such error automatically.
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.
raised #435
Signed-off-by: Benjamin Wang <[email protected]>
This should be a safe change, and already been reviewed by three people, so let me merging it for now. |
defer func() { | ||
if err != nil { | ||
if unmapErr := db.munmap(); unmapErr != nil { | ||
err = fmt.Errorf("%w; unmap failed: %v", err, unmapErr) |
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.
-
I would be explicit in that error that it's 'rollback unmap also failed'.
-
I had some doubts whether we should execute here unmap or just db.invalidate.
Ideally cleanup for failing mmap() (like rollback unmap) should be handled within the mmap() function's logic, rather than assumed externally. -
If we suspect the failing rollbacks might be reason for the double-linking issues,
by submitting this patch, we are making it more difficult to build repro (i.e. we need to test with & without that patch). It would be good to split failpoints (helping with repro) from the 'fix' PR. -
Next time please ping me or @serathius a little longer for business logic change - to not create precedences.
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.
- I would be explicit in that error that it's 'rollback unmap also failed'.
Thanks for the suggestion. Will fix it separately.
- I had some doubts whether we should execute here unmap or just db.invalidate.
Ideally cleanup for failing mmap() (like rollback unmap) should be handled within the mmap() function's logic, rather than assumed externally.
Definitely we should execute db.unmap
instead of db.invalidate
. Note that the deferred function will only be executed when mmap already succeeded but (1) mlock somehow failed or (2) both meta pages are corrupted.
- If we suspect the failing rollbacks might be reason for the double-linking issues,
by submitting this patch, we are making it more difficult to build repro (i.e. we need to test with & without that patch). It would be good to split failpoints (helping with repro) from the 'fix' PR.
Not sure what do you mean by "double-linking issues", could you clarify this? I found the issue with the new added test cases in this PR, so I fixed it in the same PR. I plan to backport both failpoints and all bug fixes to release-1.3, please see #436. Please let me know if you still have any concern.
- Next time please ping me or @serathius a little longer for business logic change - to not create precedences.
Sorry to merge this PR without another maintainer's approval. I do think it's a safe change, and It's already reviewed by three experienced contributors. But anyway, will try to follow the process next time.
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.
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.
- thx
- You are right.
- I mean corruptions like Branch page items link to already released pages #402. There is slim chance there are caused by transaction rollback and follow up commit. If we find repro without this PR, we have a higher confidence we found the root issue.
If the PR indeed fixes the problem. You might struggle to repro problem that got already fixed.
I'm not saying I have concerns about this PR, just flagging. - Thx.
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.
If the PR indeed fixes the problem. You might struggle to repro problem that got already fixed.
I'm not saying I have concerns about this PR, just flagging.
Thanks for the reminder.
When mlock somehow fails, then bbolt may run into nil pointer error in rollback. The new added test case also fails. The solution is to perform unmap when mlock fails or both meta pages corrupted.
Linked to #382