Skip to content

Commit

Permalink
chore(rust): disabled SQLite WAL mode, revertable commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-baldo committed Oct 22, 2024
1 parent 28fa890 commit 21e9391
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
22 changes: 3 additions & 19 deletions implementations/rust/ockam/ockam_api/src/cli_state/cli_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,7 @@ impl CliState {
let _ = std::fs::remove_dir_all(Self::make_commands_log_dir_path(root_path));
// Delete the nodes database, keep the application database
if let Some(path) = Self::make_database_configuration(root_path)?.path() {
std::fs::remove_file(path.clone())?;
// wal and shm files may not exist, depending on the database state
let wal_path = path.with_extension("sqlite3-wal");
if wal_path.exists() {
std::fs::remove_file(wal_path)?;
}
let shm_path = path.with_extension("sqlite3-shm");
if shm_path.exists() {
std::fs::remove_file(shm_path)?;
}
std::fs::remove_file(path)?;
};
Ok(())
}
Expand Down Expand Up @@ -409,16 +400,9 @@ mod tests {

/// HELPERS
fn list_file_names(dir: &Path) -> Vec<String> {
let file_names: Vec<_> = fs::read_dir(dir)
fs::read_dir(dir)
.unwrap()
.map(|f| f.unwrap().file_name().to_string_lossy().to_string())
.collect();

// remove -wal and -shm files from the list
// they may or may not exist depending on the database state
file_names
.into_iter()
.filter(|file| !file.ends_with("-wal") && !file.ends_with("-shm"))
.collect::<Vec<String>>()
.collect()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ impl Drop for InMemoryNode {
// because in that case they can be restarted
if !self.persistent {
executor::block_on(async {
self.cli_state
.remove_node(&self.node_name)
.await
.unwrap_or_else(|e| panic!("cannot delete the node {}: {e:?}", self.node_name));
let result = self.cli_state.remove_node(&self.node_name).await;
if let Err(err) = result {
// code: 1032 maps to SQLITE_READONLY_DBMOVED - meaning the database has been
// moved to another directory, most likely already deleted
if !err.to_string().contains("code: 1032") {
panic!("cannot delete the node {}: {err:?}", self.node_name);
}
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ function get_project_data() {
function copy_enrolled_home_dir() {
if [ ! -z "${ORCHESTRATOR_TESTS}" ]; then
cp -a $OCKAM_HOME_BASE/application_database.sqlite3 $OCKAM_HOME/
if [ -f $OCKAM_HOME_BASE/application_database.sqlite3-wal ]; then
cp -a $OCKAM_HOME_BASE/application_database.sqlite3-wal $OCKAM_HOME
fi

cp -a $OCKAM_HOME_BASE/database.sqlite3 $OCKAM_HOME/
if [ -f $OCKAM_HOME_BASE/database.sqlite3-wal ]; then
cp -a $OCKAM_HOME_BASE/database.sqlite3-wal $OCKAM_HOME
fi
fi
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ teardown() {
# reset the OCKAM_HOME directory
run_success "$OCKAM" reset --yes

# it may, or may not exist, so we remove it to have a consistent state
run_success rm -f "$OCKAM_HOME"/application_database.sqlite3-wal

# list all remaining files and directories
run_success ls "$OCKAM_HOME"
assert_output 'application_database.sqlite3
Expand All @@ -46,8 +43,6 @@ env'
# reset the OCKAM_HOME directory twice, this should not fail
run_success "$OCKAM" reset --yes

run_success rm -f "$OCKAM_HOME"/application_database.sqlite3-wal

run_success ls "$OCKAM_HOME"
assert_output 'application_database.sqlite3
bin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,12 @@ impl SqlxDatabase {
// synchronous = EXTRA - trade performance for durability and reliability
// locking_mode = NORMAL - it's important because WAL mode changes behavior
// if locking_mode is set to EXCLUSIVE *before* WAL is set
// journal_mode = WAL - write-ahead logging, mainly for better concurrency
// busy_timeout = 10000 - wait for 10 seconds before failing a query due to exclusive lock
let _ = connection
.execute(
r#"
PRAGMA synchronous = EXTRA;
PRAGMA locking_mode = NORMAL;
PRAGMA journal_mode = WAL;
PRAGMA busy_timeout = 10000;
"#,
)
Expand Down

0 comments on commit 21e9391

Please sign in to comment.