Skip to content

Commit

Permalink
Merge pull request #1748 from tursodatabase/lucio/graceful-connisprimary
Browse files Browse the repository at this point in the history
sqld: gracefully reject schema migration on replica
  • Loading branch information
LucioFranco authored Sep 18, 2024
2 parents 5129424 + 3e192cf commit 32150fe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libsql-server/src/rpc/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,12 @@ impl Proxy for ProxyService {
tracing::debug!("connected: {client_id}");
match connection_maker.create().await {
Ok(conn) => {
assert!(conn.is_primary());
if !conn.is_primary() {
return Err(tonic::Status::failed_precondition(
"cannot run schema migration against a replica",
));
}

let conn = Arc::new(TimeoutConnection::new(conn));
let mut lock = RwLockUpgradableReadGuard::upgrade(lock).await;
lock.insert(client_id, conn.clone());
Expand Down Expand Up @@ -703,7 +708,12 @@ impl Proxy for ProxyService {
tracing::debug!("connected: {client_id}");
match connection_maker.create().await {
Ok(conn) => {
assert!(conn.is_primary());
if !conn.is_primary() {
return Err(tonic::Status::failed_precondition(
"cannot run schema migration against a replica",
));
}

let conn = Arc::new(TimeoutConnection::new(conn));
let mut lock = RwLockUpgradableReadGuard::upgrade(lock).await;
lock.insert(client_id, conn.clone());
Expand Down

0 comments on commit 32150fe

Please sign in to comment.