Skip to content
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

Database corruption caused by power loss #3159

Open
marcinstrzelczyk opened this issue Nov 7, 2024 · 5 comments
Open

Database corruption caused by power loss #3159

marcinstrzelczyk opened this issue Nov 7, 2024 · 5 comments
Labels
Status: Available No one has claimed responsibility for resolving this issue.

Comments

@marcinstrzelczyk
Copy link

marcinstrzelczyk commented Nov 7, 2024

Hello,
I have mosquitto v2.0.18 running on Windows 10 as a service. Few days ago I experienced sudden power loss on my computer and then mosquitto failed to start with

Error: Unable to restore persistent database. Unrecognised file format.
Error: Couldn't open database.

errors in log file. Most likely mosquitto was trying to update the database file when the power loss happened, but I'm not 100% sure.

The mosquitto.db file exists and contains only NULLs. There is no mosquitto.db.new file, which I saw being mentioned in other issues.

This issue is similar to #189, I looked at PR for that issue and the solution was to add fflush(db_fptr); before closing the file (https://github.com/eclipse-mosquitto/mosquitto/pull/206/files), but it was done inside #ifndef WIN32 directive, so it was not applied to Windows version. I don't know if that fflush call could fix problems on Windows as well, but maybe it's worth looking at.

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Nov 7, 2024
@sitaalbeMarp
Copy link

Hello, I've experienced similar behaviour also with version 2.0.20.

@bartoszsurowiec
Copy link

@marcinstrzelczyk did you find a solution/fix?

@marcinstrzelczyk
Copy link
Author

@bartoszsurowiec nope

@NorbertHeusser
Copy link
Contributor

One of the general problems in windows is the absence of a real atomic and posix compliant file rename.
The fflush might reduce the risk to loose data, but we would need to introduce an additional fsync (FlushFileBuffers as well. And this would introduce a massiv delay.

In general Mosquitto broker has introduced an extension of the plugin API on the development branch to allow persistence based on a plugin. And added a sqlite based persistence plugin. With the next major release it will be possible to replace the snapshot based blocking persistence by a more continuous persistence making use of a SQLite DB.

@bartoszsurowiec
Copy link

bartoszsurowiec commented Dec 6, 2024

When is the next major release planned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Available No one has claimed responsibility for resolving this issue.
Projects
None yet
Development

No branches or pull requests

4 participants