mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-20 19:25:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d86a1676fe | ||
|
|
53a05820c8 |
No files matched your search
Generated
+3
-3
@@ -491,7 +491,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "coa-core"
|
name = "coa-core"
|
||||||
version = "0.6.14"
|
version = "0.6.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -520,7 +520,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "coa-release"
|
name = "coa-release"
|
||||||
version = "0.6.14"
|
version = "0.6.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"coa-core",
|
"coa-core",
|
||||||
@@ -529,7 +529,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "coa-server-manager"
|
name = "coa-server-manager"
|
||||||
version = "0.6.14"
|
version = "0.6.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"coa-core",
|
"coa-core",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "2"
|
|||||||
members = ["crates/coa-core", "crates/coa-release", "src-tauri"]
|
members = ["crates/coa-core", "crates/coa-release", "src-tauri"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.6.14"
|
version = "0.6.15"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-only"
|
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.
|
||||||
@@ -687,6 +687,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<()> {
|
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;
|
let mut completed = 0usize;
|
||||||
for i in 0..txn.ops.len() {
|
for i in 0..txn.ops.len() {
|
||||||
if fail_after == Some(completed) {
|
if fail_after == Some(completed) {
|
||||||
@@ -695,17 +714,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 (path, action) = (txn.ops[i].path.clone(), txn.ops[i].action);
|
||||||
let target = fsx::ensure_within(root, &fsx::safe_join(root, &path)?)?;
|
let target = fsx::ensure_within(root, &fsx::safe_join(root, &path)?)?;
|
||||||
let staged = fsx::safe_join(tree, &path)?;
|
let staged = fsx::safe_join(tree, &path)?;
|
||||||
let entry = files.iter().find(|f| f.path == path).expect("listed");
|
let entry = entries.get(path.as_str()).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)?;
|
|
||||||
fs::create_dir_all(target.parent().unwrap())?;
|
fs::create_dir_all(target.parent().unwrap())?;
|
||||||
match action {
|
match action {
|
||||||
Action::Create | Action::Replace => {
|
Action::Create | Action::Replace => {
|
||||||
@@ -730,10 +739,9 @@ fn apply_ops(root: &Path, tree: &Path, before: &Path, files: &[FileEntry], txn:
|
|||||||
Action::Skip | Action::Conflict => {}
|
Action::Skip | Action::Conflict => {}
|
||||||
}
|
}
|
||||||
txn.ops[i].done = true;
|
txn.ops[i].done = true;
|
||||||
save(meta_dir, txn)?;
|
|
||||||
completed += 1;
|
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
|
/// Put every touched file back the way it was. Files created by the update (no previous version) are removed only if
|
||||||
@@ -1544,6 +1552,46 @@ mod tests {
|
|||||||
assert_eq!(fs::read(saved).unwrap(), b"my-custom-build", "the replaced custom build is kept for rollback");
|
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]
|
#[test]
|
||||||
fn failure_in_the_middle_of_applying_restores_every_file_byte_for_byte() {
|
fn failure_in_the_middle_of_applying_restores_every_file_byte_for_byte() {
|
||||||
for fail_after in [0usize, 1, 2] {
|
for fail_after in [0usize, 1, 2] {
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "coa-server-manager",
|
"name": "coa-server-manager",
|
||||||
"version": "0.6.14",
|
"version": "0.6.15",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coa-server-manager",
|
"name": "coa-server-manager",
|
||||||
"version": "0.6.14",
|
"version": "0.6.15",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2.12.0",
|
"@tauri-apps/api": "^2.12.0",
|
||||||
"@tauri-apps/plugin-dialog": "^2.8.0",
|
"@tauri-apps/plugin-dialog": "^2.8.0",
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "coa-server-manager",
|
"name": "coa-server-manager",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.14",
|
"version": "0.6.15",
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "CoA Server Manager",
|
"productName": "CoA Server Manager",
|
||||||
"version": "0.6.14",
|
"version": "0.6.15",
|
||||||
"identifier": "com.coa.servermanager",
|
"identifier": "com.coa.servermanager",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
|
|||||||
Reference in new issue
Block a user