From 099cc0ba80a518d06da17e88e9d0f38b603691d2 Mon Sep 17 00:00:00 2001 From: August Date: Fri, 2 Feb 2024 19:09:52 +0800 Subject: [PATCH] fix: force sqlite connection singleton to avoid database lock error --- 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 47dcaf54f264..8fce62c2761e 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?;