Skip to content

Commit

Permalink
fix(sql-backend): force sqlite connection singleton to avoid database…
Browse files Browse the repository at this point in the history
… lock error (#14962)
  • Loading branch information
yezizp2012 committed Feb 4, 2024
1 parent 53c75b1 commit 4fbf65f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/meta/node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,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?;
Expand Down

0 comments on commit 4fbf65f

Please sign in to comment.