Skip to content

Commit f9af6fb

Browse files
author
Vadim Belov
committed
Prevent duplicate chunk hashes with different compression
Ensure that uploaded chunk hashes cannot be stored with different compression algorithms for the same storage module. If a hash already exists with a different algorithm, throw an exception to prevent inconsistent storage.
1 parent 02c4ec2 commit f9af6fb

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Octockup.Server/Jobs/BackupRunner.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,16 @@ private async Task EnsureUploadedHashRecordedAsync(
451451
CompressionAlgorithm algorithm,
452452
CancellationToken cancellationToken)
453453
{
454-
bool chunkRecorded = await dbContext.UploadedHashes
454+
var foundChunk = await dbContext.UploadedHashes
455455
.AsNoTracking()
456-
.AnyAsync(x => x.Hash == hash && x.ModuleId == storageModuleId, cancellationToken);
457-
if (chunkRecorded)
456+
.FirstOrDefaultAsync(x => x.Hash == hash && x.ModuleId == storageModuleId, cancellationToken);
457+
if (foundChunk != null)
458458
{
459+
if (foundChunk.CompressionAlgorithm != algorithm)
460+
{
461+
throw new InvalidOperationException($"Hash {hash} for storage module {storageModuleId} already exists with different compression algorithm. " +
462+
$"Existing: {foundChunk.CompressionAlgorithm}, New: {algorithm}");
463+
}
459464
return;
460465
}
461466

0 commit comments

Comments
 (0)