E2: prove del motore, dell'archivio e del servizio delle copie
Le prove della tappa E2 (WP5a) coprono il montaggio di /esporta, la radice, il controllo delle cartelle, le destinazioni, i percorsi, la copia, gli stati «Tolto» e «Superato», lo stesso post in due account, il lavoro in sottofondo (interrompi, riprendi, annulla, riavvio, porta condivisa con importazione e ricostruzione, sessione del motore, interruttore dell'account, Docker senza montaggio) e il filtro «Copie». Si appoggiano a un banco comune con falsi per disco, sessione, montaggi e file system, senza permessi dei file, così girano anche da root. Le prove hanno trovato due difetti, corretti: - MarkCopiesRemovedAsync riusava il comando in cache del primo blocco di 900 id: «Controlla le copie» falliva con più di 900 file mancanti in una pagina. - ReplacedStatesSql senza statistiche leggeva tutte le copie tolte o superate della destinazione: «+state» la tiene sul suo indice. Il controllo delle cartelle accetta una scrittura di prova sostituibile, per provare il guasto della sonda senza permessi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
31cfdac051
commit
736d241a38
18 files changed
+3124
-12
No files matched your search
@@ -49,6 +49,9 @@ public sealed record ExportEnvironment
|
||||
/// <summary>Time allowed to a check of a destination folder (a disconnected share must not block).</summary>
|
||||
public TimeSpan FolderCheckTimeout { get; init; } = TimeSpan.FromSeconds(10);
|
||||
|
||||
/// <summary>Writes the probe file of a folder check (a seam: tests make it fail or hang); null: the real file.</summary>
|
||||
public Action<string>? WriteProbe { get; init; }
|
||||
|
||||
/// <summary>How often a waiting job looks whether the engine session ended.</summary>
|
||||
public TimeSpan SessionPoll { get; init; } = TimeSpan.FromSeconds(5);
|
||||
|
||||
@@ -59,7 +62,7 @@ public sealed record ExportEnvironment
|
||||
public long GroupBytes { get; init; } = 1L << 30;
|
||||
|
||||
/// <summary>The checker of destination folders of this environment.</summary>
|
||||
public ExportFolderCheck CreateFolderCheck() => new(Root.Mounts, FolderCheckTimeout);
|
||||
public ExportFolderCheck CreateFolderCheck() => new(Root.Mounts, FolderCheckTimeout, WriteProbe);
|
||||
|
||||
/// <summary>The protected folders now (Data, library, account folders, <c>/importa</c>) and the extra ones.</summary>
|
||||
public Task<ExportFolderContext> FolderContextAsync(IReadOnlyList<ProtectedFolder>? extra, CancellationToken ct) =>
|
||||
|
||||
@@ -107,13 +107,19 @@ public sealed class ExportFolderException : IOException
|
||||
/// looked for, read-only. Everything that touches the disk runs in the background with a timeout (10 s by default): a
|
||||
/// disconnected share never blocks the caller.
|
||||
/// </summary>
|
||||
public sealed class ExportFolderCheck(IExportMounts mounts, TimeSpan? timeout = null)
|
||||
/// <param name="mounts">The mount table (the root of a file system is refused).</param>
|
||||
/// <param name="timeout">Time allowed to the checks on disk; 10 s when null.</param>
|
||||
/// <param name="writeProbe">
|
||||
/// Writes the probe file at the full path given (a seam: tests make it fail or hang); null writes «Febe» in a new file.
|
||||
/// </param>
|
||||
public sealed class ExportFolderCheck(IExportMounts mounts, TimeSpan? timeout = null, Action<string>? writeProbe = null)
|
||||
{
|
||||
/// <summary>Prefix of the probe file (a temporary file of <see cref="SafeFileWriter"/>: <c>.febe-prova-*.part</c>).</summary>
|
||||
public const string ProbePrefix = SafeFileWriter.TempPrefix + "prova-";
|
||||
|
||||
private readonly IExportMounts _mounts = mounts ?? throw new ArgumentNullException(nameof(mounts));
|
||||
private readonly TimeSpan _timeout = timeout ?? TimeSpan.FromSeconds(10);
|
||||
private readonly Action<string> _writeProbe = writeProbe ?? WriteProbeFile;
|
||||
|
||||
/// <summary>A new probe file name: <c>.febe-prova-<12 hex>.part</c>.</summary>
|
||||
public static string NewProbeName() => ProbePrefix + Guid.NewGuid().ToString("N")[..12] + SafeFileWriter.TempSuffix;
|
||||
@@ -290,7 +296,7 @@ public sealed class ExportFolderCheck(IExportMounts mounts, TimeSpan? timeout =
|
||||
/// parents of each protected folder (the candidate contains it, or is it) and, for each parent of the candidate, at the
|
||||
/// same relative path under each protected folder (the candidate is inside it).
|
||||
/// </summary>
|
||||
private static ExportFolderVerdict ProbeIdentity(string full, string shown, IReadOnlyList<ProtectedFolder> protectedFolders)
|
||||
private ExportFolderVerdict ProbeIdentity(string full, string shown, IReadOnlyList<ProtectedFolder> protectedFolders)
|
||||
{
|
||||
var name = NewProbeName();
|
||||
var probe = Path.Combine(full, name);
|
||||
@@ -298,9 +304,7 @@ public sealed class ExportFolderCheck(IExportMounts mounts, TimeSpan? timeout =
|
||||
{
|
||||
try
|
||||
{
|
||||
using var stream = new FileStream(probe, FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
||||
stream.Write("Febe"u8);
|
||||
stream.Flush(flushToDisk: true);
|
||||
_writeProbe(probe);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
@@ -352,6 +356,13 @@ public sealed class ExportFolderCheck(IExportMounts mounts, TimeSpan? timeout =
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteProbeFile(string path)
|
||||
{
|
||||
using var stream = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
||||
stream.Write("Febe"u8);
|
||||
stream.Flush(flushToDisk: true);
|
||||
}
|
||||
|
||||
private static bool Exists(string path)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Export;
|
||||
using Febe.Core.Storage;
|
||||
@@ -896,10 +897,14 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
|
||||
WHERE source_sha256 IN ({shaList}) AND destination_id = @d AND account_id IS NOT NULL AND variant = 'Whole' AND format = 'Original'
|
||||
""";
|
||||
|
||||
/// <summary>The rows of a destination superseded or removed in favour of some files (ix_export_copy_superseded_by).</summary>
|
||||
/// <summary>
|
||||
/// The rows of a destination superseded or removed in favour of some files (ix_export_copy_superseded_by). <c>+state</c>
|
||||
/// keeps the planner off ix_export_copy_destination, which without statistics it took to read every Superseded and
|
||||
/// Removed copy of the destination for each chunk of SHA-256.
|
||||
/// </summary>
|
||||
internal static string ReplacedStatesSql(string shaList) => $"""
|
||||
SELECT account_id, superseded_by_sha256, state, id FROM export_copy
|
||||
WHERE superseded_by_sha256 IN ({shaList}) AND destination_id = @d AND account_id IS NOT NULL AND state IN ('Superseded', 'Removed')
|
||||
WHERE superseded_by_sha256 IN ({shaList}) AND destination_id = @d AND account_id IS NOT NULL AND +state IN ('Superseded', 'Removed')
|
||||
""";
|
||||
|
||||
private const string CandidateColumns =
|
||||
@@ -1040,10 +1045,18 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
|
||||
var changed = 0;
|
||||
foreach (var chunk in copyIds.Distinct().Chunk(IdChunk))
|
||||
{
|
||||
var command = w.Command(string.Empty).With("@at", Sql.Time(at));
|
||||
var list = command.AddList("i", chunk);
|
||||
// The write context keeps one prepared command per SQL text: the text names its parameters, so a
|
||||
// second chunk of the same size reuses the command with new values (one built on an empty text and
|
||||
// filled in afterwards would be the first chunk's command again, its parameters still there).
|
||||
var names = string.Join(", ", chunk.Select((_, i) => string.Create(CultureInfo.InvariantCulture, $"@i{i}")));
|
||||
// A Superseded row keeps the SHA-256 of the file that replaced it: still never copied again by itself.
|
||||
command.CommandText = $"UPDATE export_copy SET state = 'Removed', state_changed_at = @at WHERE id IN ({list}) AND state IN ('Copied', 'Superseded')";
|
||||
var command = w.Command($"UPDATE export_copy SET state = 'Removed', state_changed_at = @at WHERE id IN ({names}) AND state IN ('Copied', 'Superseded')")
|
||||
.With("@at", Sql.Time(at));
|
||||
for (var i = 0; i < chunk.Length; i++)
|
||||
{
|
||||
command.With(string.Create(CultureInfo.InvariantCulture, $"@i{i}"), chunk[i]);
|
||||
}
|
||||
|
||||
changed += command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user