fix(archive): convert job applies exactly the confirmed plan, resumes safely and watches its space
The convert job planned every sequence again when it ran and checked only the frames version, so a verify, a repaired upload or a tier change between the dry run and the job let it replace photos the confirmed plan had listed as staying unchanged. - Each sequence of a convert job now carries the digest of the photos it converts, each with its SHA-256 (ConvertSequencePlan.Digest, also in the plan's fingerprint). Under the sequence's lease, its sidecar settled, the job plans it again and goes on only while the digest matches; it then pins those photos (convert-<job>.pins), so photos that come in or are verified later stay as they are, a retry included. Stage B checks under the lease that every pinned photo still holds the content converted instead of holding the frames version, so a sequence still receiving uploads converts what was confirmed. - A resumed job settles the journals a crash left in a sequence (a half-done replacement among them) before it plans, and reports a sequence its replacement completed as Converted, never Nothing or a partial swap. - The passes a converted or new sequence needs are queued as soon as its outcome is journaled; the journal records the statuses they follow from and whether they were queued, so a pause, yield, stop or crash no longer loses them. - Staged conversions of a blocked or failed sequence are kept for the retry, which re-verifies and takes them; maintenance keeps a convert job's staging while the job is queued, running or paused, and removes its journal and staging once the job is done or gone from the history. - A dry run counts the sequences of a queued conversion as busy, so the same conversion cannot be confirmed twice. - New sequence copies are owned by the source's owner, else by the requesting user's id (never the user name); a staged copy that vanished fails the sequence instead of leaving its photo out; the job log states how many photos stayed in the source alone. - Free space is measured where the conversion writes: the server takes the tighter of the space path's volume and the archive's own (Unraid cache), the desktop asks Windows (GetDiskFreeSpaceEx), which also measures UNC archives; the job checks again before each sequence and each photo, scaling estimates by the files staged so far, and stops before the volume fills with what it staged kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 2d7d461c33b9f257bf57793cc7cf331d0425c14e)
This commit is contained in:
1 parent
f86a151a5d
commit
67a6d51cbe
17 files changed
+1222
-236
No files matched your search
@@ -43,7 +43,7 @@ public enum ConvertSkip
|
||||
/// <summary>Why a whole sequence is not converted now; nothing of it is touched.</summary>
|
||||
public enum ConvertBlock
|
||||
{
|
||||
/// <summary>A running or paused job works on the sequence or its whole archive.</summary>
|
||||
/// <summary>A running or paused job works on the sequence or its whole archive, or a conversion of it waits in the queue.</summary>
|
||||
Busy,
|
||||
|
||||
/// <summary>The archive is offline or read-only.</summary>
|
||||
@@ -52,15 +52,21 @@ public enum ConvertBlock
|
||||
/// <summary>The sequence's sidecar cannot be read, or belongs to another sequence.</summary>
|
||||
Unreadable,
|
||||
|
||||
/// <summary>The sequence's frames changed after the plan was made (found by the job, which then leaves it as it is).</summary>
|
||||
/// <summary>
|
||||
/// The photos the sequence converts are no longer those of the plan confirmed (found by the job, which then leaves it as
|
||||
/// it is).
|
||||
/// </summary>
|
||||
FramesChanged,
|
||||
}
|
||||
|
||||
/// <summary>Frames of a sequence that are not converted, and why.</summary>
|
||||
public sealed record ConvertSkipped(ConvertSkip Reason, int Frames);
|
||||
|
||||
/// <summary>One frame a conversion converts: its id and index, its file and format, its size and the converted file's estimated size.</summary>
|
||||
public sealed record ConvertFramePlan(Guid FrameId, int Index, string File, ImageFileFormat Format, long Size, long EstimatedBytes);
|
||||
/// <summary>
|
||||
/// One frame a conversion converts: its id and index, its file and format, its size, the converted file's estimated size,
|
||||
/// and the SHA-256 of the content converted.
|
||||
/// </summary>
|
||||
public sealed record ConvertFramePlan(Guid FrameId, int Index, string File, ImageFileFormat Format, long Size, long EstimatedBytes, string? Sha256 = null);
|
||||
|
||||
/// <summary>
|
||||
/// One sequence of a conversion plan: the frames converted, those skipped with why, the frames version the plan was made at,
|
||||
@@ -79,6 +85,21 @@ public sealed record ConvertSequencePlan(Guid SequenceId, string Title, string F
|
||||
public long BytesAfter => Frames.Sum(f => f.EstimatedBytes);
|
||||
|
||||
public int SkippedFrames => Skipped.Sum(s => s.Frames);
|
||||
|
||||
/// <summary>
|
||||
/// A digest of the photos the sequence converts: each frame in order with the SHA-256 of the content converted. A
|
||||
/// conversion job converts the sequence only while its plan there still has the digest the user confirmed.
|
||||
/// </summary>
|
||||
public string Digest() => DigestOf(Frames.Select(f => (f.FrameId, f.Sha256)));
|
||||
|
||||
/// <summary>The digest of frames, each with the SHA-256 of its content, in order (<see cref="Digest"/>).</summary>
|
||||
public static string DigestOf(IEnumerable<(Guid FrameId, string? Sha256)> frames)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(frames);
|
||||
var text = new StringBuilder();
|
||||
foreach (var (id, sha) in frames) text.Append(CultureInfo.InvariantCulture, $"{id:N}|{sha?.ToLowerInvariant()}\n");
|
||||
return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(text.ToString())));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,15 +129,16 @@ public sealed record ConvertPlan(Guid ArchiveId, ConvertOptions Options, Convert
|
||||
public int Skipped => Sequences.Sum(s => s.SkippedFrames);
|
||||
|
||||
/// <summary>
|
||||
/// A digest of what the plan converts (options, mode, and each sequence in order with its frames version, the frames
|
||||
/// converted and skipped, and what blocks it), the same for two plans of the same archive state.
|
||||
/// A digest of what the plan converts (options, mode, and each sequence in order with its frames version, the photos
|
||||
/// converted with their content (<see cref="ConvertSequencePlan.Digest"/>), those skipped, and what blocks it), the
|
||||
/// same for two plans of the same archive state.
|
||||
/// </summary>
|
||||
public string Fingerprint()
|
||||
{
|
||||
var text = new StringBuilder().Append(Options.Key).Append('|').Append(Mode).Append('\n');
|
||||
foreach (var s in Sequences)
|
||||
{
|
||||
text.Append(CultureInfo.InvariantCulture, $"{s.SequenceId:N}|{s.FramesVersion}|{s.Frames.Count}|{s.BytesBefore}|");
|
||||
text.Append(CultureInfo.InvariantCulture, $"{s.SequenceId:N}|{s.FramesVersion}|{s.Frames.Count}|{s.BytesBefore}|{s.Digest()}|");
|
||||
foreach (var skipped in s.Skipped) text.Append(CultureInfo.InvariantCulture, $"{skipped.Reason}:{skipped.Frames};");
|
||||
foreach (var blocked in s.Blocked) text.Append(blocked).Append(';');
|
||||
text.Append('\n');
|
||||
@@ -180,7 +202,7 @@ public static class ConvertPlanner
|
||||
skipped[reason] = skipped.GetValueOrDefault(reason) + 1;
|
||||
continue;
|
||||
}
|
||||
frames.Add(new ConvertFramePlan(frame.Id, frame.I, frame.File, frame.Format, frame.Size, EstimateBytes(options, frame.W, frame.H)));
|
||||
frames.Add(new ConvertFramePlan(frame.Id, frame.I, frame.File, frame.Format, frame.Size, EstimateBytes(options, frame.W, frame.H), frame.Sha256));
|
||||
}
|
||||
return new ConvertSequencePlan(manifest.Id, title, folder.RelativeFolder, manifest.Versions.Frames, frames,
|
||||
[.. skipped.OrderBy(s => s.Key).Select(s => new ConvertSkipped(s.Key, s.Value))], []);
|
||||
|
||||
Reference in new issue
Block a user