couchbase-lite-ios: Power failure causes corruption in SQLite file
I know we’ve touched on this problem in a now closed issue, but it’s happening regularly now to my customers who have had power failures. I just tested it myself on my MacBook Pro by holding down the power button until my MBP shut itself off. When my Mac came back up and I re-launched my app, this is the message in the console log I get:
Unknown error calling sqlite3_step (11: database disk image is malformed) rs
This is using the pre-built SQLCipher library from the Couchbase SQLCipher repository. I didn’t compile it myself because I wanted to test the “out of the box” solution to see if it has this problem. Clearly it does.
I doubt it’s possible to write a test case for a power failure though, so I’m not sure how this can be tested in an automated way. I made sure I closed down all my apps other than Xcode and the running version of my app. Then I held down the power button to cause the “power failure”. Sure enough, database file corruption.
I hadn’t even changed anything in the database before I caused the power failure. I simply opened the database and caused the power failure and now the .sqlite file has become corrupted. I thought that WAL mode was also supposed to help prevent this from happening?
Do you think that ForestDB would be less prone to this type of problem? The only reason I’m not using ForestDB right now is because the FTS engine is unable to do prefixed or “OR” type searches.
- Version: 1.3.1
- Client OS: macOS Sierra 10.12
- Server: n/a
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 67 (60 by maintainers)
Commits related to this issue
- Disabled SQLite memory mapping on Mac OS It appears to produce a risk of database corruption on power failure, though as far as I can tell no one understands why yet. For couchbase/couchbase-lite-io... — committed to couchbase/couchbase-lite-core by snej 7 years ago
- Removed memory-mapped sqlite config Using memory-mapped has a potential to cuase the database corruption issue in mac os. #1482 — committed to couchbase/couchbase-lite-ios by pasin 7 years ago
Let’s close the issue!