querylog: the aside file's name says why, so a schema change is not called corrupt

This commit is contained in:
2026-08-17 20:24:21 +02:00
parent 377f00a35f
commit 64c0d723a6
4 changed files with 62 additions and 11 deletions
+11 -1
View File
@@ -190,7 +190,7 @@ fn countLines(text: []const u8) usize {
// querylog aside files
// ---------------------------------------------------------------------------
const aside_prefix = "querylog.db.corrupt-";
const aside_prefix = "querylog.db.";
const Names = struct {
items: std.ArrayList([]u8),
@@ -412,6 +412,10 @@ test "S7 case 3: a wrong user_version recreates and keeps the old file aside" {
defer asides.deinit();
try testing.expectEqual(@as(usize, 1), asides.items.items.len);
// The file was healthy: this build's schema moved, the database did not rot.
// An operator who reads "corrupt" here deletes a file that was never broken.
try testing.expect(std.mem.startsWith(u8, asides.items.items[0], "querylog.db.schema-changed-"));
const kept = try f.read(asides.items.items[0]);
defer testing.allocator.free(kept);
try testing.expectEqualSlices(u8, original, kept);
@@ -441,6 +445,12 @@ test "S7 case 4: a garbage file recreates and the garbage is preserved" {
defer asides.deinit();
try testing.expectEqual(@as(usize, 1), asides.items.items.len);
const expected: []const u8 = if (reason == .corrupt)
"querylog.db.corrupt-"
else
"querylog.db.not-a-database-";
try testing.expect(std.mem.startsWith(u8, asides.items.items[0], expected));
const kept = try f.read(asides.items.items[0]);
defer testing.allocator.free(kept);
try testing.expectEqualSlices(u8, &garbage, kept);