mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-18 19:25:56 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c0d2db368 | ||
|
|
d86a1676fe | ||
|
|
53a05820c8 |
No files matched your search
Generated
+3
-3
@@ -491,7 +491,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "coa-core"
|
||||
version = "0.6.14"
|
||||
version = "0.6.15"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
@@ -520,7 +520,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "coa-release"
|
||||
version = "0.6.14"
|
||||
version = "0.6.15"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"coa-core",
|
||||
@@ -529,7 +529,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "coa-server-manager"
|
||||
version = "0.6.14"
|
||||
version = "0.6.15"
|
||||
dependencies = [
|
||||
"coa-core",
|
||||
"serde",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/coa-core", "crates/coa-release", "src-tauri"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.6.14"
|
||||
version = "0.6.15"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-only"
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
area: manager
|
||||
type: fixed
|
||||
audience: admins
|
||||
title: Large server updates no longer repeatedly rewrite the recovery journal
|
||||
---
|
||||
Updates containing rebuilt navigation data now prepare all recovery copies before replacing files. Interrupted updates remain recoverable without rewriting the full journal for every file.
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
area: manager
|
||||
type: fixed
|
||||
audience: admins
|
||||
title: Starting the server waits for update checks and identifies ongoing maintenance
|
||||
---
|
||||
Downloading an update manifest no longer blocks startup. A start waits up to 30 seconds for a check to finish; other active maintenance still blocks it safely and shows its operation, process and start time.
|
||||
@@ -100,7 +100,7 @@ pub(crate) fn validate_update(root: &Path) -> Result<DriverOutcome> {
|
||||
fn run_inner(root: &Path, verb: Verb, validating_update: bool) -> Result<DriverOutcome> {
|
||||
let root = fsx::canonicalize_lenient(root)?;
|
||||
let _update_lock = if !validating_update && matches!(verb, Verb::StartAll | Verb::StartWorld) {
|
||||
Some(crate::update::operation_lock(&crate::registry::metadata_dir_for(&root)?)?)
|
||||
Some(crate::update::operation_lock_for(&crate::registry::metadata_dir_for(&root)?, "starting server", true)?)
|
||||
} else { None };
|
||||
if !validating_update && matches!(verb, Verb::StartAll | Verb::StartWorld) {
|
||||
crate::update::ensure_recovered(&crate::registry::metadata_dir_for(&root)?)?;
|
||||
|
||||
+102
-17
@@ -308,9 +308,12 @@ pub fn preview(root: &Path, meta: &InstallMeta, source: &Source, trusted_key: &s
|
||||
pub fn preview_with(root: &Path, meta: &InstallMeta, source: &Source, trusted_key: &str, resolutions: &BTreeMap<String, Resolution>, access: DatabaseAccess) -> Result<Preview> {
|
||||
refuse_for_docker(root)?;
|
||||
let meta_dir = crate::registry::metadata_dir_for(root)?;
|
||||
let _lock = operation_lock(&meta_dir)?;
|
||||
ensure_recovered(&meta_dir)?;
|
||||
let observed_version = MetaDir::open(&meta_dir)?.1.core.version;
|
||||
let (m, _) = fetch_manifest(source, trusted_key)?;
|
||||
let _lock = operation_lock_for(&meta_dir, "checking updates", false)?;
|
||||
ensure_recovered(&meta_dir)?;
|
||||
let (_, current_meta) = MetaDir::open(&meta_dir)?;
|
||||
let meta = if current_meta.core.version != observed_version { ¤t_meta } else { meta };
|
||||
check_manifest(&m)?;
|
||||
reject_downgrade(meta, &m)?;
|
||||
let mut items = plan(root, meta, &m, resolutions, None)?;
|
||||
@@ -687,6 +690,25 @@ fn restore_transaction(root: &Path, meta: &Path, before: &Path, txn: &mut Txn, e
|
||||
}
|
||||
|
||||
fn apply_ops(root: &Path, tree: &Path, before: &Path, files: &[FileEntry], txn: &mut Txn, meta_dir: &Path, fail_after: Option<usize>) -> Result<()> {
|
||||
if fail_after == Some(0) && !txn.ops.is_empty() {
|
||||
return Err(Error::Invalid("simulated failure".into()));
|
||||
}
|
||||
let entries: BTreeMap<_, _> = files.iter().map(|entry| (entry.path.as_str(), entry)).collect();
|
||||
// Prepare every recovery copy before changing any destination. One durable journal
|
||||
// can then cover the entire file phase: recovery restores old files even if their
|
||||
// replacement was not reached, and removes newly created files only by exact hash.
|
||||
// Rewriting the full journal twice per file makes large navigation updates quadratic.
|
||||
for op in &txn.ops {
|
||||
let target = fsx::ensure_within(root, &fsx::safe_join(root, &op.path)?)?;
|
||||
if op.had_previous {
|
||||
let keep = fsx::safe_join(before, &op.path)?;
|
||||
fs::create_dir_all(keep.parent().unwrap())?;
|
||||
fsx::atomic_write(&keep, &fs::read(&target)?)?;
|
||||
txn.recovery_hashes.insert(op.path.clone(), fsx::sha256_file(&keep)?);
|
||||
}
|
||||
}
|
||||
for op in &mut txn.ops { op.started = true; }
|
||||
save(meta_dir, txn)?;
|
||||
let mut completed = 0usize;
|
||||
for i in 0..txn.ops.len() {
|
||||
if fail_after == Some(completed) {
|
||||
@@ -695,17 +717,7 @@ fn apply_ops(root: &Path, tree: &Path, before: &Path, files: &[FileEntry], txn:
|
||||
let (path, action) = (txn.ops[i].path.clone(), txn.ops[i].action);
|
||||
let target = fsx::ensure_within(root, &fsx::safe_join(root, &path)?)?;
|
||||
let staged = fsx::safe_join(tree, &path)?;
|
||||
let entry = files.iter().find(|f| f.path == path).expect("listed");
|
||||
if target.is_file() {
|
||||
let keep = fsx::safe_join(before, &path)?;
|
||||
fs::create_dir_all(keep.parent().unwrap())?;
|
||||
fsx::atomic_write(&keep, &fs::read(&target)?)?;
|
||||
txn.recovery_hashes.insert(path.clone(), fsx::sha256_file(&keep)?);
|
||||
}
|
||||
// Journal only after the old bytes are safely saved; a crash during backup must not
|
||||
// turn an untouched file into a rollback operation with a missing saved copy.
|
||||
txn.ops[i].started = true;
|
||||
save(meta_dir, txn)?;
|
||||
let entry = entries.get(path.as_str()).expect("listed");
|
||||
fs::create_dir_all(target.parent().unwrap())?;
|
||||
match action {
|
||||
Action::Create | Action::Replace => {
|
||||
@@ -730,10 +742,9 @@ fn apply_ops(root: &Path, tree: &Path, before: &Path, files: &[FileEntry], txn:
|
||||
Action::Skip | Action::Conflict => {}
|
||||
}
|
||||
txn.ops[i].done = true;
|
||||
save(meta_dir, txn)?;
|
||||
completed += 1;
|
||||
}
|
||||
Ok(())
|
||||
save(meta_dir, txn)
|
||||
}
|
||||
|
||||
/// Put every touched file back the way it was. Files created by the update (no previous version) are removed only if
|
||||
@@ -772,11 +783,26 @@ pub fn rollback(root: &Path, meta_dir: &Path, id: &str, env: &dyn Env) -> Result
|
||||
}
|
||||
|
||||
pub(crate) fn operation_lock(meta_dir: &Path) -> Result<fs::File> {
|
||||
operation_lock_for(meta_dir, "server maintenance", false)
|
||||
}
|
||||
|
||||
pub(crate) fn operation_lock_for(meta_dir: &Path, operation: &str, wait_for_check: bool) -> Result<fs::File> {
|
||||
fs::create_dir_all(meta_dir)?;
|
||||
let lock = fs::OpenOptions::new().read(true).write(true).create(true).truncate(false).open(meta_dir.join("update.lock"))?;
|
||||
if !fs4::fs_std::FileExt::try_lock_exclusive(&lock)? {
|
||||
return Err(Error::Invalid("Another update, repair or recovery is in progress.".into()));
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
|
||||
loop {
|
||||
if fs4::fs_std::FileExt::try_lock_exclusive(&lock)? { break; }
|
||||
let owner = fsx::read_json::<serde_json::Value>(&meta_dir.join("update-lock-owner.json")).ok();
|
||||
let checking = owner.as_ref().and_then(|owner| owner.get("operation")).and_then(|value| value.as_str()) == Some("checking updates");
|
||||
if wait_for_check && checking && std::time::Instant::now() < deadline {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
continue;
|
||||
}
|
||||
let details = owner.as_ref().and_then(|owner| Some(format!(" Operation: {}; Manager process: {}; started: {}.", owner.get("operation")?.as_str()?, owner.get("pid")?.as_u64()?, owner.get("started")?.as_str()?))).unwrap_or_default();
|
||||
return Err(Error::Invalid(format!("Another update, repair or recovery is in progress.{details} Wait for that operation to finish, then retry.")));
|
||||
}
|
||||
let record = serde_json::json!({"operation": operation, "pid": std::process::id(), "started": chrono::Utc::now().to_rfc3339()});
|
||||
fsx::atomic_write_json(&meta_dir.join("update-lock-owner.json"), &record)?;
|
||||
Ok(lock)
|
||||
}
|
||||
|
||||
@@ -1350,6 +1376,25 @@ mod tests {
|
||||
w
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_waits_for_an_update_check_but_not_for_active_maintenance() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let checker = operation_lock_for(temp.path(), "checking updates", false).unwrap();
|
||||
let root = temp.path().to_path_buf();
|
||||
let release = std::thread::spawn(move || {
|
||||
std::thread::sleep(std::time::Duration::from_millis(150));
|
||||
drop(checker);
|
||||
});
|
||||
let start = operation_lock_for(&root, "starting server", true).unwrap();
|
||||
release.join().unwrap();
|
||||
let error = operation_lock(&root).unwrap_err().to_string();
|
||||
assert!(error.contains("starting server"));
|
||||
assert!(error.contains(&std::process::id().to_string()));
|
||||
drop(start);
|
||||
// Stale owner metadata is harmless once the OS lock is released.
|
||||
operation_lock(&root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_manager_realm_launcher_is_replaced_during_update() {
|
||||
let w = legacy_launcher_world(false);
|
||||
@@ -1544,6 +1589,46 @@ mod tests {
|
||||
assert_eq!(fs::read(saved).unwrap(), b"my-custom-build", "the replaced custom build is kept for rollback");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn power_loss_during_bulk_files_restores_written_and_unwritten_files() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
let root = d.path().join("root");
|
||||
let meta = d.path().join("meta");
|
||||
let tree = d.path().join("tree");
|
||||
let before = meta.join("updates/bulk/before");
|
||||
let mut files = Vec::new();
|
||||
let mut ops = Vec::new();
|
||||
for (path, previous) in [("Data/maps/first.map", true), ("Data/maps/new.map", false), ("Data/maps/last.map", true)] {
|
||||
if previous { write(&root, path, b"old"); }
|
||||
write(&tree, path, b"new");
|
||||
let hash = fsx::sha256_file(&tree.join(path)).unwrap();
|
||||
files.push(FileEntry { path: path.into(), sha256: hash.clone(), size: 3, policy: ReplacePolicy::Replace, owner: crate::manifest::Owner::Core });
|
||||
ops.push(Op { path: path.into(), action: if previous { Action::Replace } else { Action::Create }, reason: None,
|
||||
new_sha256: hash, had_previous: previous, started: false, done: false });
|
||||
}
|
||||
let mut txn = Txn { id: "bulk".into(), state: State::Applying, from_version: Some("1".into()), to_version: "2".into(),
|
||||
recovery_point: None, databases_started: false, ops, message: None, recovery_hashes: BTreeMap::new() };
|
||||
fs::create_dir_all(before.parent().unwrap()).unwrap();
|
||||
assert!(apply_ops(&root, &tree, &before, &files, &mut txn, &meta, Some(2)).is_err());
|
||||
// A power loss sees the pre-write checkpoint, not the in-memory completed flags.
|
||||
let mut durable = load(&meta, "bulk").unwrap();
|
||||
assert!(durable.ops.iter().all(|op| op.started && !op.done));
|
||||
assert_eq!(fs::read(root.join("Data/maps/last.map")).unwrap(), b"old");
|
||||
restore_files(&root, &before, &mut durable).unwrap();
|
||||
assert_eq!(fs::read(root.join("Data/maps/first.map")).unwrap(), b"old");
|
||||
assert_eq!(fs::read(root.join("Data/maps/last.map")).unwrap(), b"old");
|
||||
assert!(!root.join("Data/maps/new.map").exists());
|
||||
// If preparing any recovery copy fails, no destination may be changed.
|
||||
for op in &mut durable.ops { op.started = false; op.done = false; }
|
||||
durable.recovery_hashes.clear();
|
||||
save(&meta, &durable).unwrap();
|
||||
fs::remove_file(root.join("Data/maps/last.map")).unwrap();
|
||||
assert!(apply_ops(&root, &tree, &before, &files, &mut durable, &meta, None).is_err());
|
||||
assert_eq!(fs::read(root.join("Data/maps/first.map")).unwrap(), b"old");
|
||||
assert!(!root.join("Data/maps/new.map").exists());
|
||||
assert!(load(&meta, "bulk").unwrap().ops.iter().all(|op| !op.started));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failure_in_the_middle_of_applying_restores_every_file_byte_for_byte() {
|
||||
for fail_after in [0usize, 1, 2] {
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "coa-server-manager",
|
||||
"version": "0.6.14",
|
||||
"version": "0.6.15",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coa-server-manager",
|
||||
"version": "0.6.14",
|
||||
"version": "0.6.15",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.12.0",
|
||||
"@tauri-apps/plugin-dialog": "^2.8.0",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "coa-server-manager",
|
||||
"private": true,
|
||||
"version": "0.6.14",
|
||||
"version": "0.6.15",
|
||||
"license": "AGPL-3.0-only",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "CoA Server Manager",
|
||||
"version": "0.6.14",
|
||||
"version": "0.6.15",
|
||||
"identifier": "com.coa.servermanager",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
|
||||
Reference in new issue
Block a user