Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xo-server/delta NG): dont start export before all targets ready #3427

Merged
merged 2 commits into from Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@
- [Backup NG] Don't fail on VMs with empty VBDs (like CDs or floppy disks) (PR [#3410](https://github.com/vatesfr/xen-orchestra/pull/3410))
- [XOA updater] Fix issue where trial request would fail [#3407](https://github.com/vatesfr/xen-orchestra/issues/3407) (PR [#3412](https://github.com/vatesfr/xen-orchestra/pull/3412))
- [Backup NG logs] Fix log's value not being updated in the copy and report button [#3273](https://github.com/vatesfr/xen-orchestra/issues/3273) (PR [#3360](https://github.com/vatesfr/xen-orchestra/pull/3360))
- [Backup NG] Fix issue when *Delete first* was enabled for some of the remotes [#3424](https://github.com/vatesfr/xen-orchestra/issues/3424) (PR [#3427](https://github.com/vatesfr/xen-orchestra/pull/3427))

### Released packages

Expand Down
33 changes: 22 additions & 11 deletions packages/xo-server/src/xo-mixins/backups-ng/index.js
Expand Up @@ -1227,17 +1227,28 @@ export default class BackupNg {
const streams: any = mapValues(
deltaExport.streams,
lazyStream => {
const pStream = lazyStream()
const forks = Array.from({ length: nTargets }, _ => {
const promise = pStream.then(stream => {
const fork: any = stream.pipe(new PassThrough())
fork.task = stream.task
return fork
})
promise.catch(noop) // prevent unhandled rejection
return promise
})
return () => forks.pop()
// wait for all targets to require the stream and then starts
// the real export and create the forks.
const resolves = []
function resolver (resolve) {
resolves.push(resolve)

if (resolves.length === nTargets) {
const pStream = lazyStream()
resolves.forEach(resolve => {
resolve(
pStream.then(stream => {
const fork: any = stream.pipe(new PassThrough())
fork.task = stream.task
return fork
})
)
})
resolves.length = 0
}
}

return () => new Promise(resolver)
}
)
return () => {
Expand Down