chore(xo-server/backups-ng): dont fork streams if 1 target
This commit is contained in:
parent
2ac1093543
commit
505f06c1d8
@ -671,7 +671,8 @@ export default class BackupNg {
|
|||||||
|
|
||||||
const remotes = unboxIds(job.remotes)
|
const remotes = unboxIds(job.remotes)
|
||||||
const srs = unboxIds(job.srs)
|
const srs = unboxIds(job.srs)
|
||||||
if (remotes.length === 0 && srs.length === 0) {
|
const nTargets = remotes.length + srs.length
|
||||||
|
if (nTargets === 0) {
|
||||||
throw new Error('export retention must be 0 without remotes and SRs')
|
throw new Error('export retention must be 0 without remotes and SRs')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,6 +696,15 @@ export default class BackupNg {
|
|||||||
const exportTask = xva.task
|
const exportTask = xva.task
|
||||||
xva = xva.pipe(createSizeStream())
|
xva = xva.pipe(createSizeStream())
|
||||||
|
|
||||||
|
const forkExport =
|
||||||
|
nTargets === 0
|
||||||
|
? () => xva
|
||||||
|
: () => {
|
||||||
|
const fork = xva.pipe(new PassThrough())
|
||||||
|
fork.task = exportTask
|
||||||
|
return fork
|
||||||
|
}
|
||||||
|
|
||||||
const dataBasename = `${basename}.xva`
|
const dataBasename = `${basename}.xva`
|
||||||
|
|
||||||
const metadata: MetadataFull = {
|
const metadata: MetadataFull = {
|
||||||
@ -715,7 +725,7 @@ export default class BackupNg {
|
|||||||
await waitAll(
|
await waitAll(
|
||||||
[
|
[
|
||||||
...remotes.map(async remoteId => {
|
...remotes.map(async remoteId => {
|
||||||
const fork = xva.pipe(new PassThrough())
|
const fork = forkExport()
|
||||||
|
|
||||||
const handler = await app.getRemoteHandler(remoteId)
|
const handler = await app.getRemoteHandler(remoteId)
|
||||||
|
|
||||||
@ -742,8 +752,7 @@ export default class BackupNg {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
...srs.map(async srId => {
|
...srs.map(async srId => {
|
||||||
const fork = xva.pipe(new PassThrough())
|
const fork = forkExport()
|
||||||
fork.task = exportTask
|
|
||||||
|
|
||||||
const xapi = app.getXapi(srId)
|
const xapi = app.getXapi(srId)
|
||||||
const sr = xapi.getObject(srId)
|
const sr = xapi.getObject(srId)
|
||||||
@ -841,9 +850,14 @@ export default class BackupNg {
|
|||||||
const jsonMetadata = JSON.stringify(metadata)
|
const jsonMetadata = JSON.stringify(metadata)
|
||||||
|
|
||||||
// create a fork of the delta export
|
// create a fork of the delta export
|
||||||
const forkExport = (() => {
|
const forkExport =
|
||||||
|
nTargets === 1
|
||||||
|
? () => deltaExport
|
||||||
|
: (() => {
|
||||||
// replace the stream factories by fork factories
|
// replace the stream factories by fork factories
|
||||||
const streams: any = mapValues(deltaExport.streams, lazyStream => {
|
const streams: any = mapValues(
|
||||||
|
deltaExport.streams,
|
||||||
|
lazyStream => {
|
||||||
let forks = []
|
let forks = []
|
||||||
return () => {
|
return () => {
|
||||||
if (forks === undefined) {
|
if (forks === undefined) {
|
||||||
@ -876,7 +890,8 @@ export default class BackupNg {
|
|||||||
forks.push({ reject, resolve })
|
forks.push({ reject, resolve })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
return () => {
|
return () => {
|
||||||
return {
|
return {
|
||||||
__proto__: deltaExport,
|
__proto__: deltaExport,
|
||||||
|
Loading…
Reference in New Issue
Block a user