Skip to content

Commit

Permalink
sqld: improve replica dump error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioFranco committed Nov 22, 2024
1 parent 4a5f373 commit 2bf9d48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions libsql-server/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub enum Error {
RuntimeTaskJoinError(#[from] tokio::task::JoinError),
#[error("wal error: {0}")]
LibsqlWal(#[from] libsql_wal::error::Error),
#[error("database is not a primary")]
NotAPrimary,
}

impl AsRef<Self> for Error {
Expand Down Expand Up @@ -224,6 +226,7 @@ impl IntoResponse for &Error {
AttachInMigration => self.format_err(StatusCode::BAD_REQUEST),
RuntimeTaskJoinError(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
LibsqlWal(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
NotAPrimary => self.format_err(StatusCode::BAD_REQUEST),
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions libsql-server/src/http/user/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ pub(super) async fn handle_dump(
let conn_maker = state
.namespaces
.with(namespace, |ns| {
assert!(ns.db.is_primary());
ns.db.connection_maker()
if !ns.db.is_primary() {
return Err(Error::NotAPrimary);
}

Ok::<_, crate::Error>(ns.db.connection_maker())
})
.await
.unwrap();
.await??;

let conn = conn_maker.create().await.unwrap();

Expand Down

0 comments on commit 2bf9d48

Please sign in to comment.