From 492cb7440b0584011e23e889749dd0ab0448e4fd Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 12 Oct 2021 17:59:16 -0600 Subject: [PATCH] improve patch-db locking --- appmgr/src/config/mod.rs | 4 ++-- appmgr/src/install/mod.rs | 4 ++-- appmgr/src/notifications.rs | 4 ++-- appmgr/src/shutdown.rs | 10 +++++++--- appmgr/src/status/mod.rs | 4 ++-- build/write-image.sh | 2 +- patch-db | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/appmgr/src/config/mod.rs b/appmgr/src/config/mod.rs index 4ac46ef37..ae0794a92 100644 --- a/appmgr/src/config/mod.rs +++ b/appmgr/src/config/mod.rs @@ -6,7 +6,7 @@ use color_eyre::eyre::eyre; use futures::future::{BoxFuture, FutureExt}; use indexmap::IndexSet; use itertools::Itertools; -use patch_db::DbHandle; +use patch_db::{DbHandle, LockType}; use rand::SeedableRng; use regex::Regex; use rpc_toolkit::command; @@ -288,7 +288,7 @@ pub fn configure<'a, Db: DbHandle>( async move { crate::db::DatabaseModel::new() .package_data() - .lock(db, true) + .lock(db, LockType::Write) .await; // fetch data from db let pkg_model = crate::db::DatabaseModel::new() diff --git a/appmgr/src/install/mod.rs b/appmgr/src/install/mod.rs index 00554df0f..9d4b17104 100644 --- a/appmgr/src/install/mod.rs +++ b/appmgr/src/install/mod.rs @@ -9,7 +9,7 @@ use color_eyre::eyre::{self, eyre}; use emver::VersionRange; use futures::TryStreamExt; use http::StatusCode; -use patch_db::DbHandle; +use patch_db::{DbHandle, LockType}; use reqwest::Response; use rpc_toolkit::command; use tokio::fs::{File, OpenOptions}; @@ -532,7 +532,7 @@ pub async fn install_s9pk( let mut sql_tx = ctx.secret_store.begin().await?; crate::db::DatabaseModel::new() .package_data() - .lock(&mut tx, true) + .lock(&mut tx, LockType::Write) .await; tracing::info!("Install {}@{}: Creating volumes", pkg_id, version); diff --git a/appmgr/src/notifications.rs b/appmgr/src/notifications.rs index 318d1b8e3..cdb6555b9 100644 --- a/appmgr/src/notifications.rs +++ b/appmgr/src/notifications.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use chrono::{DateTime, Utc}; use color_eyre::eyre::eyre; -use patch_db::{DbHandle, PatchDb}; +use patch_db::{DbHandle, LockType}; use rpc_toolkit::command; use sqlx::SqlitePool; use tokio::sync::Mutex; @@ -35,7 +35,7 @@ pub async fn list( let model = crate::db::DatabaseModel::new() .server_info() .unread_notification_count(); - model.lock(&mut handle, true).await; + model.lock(&mut handle, LockType::Write).await; let records = sqlx::query!( "SELECT id, package_id, created_at, code, level, title, message, data FROM notifications ORDER BY id DESC LIMIT ?", limit diff --git a/appmgr/src/shutdown.rs b/appmgr/src/shutdown.rs index ad489b7d4..c897fa772 100644 --- a/appmgr/src/shutdown.rs +++ b/appmgr/src/shutdown.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use patch_db::PatchDbHandle; +use patch_db::{LockType, PatchDbHandle}; use rpc_toolkit::command; use crate::context::RpcContext; @@ -67,7 +67,9 @@ impl Shutdown { #[command(display(display_none))] pub async fn shutdown(#[context] ctx: RpcContext) -> Result<(), Error> { let mut db = ctx.db.handle(); - crate::db::DatabaseModel::new().lock(&mut db, true).await; + crate::db::DatabaseModel::new() + .lock(&mut db, LockType::Write) + .await; ctx.shutdown .send(Some(Shutdown { zfs_pool: ctx.zfs_pool_name.clone(), @@ -82,7 +84,9 @@ pub async fn shutdown(#[context] ctx: RpcContext) -> Result<(), Error> { #[command(display(display_none))] pub async fn restart(#[context] ctx: RpcContext) -> Result<(), Error> { let mut db = ctx.db.handle(); - crate::db::DatabaseModel::new().lock(&mut db, true).await; + crate::db::DatabaseModel::new() + .lock(&mut db, LockType::Write) + .await; ctx.shutdown .send(Some(Shutdown { zfs_pool: ctx.zfs_pool_name.clone(), diff --git a/appmgr/src/status/mod.rs b/appmgr/src/status/mod.rs index 0648a0522..68e2eca2e 100644 --- a/appmgr/src/status/mod.rs +++ b/appmgr/src/status/mod.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use chrono::{DateTime, Utc}; use color_eyre::eyre::eyre; use futures::{FutureExt, StreamExt}; -use patch_db::{DbHandle, HasModel, Map, ModelData}; +use patch_db::{DbHandle, HasModel, LockType, Map, ModelData}; use serde::{Deserialize, Serialize}; use tracing::instrument; @@ -38,7 +38,7 @@ pub async fn synchronize_all(ctx: &RpcContext) -> Result<(), Error> { // is likely iterating through packages in a different order. crate::db::DatabaseModel::new() .package_data() - .lock(&mut db, true) + .lock(&mut db, LockType::Write) .await; // Without the above lock, the below check operation will deadlock diff --git a/build/write-image.sh b/build/write-image.sh index e5737a7ad..bfa85ceeb 100755 --- a/build/write-image.sh +++ b/build/write-image.sh @@ -35,7 +35,7 @@ sudo umount /tmp/eos-mnt sudo mount ${OUTPUT_DEVICE}p3 /tmp/eos-mnt sudo sed -i 's/LABEL=writable/LABEL=green/g' /tmp/eos-mnt/etc/fstab -sudo sed -i 's/LABEL=system-boot \(\S\+\) \(\S\+\) defaults/LABEL=system-boot \1 \2 defaults,ro/g' /tmp/eos-mnt/etc/fstab +sudo sed -i 's/LABEL=system-boot\(\s\+\S\+\s\+\S\+\s\+\)defaults/LABEL=system-boot\1defaults,ro/g' /tmp/eos-mnt/etc/fstab # Enter the appmgr directory, copy over the built EmbassyOS binaries and systemd services, edit the nginx config, then create the .ssh directory cd appmgr/ diff --git a/patch-db b/patch-db index dc95daa95..66906b87f 160000 --- a/patch-db +++ b/patch-db @@ -1 +1 @@ -Subproject commit dc95daa959d0710df1f4003911aae20fbf9f5c35 +Subproject commit 66906b87f32a594f5eeefd5467fde0e91cf24b25