Skip to content

Commit

Permalink
refactor(backup/mirror): compute filter predicate only once
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Aug 28, 2024
1 parent 9aa4758 commit 8ab1a45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions @xen-orchestra/backups/_runners/_vmRunners/FullRemote.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const FullRemote = class FullRemoteVmBackupRunner extends AbstractRemote
return FullRemoteWriter
}

_filterTransferlist(transferList) {
return transferList.filter(vmBackupMetadata => this._shouldTransferBackup(vmBackupMetadata))
_filterTransferList(transferList) {
return transferList.filter(this._filterPredicate)
}

async _run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {

// we'll transfer the full list if at least one backup should be transfered
// to ensure we don't cut the delta chain
_filterTransferlist(transferList) {
if (transferList.some(vmBackupMetadata => this._shouldTransferBackup(vmBackupMetadata))) {
_filterTransferList(transferList) {
if (transferList.some(vmBackupMetadata => this._filterPredicate(vmBackupMetadata))) {
return transferList
}
return []
Expand Down
22 changes: 7 additions & 15 deletions @xen-orchestra/backups/_runners/_vmRunners/_AbstractRemote.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { extractIdsFromSimplePattern } from '../../extractIdsFromSimplePattern.m
import { Task } from '../../Task.mjs'

export const AbstractRemote = class AbstractRemoteVmBackupRunner extends Abstract {
_filterPredicate
constructor({
config,
job,
Expand Down Expand Up @@ -60,6 +61,12 @@ export const AbstractRemote = class AbstractRemoteVmBackupRunner extends Abstrac
})
)
})
const { filter } = job
if (filter === undefined) {
this._filterPredicate = () => true
} else {
this._filterPredicate = createPredicate(filter)
}
}

async #computeTransferListPerJob(sourceBackups, remotesBackups) {
Expand Down Expand Up @@ -124,21 +131,6 @@ export const AbstractRemote = class AbstractRemoteVmBackupRunner extends Abstrac
return transferByJobs.flat(1)
}

/**
* check if users want to mirror this vm backup
*
* @param {Object} vmBackupMetadata
* @returns Boolean
*/
_shouldTransferBackup(vmBackupMetadata) {
const { filter } = this.job
if (filter === undefined) {
return true
}
const predicate = createPredicate(filter)
return predicate(vmBackupMetadata)
}

async run($defer) {
const handler = this._sourceRemoteAdapter._handler
await Disposable.use(await handler.lock(getVmBackupDir(this._vmUuid)), async () => {
Expand Down

0 comments on commit 8ab1a45

Please sign in to comment.