Skip to content

Commit

Permalink
fix(vhd-lib): fixes asserts on existing merge state
Browse files Browse the repository at this point in the history
Introduced by 5a933ba
  • Loading branch information
fbeauchamp authored and julien-f committed Jan 21, 2022
1 parent 3aa6669 commit bc4034a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 13 additions & 16 deletions packages/vhd-lib/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit bc4034a

Please sign in to comment.