fix(native): possible deadlock when batching read/write (#9817)

This commit is contained in:
forehalo
2025-01-21 06:07:03 +00:00
parent 46ee235674
commit 07c32d016d
11 changed files with 208 additions and 169 deletions

View File

@@ -16,24 +16,28 @@ impl SqliteDocStorage {
pub fn new(path: String) -> Self {
let sqlite_options = SqliteConnectOptions::new()
.filename(&path)
.foreign_keys(false)
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal);
.foreign_keys(false);
let mut pool_options = SqlitePoolOptions::new();
if cfg!(test) && path == ":memory:" {
if path == ":memory:" {
pool_options = pool_options
.min_connections(1)
.max_connections(1)
.idle_timeout(None)
.max_lifetime(None);
} else {
pool_options = pool_options.max_connections(4);
}
Self {
pool: pool_options.connect_lazy_with(sqlite_options),
path,
Self {
pool: pool_options.connect_lazy_with(sqlite_options),
path,
}
} else {
Self {
pool: pool_options
.max_connections(4)
.connect_lazy_with(sqlite_options.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)),
path,
}
}
}