From 5f741c6a36173e4b5ac95d8b1dc7626e37c92d45 Mon Sep 17 00:00:00 2001 From: August Date: Sun, 4 Feb 2024 12:54:53 +0800 Subject: [PATCH] fix(sql-backend): force sqlite connection singleton to avoid database lock error (#14962) --- src/meta/node/src/server.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/meta/node/src/server.rs b/src/meta/node/src/server.rs index 2ae3722bc24c1..bd61debc3bf79 100644 --- a/src/meta/node/src/server.rs +++ b/src/meta/node/src/server.rs @@ -174,9 +174,17 @@ pub async fn rpc_serve( ) } MetaStoreBackend::Sql { endpoint } => { + let max_connection = if DbBackend::Sqlite.is_prefix_of(&endpoint) { + // Due to the fact that Sqlite is prone to the error "(code: 5) database is locked" under concurrent access, + // here we forcibly specify the number of connections as 1. + 1 + } else { + 10 + }; + let mut options = sea_orm::ConnectOptions::new(endpoint); options - .max_connections(20) + .max_connections(max_connection) .connect_timeout(Duration::from_secs(10)) .idle_timeout(Duration::from_secs(30)); let conn = sea_orm::Database::connect(options).await?;