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
@@ -279,7 +279,7 @@ public sealed class ThumbPackReader : IDisposable
|
||||
public void Dispose() => _stream?.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>Appends thumbnails to a pack; one writer per pack at a time (the sequence lease guarantees it).</summary>
|
||||
/// <summary>Appends thumbnails to a pack; one writer per pack at a time (the <c>thumbs-<sequence id></c> lease guarantees it).</summary>
|
||||
public sealed class ThumbPackWriter : IDisposable
|
||||
{
|
||||
private readonly FileStream _stream;
|
||||
|
||||
@@ -188,7 +188,11 @@ public sealed class ArchiveMaintenance
|
||||
if (length == 0 || garbage < length * CompactionRatio) continue;
|
||||
compacted.Add(location.Folder);
|
||||
if (dryRun) continue;
|
||||
// The thumbnail builder appends under the thumbs lease only: holding it too keeps the compacted pack from
|
||||
// replacing the file under a writer, whose later thumbnails would land in the orphaned one.
|
||||
await using (await _writer.LockAsync(paths, location.Id, cancellationToken).ConfigureAwait(false))
|
||||
using (await LeaseFile.AcquireAsync(paths.LocksDirectory, $"thumbs-{location.Id:N}", _writer.Options.Owner, _writer.Options.LeaseWait,
|
||||
_writer.Options.LeaseDuration, cancellationToken).ConfigureAwait(false))
|
||||
ThumbPackWriter.Compact(sequence.ThumbsPackPath);
|
||||
}
|
||||
return compacted;
|
||||
|
||||
Reference in new issue
Block a user