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

Ignore corrupt status files and use default. #1164

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/daemon/ca/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ impl StatusStore {
/// so any missing, corrupted, or no longer supported data format - can be ignored.
/// It will get updated with new status values as Krill is running.
fn load_full_status(&self, ca: &CaHandle) -> KrillResult<()> {
let repo: RepoStatus = self.store.get(&Self::repo_status_key(ca))?.unwrap_or_default();
let repo: RepoStatus = match self.store.get(&Self::repo_status_key(ca)) {
Copy link
Member

Choose a reason for hiding this comment

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

I can live with this pattern though it gets repetitive given that you do it more than once.

An alternative syntax for this could be (but still requires that the pattern be repeated on each use):

let repo: RepoStatus = self.store.get(&Self::repo_status_key(ca))
    .unwrap_or(None)
    .unwrap_or_default();

It might be better to just add a get_or_default() fn to the store and use that.

Copy link
Member

Choose a reason for hiding this comment

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

Wow even uglier would be calling unwrap_or_default() twice in a chain... ;-)

Copy link
Member

Choose a reason for hiding this comment

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

I wonder, is there an issue here when there is nothing wrong with the data on disk or in whatever backend KV store, but there's just a temporary issue accessing it? Then you'd proceed anyway ignoring the good but temporarily unavailable state rather than reporting the access issue - would it be good to at least warn that the underlying "execute()" call failed?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose if there is a problem accessing the underlying store then failure is going to happen soon anyway...

Ok(Some(status)) => status,
_ => RepoStatus::default(),
};

// We use the following mapping for keystore keys to parents/children:
// parents-{parent-handle}.json
Expand All @@ -121,10 +124,10 @@ impl StatusStore {
// the format changed in a new version, then just fall back to
// an empty default value. We will get a new connection status
// value soon enough as Krill is running.
let status: ParentStatus = self
.store
.get(&Self::parent_status_key(ca, &parent))?
.unwrap_or_default();
let status: ParentStatus = match self.store.get(&Self::parent_status_key(ca, &parent)) {
Ok(Some(status)) => status,
_ => ParentStatus::default(),
};

parents.insert(parent, status);
}
Expand All @@ -149,7 +152,10 @@ impl StatusStore {
// the format changed in a new version, then just fall back to
// an empty default value. We will get a new connection status
// value soon enough as Krill is running.
let status: ChildStatus = self.store.get(&Self::child_status_key(ca, &child))?.unwrap_or_default();
let status: ChildStatus = match self.store.get(&Self::child_status_key(ca, &child)) {
Ok(Some(status)) => status,
_ => ChildStatus::default(),
};

children.insert(child, status);
}
Expand Down
Loading