improve patch-db locking

This commit is contained in:
Aiden McClelland
2021-10-12 17:59:16 -06:00
committed by Aiden McClelland
parent a59f0b18ca
commit 492cb7440b
7 changed files with 17 additions and 13 deletions

View File

@@ -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()

View File

@@ -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<R: AsyncRead + AsyncSeek + Unpin>(
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);

View File

@@ -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

View File

@@ -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(),

View File

@@ -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

View File

@@ -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/