feat(server): show the Unraid array's free space and check the archive volume before filing uploads

On Unraid the archive is a user share (FUSE shfs), which reports the share's
primary storage, often the cache, while the mover sends the photos to the
array: the admin panel showed the cache's free space (owner review 2, R2).

- New option SpacePath (server.json) / CHRONOS_SPACE_PATH: the admin panel
  shows that folder's volume; empty, or a folder that cannot be measured, falls
  back to the archive's volume (one warning, at start, not per request).
- VolumeSpace measures folders (DriveInfo; the path root on Windows) and reads
  the filesystem type and mount from /proc/self/mountinfo on Linux (longest
  mount point on segment boundaries, octal escapes, optional fields, the top of
  stacked mounts), since DriveFormat calls an shfs share only "fuse". It is an
  injectable service, so tests simulate a full volume; the /data checks use it.
- ArchiveStatsDto keeps FreeBytes/CapacityBytes for the shown volume and gains
  optional trailing members: the write volume's figures (when a space path is
  in use and they differ), the filesystem type and UsesSpacePath.
- Admin panel (dashboard and archive): a tooltip on the storage figures names
  the volume and its filesystem and, on an shfs share without a space path,
  says they are the primary storage and to map the array view to /space; a
  "Write volume" line shows the archive's own volume when it differs.
- Completing an upload, a render upload or a render node's result checks the
  archive volume for its size plus the 64 MiB reserve before the staging copy
  and answers 507 insufficient_storage, the upload still receiving.
- Diagnostics list the archive and space volumes with filesystem and mount.
- Unraid template: optional read-only "Array view" /space (default
  /mnt/user0/Timelapse) and "Space path" CHRONOS_SPACE_PATH=/space; compose and
  the releases README describe the same as an option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-26 21:58:27 +01:00
1 parent 5209579631
commit d560b41b81
22 files changed
+641 -66

No files matched your search

+24 -6
View File
@@ -17,9 +17,10 @@ namespace Chronos.Server.Storage;
/// <summary>
/// Chunked, resumable, hash-verified frame uploads (BRIEF §14.4): start (short-circuit on a known SHA-256 held by an
/// intact frame, resume an unfinished upload, quota and disk checks), idempotent chunks, and completion that stages the
/// file on the archive volume, verifies its hash and hands it to <see cref="IArchiveIngest"/>, which repairs a missing or
/// damaged frame of that content (no quota is charged for a repair: the archive already counts those bytes).
/// intact frame, resume an unfinished upload, quota and disk checks), idempotent chunks, and completion that checks the
/// archive volume's free space, stages the file there, verifies its hash and hands it to <see cref="IArchiveIngest"/>,
/// which repairs a missing or damaged frame of that content (no quota is charged for a repair: the archive already
/// counts those bytes).
/// </summary>
public sealed class UploadService(
ChronosDatabase db,
@@ -29,11 +30,12 @@ public sealed class UploadService(
IArchiveIngest ingest,
SequenceJobs sequenceJobs,
EventHub events,
VolumeSpace volumes,
IHostApplicationLifetime lifetime,
TimeProvider time,
ILogger<UploadService> logger)
{
/// <summary>Space kept free on the upload volume beyond the announced size.</summary>
/// <summary>Space kept free on the upload and archive volumes beyond an upload's size.</summary>
private const long DiskReserve = 64L * 1024 * 1024;
/// <summary>Card events one account may publish per minute: progress once a second leaves room for every start and end.</summary>
@@ -74,7 +76,7 @@ public sealed class UploadService(
if (caller.User.UsedBytes + pending + request.Size > caller.User.QuotaBytes)
return Fail<StartUploadResponse>(403, "quota_exceeded", caller.User.QuotaBytes.ToString(CultureInfo.InvariantCulture));
}
if (UploadRules.FreeBytes(options.UploadsPath) is { } free && free < request.Size + DiskReserve)
if (volumes.Measure(options.UploadsPath) is { } uploadVolume && uploadVolume.FreeBytes < request.Size + DiskReserve)
return Fail<StartUploadResponse>(507, "insufficient_storage");
var now = time.GetUtcNow();
@@ -165,6 +167,7 @@ public sealed class UploadService(
if (upload.State != UploadState.Receiving) return Fail<CompleteUploadResponse>(409, "upload_state");
if (!upload.IsComplete)
return Fail<CompleteUploadResponse>(409, "incomplete", (upload.ChunkCount - upload.ReceivedCount).ToString(CultureInfo.InvariantCulture));
if (!ArchiveHasRoom(upload)) return Fail<CompleteUploadResponse>(507, "insufficient_storage");
if (!await db.Uploads.TryTransitionAsync(id, UploadState.Receiving, UploadState.Committing, cancellationToken: stopping))
return Fail<CompleteUploadResponse>(409, "upload_state");
@@ -240,9 +243,24 @@ public sealed class UploadService(
return true;
}
/// <summary>
/// The archive volume has room for <paramref name="upload"/> and the reserve: completing it copies the file into the
/// staging folder there (<see cref="StageVerifiedAsync"/>). Checked before the upload leaves the receiving state, so a
/// refused completion (507) can be repeated once there is room. A volume that cannot be measured refuses nothing.
/// </summary>
public bool ArchiveHasRoom(Upload upload)
{
ArgumentNullException.ThrowIfNull(upload);
if (volumes.Measure(archive.Root) is not { } volume || volume.FreeBytes >= upload.Size + DiskReserve) return true;
logger.LogWarning("The archive volume {Archive} has {Free} bytes free: upload {Upload} ({File}, {Size} bytes) waits for room",
archive.Root, volume.FreeBytes, upload.Id, upload.FileName, upload.Size);
return false;
}
/// <summary>
/// Copies a fully received upload to the archive staging folder and checks its SHA-256. On a mismatch the upload
/// fails, its files are deleted and null is returned; the client starts over.
/// fails, its files are deleted and null is returned; the client starts over. Callers check
/// <see cref="ArchiveHasRoom"/> first.
/// </summary>
public async Task<string?> StageVerifiedAsync(Upload upload, CancellationToken cancellationToken)
{