R-361: the safety dump destroyed the app's own database backup
gates / gates (push) Successful in 11s
gates / gates (push) Successful in 11s
writeSafetyDump called DumpOne into the app's OWN unit dir and renamed the result to pre-restore-* afterwards. DumpOne writes <stack>-<dbtype>.sql - the app's canonical dump - so every safety dump overwrote the app's real backup and then moved it away, leaving the app with no database backup until the next nightly run. A local restore-from-unit in that window tells the customer the app never had a database. The comment beside it asserted the rename meant it 'can never overwrite the app's real dump'. False as written, and believed for four months. Measured live before the fix: docmost and bookstack each held only pre-restore-* files and no canonical dump. DumpOneTo takes the final path and derives its own .tmp from it. DumpOne keeps its signature and calls it with the canonical name. writeSafetyDump asks for its own name directly; the rename is gone; the comment now states the invariant and how it is enforced. db_dumps no longer lists the undo copies. All three consumers of Manifest.DBDumps were grepped and named - all inside recovery_unit.go, none reads it for recovery. The files are neither deleted nor hidden. Tests 1485 -> 1493. FIVE red-proofs, TWO PASSED first time and both are reported: the behavioural tests inject the dump seam so a mutation inside DumpOneTo was invisible, and 1.3 had no test at all. Guards added at the layer each defect lives in; both mutations then convicted.
This commit is contained in:
@@ -34,15 +34,15 @@ func TestR355_SafetyDumpIsTakenForTheCorrectlyAttributedApp(t *testing.T) {
|
||||
{StackName: "paperless-ngx", DBType: DBTypePostgres, ContainerName: "paperless-postgres", ContainerID: "cid"},
|
||||
}, nil
|
||||
}
|
||||
m.safetyDumpFn = func(ctx context.Context, db DiscoveredDB, dumpDir string) DumpResult {
|
||||
p := filepath.Join(dumpDir, string(db.StackName)+"-"+string(db.DBType)+".sql")
|
||||
if err := os.MkdirAll(dumpDir, 0o755); err != nil {
|
||||
m.safetyDumpFn = func(ctx context.Context, db DiscoveredDB, finalPath string) DumpResult {
|
||||
// R-361: the seam takes the FINAL PATH now.
|
||||
if err := os.MkdirAll(filepath.Dir(finalPath), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(p, []byte("-- 72 tables\n"), 0o644); err != nil {
|
||||
if err := os.WriteFile(finalPath, []byte("-- 72 tables\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return DumpResult{DB: db, FilePath: p, Size: 13}
|
||||
return DumpResult{DB: db, FilePath: finalPath, Size: 13}
|
||||
}
|
||||
|
||||
// v0.220.0 (R-379): writeSafetyDump returns the SET it wrote, so a rollback can re-apply EVERY
|
||||
|
||||
Reference in New Issue
Block a user