-
Notifications
You must be signed in to change notification settings - Fork 173
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 syncing dirty pages on IOS #5993
Merged
Merged
Conversation
This file contains 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
e98a351
to
e166d5d
Compare
nicola-cab
commented
Nov 4, 2022
nicola-cab
commented
Nov 7, 2022
This was referenced Nov 9, 2022
This was referenced Nov 9, 2022
tgoyne
approved these changes
Nov 9, 2022
This was referenced Nov 17, 2022
Closed
Closed
Closed
Closed
This was referenced Jan 4, 2023
Closed
This was referenced Jan 17, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What, How & Why?
On IOS, we have been seeing a huge increase of database corruption issues.
I went down bisecting a little bit our code base, and it seems like the problem is related to the fact that as per the current implementation we never sync dirty pages up until this barrier is hit:
The barrier implementation itself is platform specific, and on Linux for example this does not cause any issues, because
msync()
is basically equal tofsync()
. On IOS, this does not look like the normal behaviour. Thus, there is the chance of losing some data if the dirty page is notmsynced
before we hit the barrier. Moreover, on IOS, even the barrier does not guarantee that the page will actually reach disk. We need to explicitly callmsync
for each page.The easiest way to reproduce this is to start a write transaction, that writes several bytes of data (my test consisted of 2 reasonably long strings), and crash the platform in the middle of the commit itself. Most likely, some of the dirty pages won't be written, causing havoc in the database file.
The same behaviour could happen during a normal commit, thus some insertion or deletion could fail apparently spuriously because of some data that got corrupted during a previous commit.
Calling
msync
for each page proved to be effective, and the database was never corrupted.We need to add a specific tests for this case, in which we write to disk, and we crash the platform.
Corruption:
Fixes: #5972
Fixes: #5718
Fixes: #5859
Fixes: #5976
FIxes: #5975
Fixes: #5970
Fixes: #5758
Fixes: #5761
Fixes: #5298
Fixes: #5299
Fixes: #5941
Encryption
Fixes: #5810
Fixes: #5811
☑️ ToDos