Remove known bad blobs from do-not-use list when deleting them

This commit is contained in:
Torsten Grote 2024-11-08 10:41:18 -03:00
parent 69765c7857
commit ae77ebed8f
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 16 additions and 5 deletions

View file

@ -23,6 +23,7 @@ internal class Pruner(
private val crypto: Crypto, private val crypto: Crypto,
private val backendManager: BackendManager, private val backendManager: BackendManager,
private val snapshotManager: SnapshotManager, private val snapshotManager: SnapshotManager,
private val blobCache: BlobCache,
) { ) {
private val log = KotlinLogging.logger {} private val log = KotlinLogging.logger {}
@ -77,11 +78,17 @@ internal class Pruner(
blob.id.hexFromProto() blob.id.hexFromProto()
} }
}.toSet() }.toSet()
blobHandles.forEach { blobHandle -> val removedBlobs = mutableSetOf<String>()
if (blobHandle.name !in usedBlobIds) { try {
log.info { "Removing blob ${blobHandle.name}" } blobHandles.forEach { blobHandle ->
backendManager.backend.remove(blobHandle) if (blobHandle.name !in usedBlobIds) {
log.info { "Removing blob ${blobHandle.name}" }
backendManager.backend.remove(blobHandle)
removedBlobs.add(blobHandle.name)
}
} }
} finally {
if (removedBlobs.isNotEmpty()) blobCache.onBlobsRemoved(removedBlobs)
} }
} }

View file

@ -33,9 +33,10 @@ internal class PrunerTest : TransportTest() {
private val backendManager: BackendManager = mockk() private val backendManager: BackendManager = mockk()
private val snapshotManager: SnapshotManager = mockk() private val snapshotManager: SnapshotManager = mockk()
private val blobCache: BlobCache = mockk()
private val backend: Backend = mockk() private val backend: Backend = mockk()
private val pruner = Pruner(crypto, backendManager, snapshotManager) private val pruner = Pruner(crypto, backendManager, snapshotManager, blobCache)
private val folder = TopLevelFolder(repoId) private val folder = TopLevelFolder(repoId)
private val snapshotHandle1 = private val snapshotHandle1 =
@ -84,6 +85,7 @@ internal class PrunerTest : TransportTest() {
blobIds.forEach { blobIds.forEach {
coEvery { backend.remove(AppBackupFileType.Blob(repoId, it)) } just Runs coEvery { backend.remove(AppBackupFileType.Blob(repoId, it)) } just Runs
} }
every { blobCache.onBlobsRemoved(blobIds.toSet()) } just Runs
pruner.removeOldSnapshotsAndPruneUnusedBlobs() pruner.removeOldSnapshotsAndPruneUnusedBlobs()
} }
@ -143,12 +145,14 @@ internal class PrunerTest : TransportTest() {
// now extra blobs will get removed // now extra blobs will get removed
coEvery { backend.remove(AppBackupFileType.Blob(repoId, blob1)) } just Runs coEvery { backend.remove(AppBackupFileType.Blob(repoId, blob1)) } just Runs
coEvery { backend.remove(AppBackupFileType.Blob(repoId, blob2)) } just Runs coEvery { backend.remove(AppBackupFileType.Blob(repoId, blob2)) } just Runs
every { blobCache.onBlobsRemoved(setOf(blob1, blob2)) } just Runs
pruner.removeOldSnapshotsAndPruneUnusedBlobs() pruner.removeOldSnapshotsAndPruneUnusedBlobs()
coVerify { coVerify {
backend.remove(AppBackupFileType.Blob(repoId, blob1)) backend.remove(AppBackupFileType.Blob(repoId, blob1))
backend.remove(AppBackupFileType.Blob(repoId, blob2)) backend.remove(AppBackupFileType.Blob(repoId, blob2))
blobCache.onBlobsRemoved(setOf(blob1, blob2))
} }
} }