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

Create InvalidCheckpoint Error to bucket errors relevant to checkpoint #593

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum KernelError {
ParseIntervalError,
ChangeDataFeedUnsupported,
ChangeDataFeedIncompatibleSchema,
InvalidCheckpoint,
}

impl From<Error> for KernelError {
Expand Down Expand Up @@ -108,6 +109,7 @@ impl From<Error> for KernelError {
Error::ChangeDataFeedIncompatibleSchema(_, _) => {
KernelError::ChangeDataFeedIncompatibleSchema
}
Error::InvalidCheckpoint(_) => KernelError::InvalidCheckpoint,
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions kernel/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ pub enum Error {

#[error("Change data feed encountered incompatible schema. Expected {0}, got {1}")]
ChangeDataFeedIncompatibleSchema(String, String),

/// Invalid checkpoint files
#[error("Invalid Checkpoint: {0}")]
InvalidCheckpoint(String),
}

// Convenience constructors for Error types that take a String argument
Expand Down Expand Up @@ -264,6 +268,10 @@ impl Error {
Self::ChangeDataFeedIncompatibleSchema(format!("{expected:?}"), format!("{actual:?}"))
}

pub fn invalid_checkpoint(msg: impl ToString) -> Self {
Self::InvalidCheckpoint(msg.to_string())
}

// Capture a backtrace when the error is constructed.
#[must_use]
pub fn with_backtrace(self) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/log_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl LogSegment {
{
require!(
checkpoint_file.version + 1 == commit_file.version,
Error::generic(format!(
Error::InvalidCheckpoint(format!(
"Gap between checkpoint version {} and next commit {}",
checkpoint_file.version, commit_file.version,
))
Expand Down Expand Up @@ -358,7 +358,7 @@ fn list_log_files_with_checkpoint(

let Some(latest_checkpoint) = checkpoint_parts.last() else {
// TODO: We could potentially recover here
return Err(Error::generic(
return Err(Error::invalid_checkpoint(
"Had a _last_checkpoint hint but didn't find any checkpoints",
));
};
Expand All @@ -369,7 +369,7 @@ fn list_log_files_with_checkpoint(
latest_checkpoint.version
);
} else if checkpoint_parts.len() != checkpoint_metadata.parts.unwrap_or(1) {
return Err(Error::Generic(format!(
return Err(Error::InvalidCheckpoint(format!(
"_last_checkpoint indicated that checkpoint should have {} parts, but it has {}",
checkpoint_metadata.parts.unwrap_or(1),
checkpoint_parts.len()
Expand Down
Loading