From bc4034acf08fd596b3fb13b3e44eaac9b24c9b6f Mon Sep 17 00:00:00 2001 From: Florent Beauchamp Date: Wed, 19 Jan 2022 15:51:37 +0100 Subject: [PATCH] fix(vhd-lib): fixes asserts on existing merge state Introduced by 5a933bad9 --- CHANGELOG.unreleased.md | 1 + packages/vhd-lib/merge.js | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 2d4b163f1fc..d6e9ea08adb 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -21,6 +21,7 @@ - [Backup] Detect and clear orphan merge states, fix `ENOENT` errors (PR [#6087](https://github.com/vatesfr/xen-orchestra/pull/6087)) - [Backup] Ensure merges are also executed after backup on S3, maintaining the size of the VHD chain under control [Forum#45743](https://xcp-ng.org/forum/post/45743) (PR [#6095](https://github.com/vatesfr/xen-orchestra/pull/6095)) +- [Backup] Fix merge resuming (PR [#6099](https://github.com/vatesfr/xen-orchestra/pull/6099)) ### Packages to release diff --git a/packages/vhd-lib/merge.js b/packages/vhd-lib/merge.js index cec5fe52417..4a230837b89 100644 --- a/packages/vhd-lib/merge.js +++ b/packages/vhd-lib/merge.js @@ -25,22 +25,15 @@ module.exports = limitConcurrency(2)(async function merge( const mergeStatePath = dirname(parentPath) + '/' + '.' + basename(parentPath) + '.merge.json' return await Disposable.use(async function* () { - let mergeState = await parentHandler - .readFile(mergeStatePath) - .then(content => { - const state = JSON.parse(content) - - // ensure the correct merge will be continued - assert.strictEqual(parentVhd.header.checksum, state.parent.header) - assert.strictEqual(childVhd.header.checksum, state.child.header) - - return state - }) - .catch(error => { - if (error.code !== 'ENOENT') { - warn('problem while checking the merge state', { error }) - } - }) + let mergeState + try { + const mergeStateContent = await parentHandler.readFile(mergeStatePath) + mergeState = JSON.parse(mergeStateContent) + } catch (error) { + if (error.code !== 'ENOENT') { + warn('problem while checking the merge state', { error }) + } + } // during merging, the end footer of the parent can be overwritten by new blocks // we should use it as a way to check vhd health @@ -49,12 +42,16 @@ module.exports = limitConcurrency(2)(async function merge( checkSecondFooter: mergeState === undefined, }) const childVhd = yield openVhd(childHandler, childPath) + if (mergeState === undefined) { assert.strictEqual(childVhd.header.blockSize, parentVhd.header.blockSize) const parentDiskType = parentVhd.footer.diskType assert(parentDiskType === DISK_TYPES.DIFFERENCING || parentDiskType === DISK_TYPES.DYNAMIC) assert.strictEqual(childVhd.footer.diskType, DISK_TYPES.DIFFERENCING) + } else { + assert.strictEqual(parentVhd.header.checksum, mergeState.parent.header) + assert.strictEqual(childVhd.header.checksum, mergeState.child.header) } // Read allocation table of child/parent.