fix(vhd-lib): fixes asserts on existing merge state (#6099)

Introduced by 5a933bad9
This commit is contained in:
Florent BEAUCHAMP
2022-01-21 12:40:45 +01:00
committed by GitHub
parent ff24364bb6
commit 692e72a78a
2 changed files with 14 additions and 16 deletions

View File

@@ -22,6 +22,7 @@
- [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] Delete backups immediately instead of waiting for the next backup (PR [#6081](https://github.com/vatesfr/xen-orchestra/pull/6081))
- [Backup] Delete S3 backups completely, even if there are more than 1000 files (PR [#6103](https://github.com/vatesfr/xen-orchestra/pull/6103))
- [Backup] Fix merge resuming (PR [#6099](https://github.com/vatesfr/xen-orchestra/pull/6099))
### Packages to release

View File

@@ -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.