feat(backups/cleanVm): invalidate cache on backup deletion (#6402)

This commit is contained in:
Florent BEAUCHAMP 2022-09-09 16:27:12 +02:00 committed by GitHub
parent 6002a497fe
commit 5a54f7f302
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -458,8 +458,11 @@ class RemoteAdapter {
return backupsByPool return backupsByPool
} }
async _invalidateVmBackupListCacheDir(vmDir) {
await this.handler.unlink(`${vmDir}/cache.json.gz`)
}
async invalidateVmBackupListCache(vmUuid) { async invalidateVmBackupListCache(vmUuid) {
await this.handler.unlink(`${BACKUP_DIR}/${vmUuid}/cache.json.gz`) await this._invalidateVmBackupListCacheDir(`${BACKUP_DIR}/${vmUuid}`)
} }
async #getCachabledDataListVmBackups(dir) { async #getCachabledDataListVmBackups(dir) {

View File

@ -302,6 +302,7 @@ exports.cleanVm = async function cleanVm(
} }
const jsons = new Set() const jsons = new Set()
let mustInvalidateCache = false
const xvas = new Set() const xvas = new Set()
const xvaSums = [] const xvaSums = []
const entries = await handler.list(vmDir, { const entries = await handler.list(vmDir, {
@ -350,6 +351,7 @@ exports.cleanVm = async function cleanVm(
if (remove) { if (remove) {
logInfo('deleting incomplete backup', { path: json }) logInfo('deleting incomplete backup', { path: json })
jsons.delete(json) jsons.delete(json)
mustInvalidateCache = true
await handler.unlink(json) await handler.unlink(json)
} }
} }
@ -372,6 +374,7 @@ exports.cleanVm = async function cleanVm(
logWarn('some VHDs linked to the backup are missing', { backup: json, missingVhds }) logWarn('some VHDs linked to the backup are missing', { backup: json, missingVhds })
if (remove) { if (remove) {
logInfo('deleting incomplete backup', { path: json }) logInfo('deleting incomplete backup', { path: json })
mustInvalidateCache = true
jsons.delete(json) jsons.delete(json)
await handler.unlink(json) await handler.unlink(json)
} }
@ -528,6 +531,12 @@ exports.cleanVm = async function cleanVm(
} }
}) })
// purge cache if a metadata file has been deleted
if (mustInvalidateCache) {
// cleanvm is always invoked as a method of RemoteAdapter
await this._invalidateVmBackupListCacheDir(vmDir)
}
return { return {
// boolean whether some VHDs were merged (or should be merged) // boolean whether some VHDs were merged (or should be merged)
merge: toMerge.length !== 0, merge: toMerge.length !== 0,

View File

@ -29,6 +29,7 @@
<!--packages-start--> <!--packages-start-->
- @xen-orchestra/backups minor
- xo-server-auth-saml patch - xo-server-auth-saml patch
- xo-web patch - xo-web patch