Skip to content

Commit

Permalink
fix following review
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Jan 12, 2023
1 parent e496a4e commit d056dfb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
5 changes: 4 additions & 1 deletion @xen-orchestra/backups/RemoteAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const { isMetadataFile } = require('./_backupType.js')
const { isValidXva } = require('./_isValidXva.js')
const { listPartitions, LVM_PARTITION_TYPE } = require('./_listPartitions.js')
const { lvs, pvs } = require('./_lvm.js')
const { watchStreamSize } = require('./_watchStreamSize')
// @todo : this import is marked extraneous , sould be fixed when lib is published
const { mount } = require('@vates/fuse-vhd')
const { asyncEach } = require('@vates/async-each')
Expand Down Expand Up @@ -678,14 +679,16 @@ class RemoteAdapter {
}

async outputStream(path, input, { checksum = true, validator = noop } = {}) {
return this._handler.outputStream(path, input, {
const container = watchStreamSize(input)
await this._handler.outputStream(path, input, {
checksum,
dirMode: this._dirMode,
async validator() {
await input.task
return validator.apply(this, arguments)
},
})
return container.size
}

// open the hierarchy of ancestors until we find a full one
Expand Down
11 changes: 5 additions & 6 deletions @xen-orchestra/backups/writers/DeltaBackupWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(Ab
vmSnapshot: this._backup.exportedVm,
}

const { size } = await Task.run({ name: 'transfer' }, async () => {
const transferSize = await Task.run({ name: 'transfer' }, async () => {
let transferSize = 0
await Promise.all(
map(deltaExport.vdis, async (vdi, id) => {
const path = `${this._vmBackupDir}/${vhds[id]}`
Expand Down Expand Up @@ -214,7 +215,7 @@ exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(Ab
}
}

sizeContainers[`${id}.vhd`].size = await adapter.writeVhd(path, deltaExport.streams[`${id}.vhd`], {
transferSize += await adapter.writeVhd(path, deltaExport.streams[`${id}.vhd`], {
// no checksum for VHDs, because they will be invalidated by
// merges and chainings
checksum: false,
Expand All @@ -235,11 +236,9 @@ exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(Ab
})
})
)
return {
size: Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0),
}
return transferSize
})
metadataContent.size = size
metadataContent.size = transferSize
this._metadataFileName = await adapter.writeVmBackupMetadata(vm.uuid, metadataContent)

// TODO: run cleanup?
Expand Down
3 changes: 0 additions & 3 deletions @xen-orchestra/fs/src/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { synchronized } from 'decorator-synchronized'
import { basename, dirname, normalize as normalizePath } from './path'
import { createChecksumStream, validChecksumOfReadStream } from './checksum'
import { DEFAULT_ENCRYPTION_ALGORITHM, _getEncryptor } from './_encryptor'
import { watchStreamSize } from '@xen-orchestra/backups/_watchStreamSize'

const { info, warn } = createLogger('xo:fs:abstract')

Expand Down Expand Up @@ -186,7 +185,6 @@ export default class RemoteHandlerAbstract {
async outputStream(path, input, { checksum = true, dirMode, validator } = {}) {
path = normalizePath(path)
let checksumStream
const container = watchStreamSize(input)

input = this._encryptor.encryptStream(input)
if (checksum) {
Expand All @@ -203,7 +201,6 @@ export default class RemoteHandlerAbstract {
// it is by design to allow checking of encrypted files without the key
await this._outputFile(checksumFile(path), await checksumStream.checksum, { dirMode, flags: 'wx' })
}
return container.size
}

// Free the resources possibly dedicated to put the remote at work, when it
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

> Users must be able to say: “I had this issue, happy to know it's fixed”
- [NBD Backups] Fix transfer size [#6599](https://github.com/vatesfr/xen-orchestra/issues/6599)

### Packages to release

> When modifying a package, add it here with its release type.
Expand Down
11 changes: 11 additions & 0 deletions packages/vhd-lib/Vhd/VhdAbstract.integ.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ test('it can create a vhd stream', async () => {
await vhd.writeFooter()
const stream = vhd.stream()

// size and stream must have the same result
expect(stream.length).toEqual(vhd.streamSize())

expect(stream.length).toEqual(
512 /* footer */ +
1024 /* header */ +
512 /* BAT */ +
512 /* parentlocator */ +
3 * (2 * 1024 * 1024 + 512) /* blocs */ +
512 /* end footer */
)
// read all the stream into a buffer

const buffer = await streamToBuffer(stream)
Expand Down
2 changes: 1 addition & 1 deletion packages/vhd-lib/Vhd/VhdAbstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ exports.VhdAbstract = class VhdAbstract {
await handler.writeFile(aliasPath, relativePathToTarget)
}

size() {
streamSize() {
const { header, batSize } = this
let fileSize = FOOTER_SIZE + HEADER_SIZE + batSize + FOOTER_SIZE /* the footer at the end */

Expand Down
2 changes: 1 addition & 1 deletion packages/vhd-lib/createVhdDirectoryFromStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const buildVhd = Disposable.wrap(async function* (handler, path, inputStream, {
}
)
await Promise.all([vhd.writeFooter(), vhd.writeHeader(), vhd.writeBlockAllocationTable()])
return vhd.size()
return vhd.streamSize()
})

exports.createVhdDirectoryFromStream = async function createVhdDirectoryFromStream(
Expand Down

0 comments on commit d056dfb

Please sign in to comment.