From 5a54f7f30233178c77d38d68fa24641f9d4747bb Mon Sep 17 00:00:00 2001 From: Florent BEAUCHAMP Date: Fri, 9 Sep 2022 16:27:12 +0200 Subject: [PATCH] feat(backups/cleanVm): invalidate cache on backup deletion (#6402) --- @xen-orchestra/backups/RemoteAdapter.js | 5 ++++- @xen-orchestra/backups/_cleanVm.js | 9 +++++++++ CHANGELOG.unreleased.md | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/@xen-orchestra/backups/RemoteAdapter.js b/@xen-orchestra/backups/RemoteAdapter.js index 7039877b4..654c1f9d1 100644 --- a/@xen-orchestra/backups/RemoteAdapter.js +++ b/@xen-orchestra/backups/RemoteAdapter.js @@ -458,8 +458,11 @@ class RemoteAdapter { return backupsByPool } + async _invalidateVmBackupListCacheDir(vmDir) { + await this.handler.unlink(`${vmDir}/cache.json.gz`) + } async invalidateVmBackupListCache(vmUuid) { - await this.handler.unlink(`${BACKUP_DIR}/${vmUuid}/cache.json.gz`) + await this._invalidateVmBackupListCacheDir(`${BACKUP_DIR}/${vmUuid}`) } async #getCachabledDataListVmBackups(dir) { diff --git a/@xen-orchestra/backups/_cleanVm.js b/@xen-orchestra/backups/_cleanVm.js index 8d5d63829..1bec76db4 100644 --- a/@xen-orchestra/backups/_cleanVm.js +++ b/@xen-orchestra/backups/_cleanVm.js @@ -302,6 +302,7 @@ exports.cleanVm = async function cleanVm( } const jsons = new Set() + let mustInvalidateCache = false const xvas = new Set() const xvaSums = [] const entries = await handler.list(vmDir, { @@ -350,6 +351,7 @@ exports.cleanVm = async function cleanVm( if (remove) { logInfo('deleting incomplete backup', { path: json }) jsons.delete(json) + mustInvalidateCache = true 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 }) if (remove) { logInfo('deleting incomplete backup', { path: json }) + mustInvalidateCache = true jsons.delete(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 { // boolean whether some VHDs were merged (or should be merged) merge: toMerge.length !== 0, diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index b9d3a33d3..e9bde248a 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -29,6 +29,7 @@ +- @xen-orchestra/backups minor - xo-server-auth-saml patch - xo-web patch