From 3e192cf92a47058b2ac41d66af25feeaf3898e0e Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Wed, 18 Sep 2024 13:34:12 -0400 Subject: [PATCH] sqld: gracefully reject schema migration on replica --- libsql-server/src/rpc/proxy.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libsql-server/src/rpc/proxy.rs b/libsql-server/src/rpc/proxy.rs index 80cbd37088..ff9d5bac0a 100644 --- a/libsql-server/src/rpc/proxy.rs +++ b/libsql-server/src/rpc/proxy.rs @@ -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()); @@ -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());