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
@@ -8,13 +8,14 @@ namespace Chronos.Data.Archiving.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="JobKind.Convert"/>: a mass conversion (owner review 2, R7; BRIEF §12.5) of the sequences of a confirmed plan
|
||||
/// (<see cref="ConvertJobParameters"/>) through <see cref="MassConverter"/>, which plans again, refuses when the archive's
|
||||
/// volume lacks the space, and converts one sequence at a time, each all or nothing; its journal makes every stage
|
||||
/// (<see cref="ConvertJobParameters"/>) through <see cref="MassConverter"/>, which settles what a crash left half-way, refuses
|
||||
/// when the volume lacks the space (measured again before each sequence and each photo), and converts one sequence at a
|
||||
/// time, each all or nothing and only while the photos it converts are those confirmed; its journal makes every stage
|
||||
/// resumable. Progress counts photos; the checkpoint only marks a resume, the journal says where. Each sequence whose frames
|
||||
/// were replaced is told as <c>converted</c>, each new sequence as <c>created</c> (<see cref="ArchiveServiceOptions.SequenceChanged"/>),
|
||||
/// as soon as it is done; the passes they need (light analysis, a deep one when the source had it, thumbnails and
|
||||
/// proxies) are queued as follow-ups. Sequences left as they were (changed after the plan, busy, a photo that failed) are
|
||||
/// logged and fail the job at the end, after the others are converted; a retry tries them again.
|
||||
/// and the passes it needs (light analysis, a deep one when the source had it, thumbnails and proxies) are queued as
|
||||
/// follow-ups, as soon as it is done. Sequences left as they were (changed after the plan, busy, a photo that failed) are
|
||||
/// logged and fail the job at the end, after the others are converted; a retry tries them again with what they staged.
|
||||
/// </summary>
|
||||
internal sealed class ConvertJobHandler(ChronosDatabase db, MassConverter converter, Func<Guid, string, CancellationToken, Task>? sequenceChanged) : IJobHandler
|
||||
{
|
||||
@@ -35,22 +36,24 @@ internal sealed class ConvertJobHandler(ChronosDatabase db, MassConverter conver
|
||||
if (parameters.Fingerprint.Length == 0) throw new InvalidOperationException($"Convert job {context.Job.Id} has no confirmed plan.");
|
||||
var archive = await db.Archives.GetAsync(parameters.ArchiveId, context.Cancellation).ConfigureAwait(false)
|
||||
?? throw new InvalidOperationException($"Convert job {context.Job.Id} does not name a known archive.");
|
||||
var by = context.Job.CreatedBy is { } user ? (await db.Users.GetAsync(user, context.Cancellation).ConfigureAwait(false))?.Username : null;
|
||||
var result = await converter.RunAsync(archive, parameters, context.Job.Id, by, new ConvertCallbacks(
|
||||
var name = context.Job.CreatedBy is { } user ? (await db.Users.GetAsync(user, context.Cancellation).ConfigureAwait(false))?.Username : null;
|
||||
var result = await converter.RunAsync(archive, parameters, context.Job.Id, new ConvertRequester(name, context.Job.CreatedBy), new ConvertCallbacks(
|
||||
(done, total) => context.ReportAsync(done, total),
|
||||
(done, total) => context.CheckpointAsync(Checkpoint, done, total),
|
||||
context.Log, TellAsync), context.Cancellation).ConfigureAwait(false);
|
||||
await QueueAsync(context, result).ConfigureAwait(false);
|
||||
context.Log, TellAsync, requests => QueueAsync(context, requests)), context.Cancellation).ConfigureAwait(false);
|
||||
context.Log(Loc.L("Archive.Log.ConvertDone", result.Sequences.Count(s => s.Outcome == ConvertOutcome.Converted),
|
||||
result.Sequences.Count(s => s.Outcome == ConvertOutcome.Created), result.Frames));
|
||||
var kept = result.Kept.Count();
|
||||
if (kept > 0) throw new InvalidOperationException(Loc.Plural("Archive.Error.ConvertKept", kept));
|
||||
}
|
||||
|
||||
/// <summary>Queues what the converted sequences need, each kind once per sequence; a failure is logged, never passed on.</summary>
|
||||
private async Task QueueAsync(JobContext context, ConvertResult result)
|
||||
/// <summary>
|
||||
/// Queues what a sequence converted or made needs as soon as its outcome is journaled, each kind once per sequence; a
|
||||
/// failure is logged, never passed on.
|
||||
/// </summary>
|
||||
private async ValueTask QueueAsync(JobContext context, IReadOnlyList<ArchiveJobRequest> requests)
|
||||
{
|
||||
foreach (var request in result.FollowUps)
|
||||
foreach (var request in requests)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user