mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'shandley/db-locking-mitigation' into 'master'
DB Locking mitigations See merge request veloren/veloren!1047
This commit is contained in:
commit
ea414f6921
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,6 +36,8 @@ todo.txt
|
||||
# Game data
|
||||
*.sqlite
|
||||
*.sqlite-journal
|
||||
*.sqlite-wal
|
||||
*.sqlite-shm
|
||||
|
||||
# direnv
|
||||
/.envrc
|
||||
|
@ -6,7 +6,7 @@ mod schema;
|
||||
|
||||
extern crate diesel;
|
||||
|
||||
use diesel::prelude::*;
|
||||
use diesel::{connection::SimpleConnection, prelude::*};
|
||||
use diesel_migrations::embed_migrations;
|
||||
use std::{env, fs, path::PathBuf};
|
||||
|
||||
@ -24,8 +24,26 @@ pub fn run_migrations(db_dir: &str) -> Result<(), diesel_migrations::RunMigratio
|
||||
fn establish_connection(db_dir: &str) -> SqliteConnection {
|
||||
let db_dir = &apply_saves_dir_override(db_dir);
|
||||
let database_url = format!("{}/db.sqlite", db_dir);
|
||||
SqliteConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
|
||||
let connection = SqliteConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
|
||||
|
||||
// Use Write-Ahead-Logging for improved concurrency: https://sqlite.org/wal.html
|
||||
// Set a busy timeout (in ms): https://sqlite.org/c3ref/busy_timeout.html
|
||||
if let Err(error) = connection.batch_execute(
|
||||
"
|
||||
PRAGMA journal_mode = WAL;
|
||||
PRAGMA busy_timeout = 250;
|
||||
",
|
||||
) {
|
||||
log::warn!(
|
||||
"Failed adding PRAGMA statements while establishing sqlite connection, this will \
|
||||
result in a higher likelihood of locking errors: {}",
|
||||
error
|
||||
);
|
||||
}
|
||||
|
||||
connection
|
||||
}
|
||||
|
||||
fn apply_saves_dir_override(db_dir: &str) -> String {
|
||||
|
Loading…
Reference in New Issue
Block a user