Repository navigation
Fix missing flush on proxy segment if sharing write segment - #5553
Merged
Merged
Conversation
generall
approved these changes
Dec 2, 2024
ffuugoo
approved these changes
Dec 3, 2024
ffuugoo
left a comment
Contributor
There was a problem hiding this comment.
Tbh, I'm still not convinced this is a proper fix, but it seems safe enough (and easy to revert), so let's gooooo! 🫡
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix a problem where we could potentially miss flushing deletes on segments wrapped in a proxy.
Imagine the following events:
If proxy A and B share the same write segment, this write segment will be updated even though proxy B is yet to be flushed. The write segment affects the segment version of the proxy, so the version of proxy B is bumped even though it's still pending flush. We normally don't expect this to happen as we hold a read lock on proxy B.
Also, in our flush logic we normally acknowledge the highest version we've seen to the write ahead log.
If we add versions to the above actions, the problem becomes visible:
We did not flush the new change having version 11 in proxy A because we flushed before the update came in. We do acknowledge version 11 in the WAL because it was the highest as reported by proxy B which does include the new version (through proxy A). If we crash now, the WAL won't fix this for us because it'll only start replaying from version 12 onward since version 11 was already acknowledged.
As far as I can see this can only cause us missing flushing deletes. Nor should it cause major issues because we already take point versions into account everywhere. Still I think it's better to prevent this scenario from happening to make our storage more robust.
The key problem here is that we can have multiple proxy segments sharing the same write segment. They are flushed at different times and individually release immediately after flushing. Because of it we can affect a segment we still have a read-lock on.
Note that it's fine to write into non-proxy segments that have just been flushed, even if other segments are still pending flush. The reason is that writing into these will not affect the segment version of the segments pending flush.
To fix the problem from happening I delay releasing the lock for all proxy segments until all segments have been flushed. This will prevent access to shared segments if some part is already flushed.
A potential downside can be that accepting a write takes longer if all segments are proxified. I don't see this as real issue though.
This one is hard to explain, let me know if I need to elaborate further.
All Submissions:
devbranch. Did you create your branch fromdev?New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --all --all-featurescommand?