fix(archive): hold the thumbnail lease while compacting packs
CompactPacksAsync rewrote thumbs.pack under the sequence lease only, while thumbnail jobs append to the pack under the thumbs-<sequence id> lease, so a compaction racing a thumbnail pass could drop the entries just written. Compaction now takes the thumbnail lease too (CD-5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+37
-1
No files matched your search
@@ -150,6 +150,38 @@ public sealed class ArchiveIntegrityTests(TestContext context)
|
||||
Assert.FileMissing(Path.Combine(fx.Paths.LocksDirectory, "seq-dead.lease"));
|
||||
Assert.True(folder.Frames().All(File.Exists));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PackCompactionWaitsForTheThumbnailWriter()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var id = await IngestSeriesAsync(fx, "a", 2, 1);
|
||||
var folder = fx.Paths.Sequence((await fx.Db.Sequences.GetAsync(id))!.Folder);
|
||||
var hash = new byte[ThumbPack.HashLength];
|
||||
using (var pack = ThumbPackWriter.Open(folder.ThumbsPackPath))
|
||||
{
|
||||
// The same entry written again and again: everything but the last copy is garbage.
|
||||
for (var i = 0; i < 4; i++) pack.Append(0, 48, 32, hash, Photos.Jpeg(Start, 70 + i));
|
||||
pack.Commit();
|
||||
}
|
||||
var length = new FileInfo(folder.ThumbsPackPath).Length;
|
||||
|
||||
// A thumbnail pass holds the pack's own lease (not the sequence's) while it appends.
|
||||
Task<MaintenanceReport> maintenance;
|
||||
using (await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"thumbs-{id:N}", "thumbnails", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct))
|
||||
{
|
||||
maintenance = fx.Service.Maintenance.RunAsync(fx.Archive, dryRun: false, 0, _ => ValueTask.CompletedTask, fx.Ct);
|
||||
await Task.Delay(500, fx.Ct);
|
||||
Assert.False(maintenance.IsCompleted);
|
||||
Assert.Equal(length, new FileInfo(folder.ThumbsPackPath).Length);
|
||||
}
|
||||
|
||||
var report = await maintenance;
|
||||
Assert.SequenceEqual([folder.RelativeFolder], report.CompactedPacks);
|
||||
using var compacted = ThumbPackReader.Open(folder.ThumbsPackPath);
|
||||
Assert.Equal(0L, compacted.GarbageBytes);
|
||||
Assert.NotNull(compacted.Read(0));
|
||||
}
|
||||
}
|
||||
|
||||
internal static class SequencePathsExtensions
|
||||
|
||||
Reference in new issue
Block a user