From 2b0efb32c1d8a2f568f7aea4f6721aed5cd70dc8 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:20:47 -0700 Subject: [PATCH] fuckit: no patch db locks (#1969) * fuck it: no patchdb locks * fix: Add the locking to the package during the backup. (#1979) * fix: Add the locking to the package during the backup. * fix: Lock for the uninstall of the package * switch patch-db to next Co-authored-by: J M <2364004+Blu-J@users.noreply.github.com> --- backend/src/action.rs | 2 +- backend/src/backup/backup_bulk.rs | 19 ++++++++++--------- backend/src/backup/mod.rs | 4 ++-- backend/src/install/cleanup.rs | 5 +++++ backend/src/install/mod.rs | 13 +++++++++---- backend/src/manager/mod.rs | 4 ++-- backend/src/properties.rs | 2 +- backend/src/setup.rs | 2 +- backend/src/version/v0_3_2.rs | 6 +----- backend/src/version/v0_3_3.rs | 4 ++-- patch-db | 2 +- 11 files changed, 35 insertions(+), 28 deletions(-) diff --git a/backend/src/action.rs b/backend/src/action.rs index a07d0a1fa..54f0cad02 100644 --- a/backend/src/action.rs +++ b/backend/src/action.rs @@ -139,7 +139,7 @@ pub async fn action( .await .with_kind(crate::ErrorKind::NotFound)? .manifest() - .get(&mut db, true) + .get(&mut db) .await? .to_owned(); diff --git a/backend/src/backup/backup_bulk.rs b/backend/src/backup/backup_bulk.rs index f2c44e640..e0e622ed5 100644 --- a/backend/src/backup/backup_bulk.rs +++ b/backend/src/backup/backup_bulk.rs @@ -154,7 +154,7 @@ pub async fn backup_all( .await?; let all_packages = crate::db::DatabaseModel::new() .package_data() - .get(&mut db, false) + .get(&mut db) .await? .0 .keys() @@ -297,7 +297,7 @@ async fn perform_backup( for package_id in crate::db::DatabaseModel::new() .package_data() - .keys(&mut db, false) + .keys(&mut db) .await? .into_iter() .filter(|id| package_ids.contains(id)) @@ -317,7 +317,7 @@ async fn perform_backup( let main_status_model = installed_model.clone().status().main(); main_status_model.lock(&mut tx, LockType::Write).await?; - let (started, health) = match main_status_model.get(&mut tx, true).await?.into_owned() { + let (started, health) = match main_status_model.get(&mut tx).await?.into_owned() { MainStatus::Starting { .. } => (Some(Utc::now()), Default::default()), MainStatus::Running { started, health } => (Some(started), health.clone()), MainStatus::Stopped | MainStatus::Stopping | MainStatus::Restarting => { @@ -346,11 +346,7 @@ async fn perform_backup( .await?; tx.save().await?; // drop locks - let manifest = installed_model - .clone() - .manifest() - .get(&mut db, false) - .await?; + let manifest = installed_model.clone().manifest().get(&mut db).await?; ctx.managers .get(&(manifest.id.clone(), manifest.version.clone())) @@ -362,6 +358,11 @@ async fn perform_backup( .await; let mut tx = db.begin().await?; + let lock_package = crate::db::DatabaseModel::new() + .package_data() + .idx(&package_id) + .lock(&mut tx, LockType::Write) + .await; installed_model.lock(&mut tx, LockType::Write).await?; @@ -445,7 +446,7 @@ async fn perform_backup( root_ca_cert, ui: crate::db::DatabaseModel::new() .ui() - .get(&mut db, true) + .get(&mut db) .await? .into_owned(), })?, diff --git a/backend/src/backup/mod.rs b/backend/src/backup/mod.rs index b4650745e..e178ad2fa 100644 --- a/backend/src/backup/mod.rs +++ b/backend/src/backup/mod.rs @@ -137,7 +137,7 @@ impl BackupActions { .expect(db) .await? .marketplace_url() - .get(db, true) + .get(db) .await? .into_owned(); let tmp_path = Path::new(BACKUP_DIR) @@ -237,7 +237,7 @@ impl BackupActions { .installed() .expect(db) .await? - .get(db, true) + .get(db) .await?; let receipts = crate::config::ConfigReceipts::new(db).await?; diff --git a/backend/src/install/cleanup.rs b/backend/src/install/cleanup.rs index 06b5e50bb..a54ef1227 100644 --- a/backend/src/install/cleanup.rs +++ b/backend/src/install/cleanup.rs @@ -342,6 +342,11 @@ where for<'a> &'a mut Ex: Executor<'a, Database = Postgres>, { let mut tx = db.begin().await?; + crate::db::DatabaseModel::new() + .package_data() + .idx_model(&id) + .lock(&mut tx, LockType::Write) + .await?; let receipts = UninstallReceipts::new(&mut tx, id).await?; let entry = receipts.removing.get(&mut tx).await?; cleanup(ctx, &entry.manifest.id, &entry.manifest.version).await?; diff --git a/backend/src/install/mod.rs b/backend/src/install/mod.rs index d86bfe6c6..1cddece6c 100644 --- a/backend/src/install/mod.rs +++ b/backend/src/install/mod.rs @@ -63,7 +63,7 @@ pub async fn list(#[context] ctx: RpcContext) -> Result Result<(), Error> { let mut handle = ctx.db.handle(); let mut tx = handle.begin().await?; + crate::db::DatabaseModel::new() + .package_data() + .idx_model(&id) + .lock(&mut tx, LockType::Write) + .await?; let mut pde = crate::db::DatabaseModel::new() .package_data() @@ -879,7 +884,7 @@ pub async fn install_s9pk( .package_data() .idx_model(dep) .map::<_, Manifest>(|pde| pde.manifest()) - .get(&mut ctx.db.handle(), false) + .get(&mut ctx.db.handle()) .await? .into_owned() { @@ -1119,7 +1124,7 @@ pub async fn install_s9pk( let mut deps = BTreeMap::new(); for package in crate::db::DatabaseModel::new() .package_data() - .keys(&mut tx, true) + .keys(&mut tx) .await? { // update dependency_info on dependents @@ -1153,7 +1158,7 @@ pub async fn install_s9pk( .await? .installed() .and_then(|i| i.current_dependencies().idx_model(pkg_id)) - .get(&mut tx, true) + .get(&mut tx) .await? .to_owned() { diff --git a/backend/src/manager/mod.rs b/backend/src/manager/mod.rs index d356fe08d..5538fa5df 100644 --- a/backend/src/manager/mod.rs +++ b/backend/src/manager/mod.rs @@ -53,7 +53,7 @@ impl ManagerMap { let mut res = BTreeMap::new(); for package in crate::db::DatabaseModel::new() .package_data() - .keys(db, true) + .keys(db) .await? { let man: Manifest = if let Some(manifest) = crate::db::DatabaseModel::new() @@ -61,7 +61,7 @@ impl ManagerMap { .idx_model(&package) .and_then(|pkg| pkg.installed()) .map(|m| m.manifest()) - .get(db, true) + .get(db) .await? .to_owned() { diff --git a/backend/src/properties.rs b/backend/src/properties.rs index 782f7e783..acd69adbf 100644 --- a/backend/src/properties.rs +++ b/backend/src/properties.rs @@ -27,7 +27,7 @@ pub async fn fetch_properties(ctx: RpcContext, id: PackageId) -> Result Result<(Arc, Hostname, OnionAddressV3, X509), Error> { - use crate::util::Invoke; + *ctx.setup_status.write().await = Some(Ok(SetupStatus { bytes_transferred: 0, total_bytes: 110, diff --git a/backend/src/version/v0_3_2.rs b/backend/src/version/v0_3_2.rs index 8079d9057..d0f6548c1 100644 --- a/backend/src/version/v0_3_2.rs +++ b/backend/src/version/v0_3_2.rs @@ -47,11 +47,7 @@ impl VersionT for Version { crate::hostname::ensure_hostname_is_set(db, &receipts).await?; receipts.id.set(db, generate_id()).await?; - let mut ui = crate::db::DatabaseModel::new() - .ui() - .get(db, false) - .await? - .clone(); + let mut ui = crate::db::DatabaseModel::new().ui().get(db).await?.clone(); ui.merge_with(&DEFAULT_UI); crate::db::DatabaseModel::new().ui().put(db, &ui).await?; diff --git a/backend/src/version/v0_3_3.rs b/backend/src/version/v0_3_3.rs index be1345603..4b89a2794 100644 --- a/backend/src/version/v0_3_3.rs +++ b/backend/src/version/v0_3_3.rs @@ -80,7 +80,7 @@ impl VersionT for Version { for package_id in crate::db::DatabaseModel::new() .package_data() - .keys(db, false) + .keys(db) .await? .iter() { @@ -126,7 +126,7 @@ impl VersionT for Version { ui["auto-check-updates"] = Value::Bool(true); ui["pkg-order"] = json!(crate::db::DatabaseModel::new() .package_data() - .keys(db, false) + .keys(db) .await? .iter() .map(|x| x.to_string()) diff --git a/patch-db b/patch-db index c54a1f037..953a22438 160000 --- a/patch-db +++ b/patch-db @@ -1 +1 @@ -Subproject commit c54a1f037c499ae930bb449152b79aaea18132ca +Subproject commit 953a224384163f4784ace37381fb3a899893f0a6