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

[jsondb] Restore zero byte files from backup #2155

Merged
merged 2 commits into from
Jan 26, 2021
Merged

Conversation

MikeJMajor
Copy link
Contributor

@MikeJMajor MikeJMajor commented Jan 25, 2021

Fixes #2136

A file which has legitimately had all items removed, e.g. deleting all things from the UI, results in a 2 byte file containing just {}, so there should be no problem with unintentionally restoring a file from backup.

Here's an example of the output with a zero byte Things DB and a couple of zero byte backups:

2021-01-25 17:31:25.590 [WARN ] [re.storage.json.internal.JsonStorage] - Json storage file at '/var/lib/openhab/jsondb/org.openhab.core.thing.Thing.json' is empty - ignoring corrupt file.
2021-01-25 17:31:25.598 [INFO ] [re.storage.json.internal.JsonStorage] - Json storage file at '/var/lib/openhab/jsondb/org.openhab.core.thing.Thing.json' seems to be corrupt - checking for a backup.
2021-01-25 17:31:25.614 [WARN ] [re.storage.json.internal.JsonStorage] - Json storage file at '/var/lib/openhab/jsondb/backup/1611594982095--org.openhab.core.thing.Thing.json' is empty - ignoring corrupt file.
2021-01-25 17:31:25.627 [WARN ] [re.storage.json.internal.JsonStorage] - Json storage file at '/var/lib/openhab/jsondb/backup/1611594528039--org.openhab.core.thing.Thing.json' is empty - ignoring corrupt file.
2021-01-25 17:31:25.721 [INFO ] [re.storage.json.internal.JsonStorage] - Json storage file at '/var/lib/openhab/jsondb/backup/1611594297312--org.openhab.core.thing.Thing.json' is used (backup 3).

Signed-off-by: Mike Major mike_j_major@hotmail.com

Signed-off-by: Mike Major <mike_j_major@hotmail.com>
@MikeJMajor MikeJMajor requested a review from a team as a code owner January 25, 2021 12:06
@cweitkamp cweitkamp added the enhancement An enhancement or new feature of the Core label Jan 25, 2021
Signed-off-by: Mike Major <mike_j_major@hotmail.com>
@MikeJMajor MikeJMajor requested a review from cweitkamp January 26, 2021 09:53
Copy link
Contributor

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

This small path is a nice improvement to cover unexpected loss if data (e.g. due to a power loss).

As the JSON storage is a very important OHC bundle we might harden its implementation by some additional unit/itests to avoid future regressions. We can do that in a follow-up PR.

@cweitkamp cweitkamp merged commit 86a447c into openhab:main Jan 26, 2021
@cweitkamp cweitkamp added this to the 3.1 milestone Jan 26, 2021
@MikeJMajor MikeJMajor deleted the jsondb branch January 26, 2021 20:19
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/great-problem-after-update-to-openhab3/115746/6

splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 11, 2023
* Restore zero byte files from backup
* Also handle zero byte backup files

Signed-off-by: Mike Major <mike_j_major@hotmail.com>
GitOrigin-RevId: 86a447c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[jsondb] zero byte files should be treated as missing and restored from backup
3 participants