Skip to content

Commit

Permalink
feat(fs): speedup s3 delete tree 8-10/s => 100-120/s
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Jan 20, 2022
1 parent ecf95bc commit 6afdffa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 15 additions & 8 deletions @xen-orchestra/fs/src/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { decorateWith } from '@vates/decorate-with'
import { parse } from 'xo-remote-parser'

import RemoteHandlerAbstract from './abstract'
import { asyncEach } from '@vates/async-each'

// endpoints https://docs.aws.amazon.com/general/latest/gr/s3.html

Expand Down Expand Up @@ -177,7 +178,7 @@ export default class S3Handler extends RemoteHandlerAbstract {
Delimiter: '/', // will only return path until delimiters
})

if (result.isTruncated) {
if (result.IsTruncated) {
const error = new Error('more than 1000 objects, unsupported in this implementation')
error.dir = dir
throw error
Expand Down Expand Up @@ -267,15 +268,21 @@ export default class S3Handler extends RemoteHandlerAbstract {
Prefix: this._dir + path + '/',
ContinuationToken: NextContinuationToken,
})
NextContinuationToken = result.isTruncated ? result.NextContinuationToken : undefined
for (const { Key } of result.Contents) {
NextContinuationToken = result.IsTruncated ? result.NextContinuationToken : undefined
await asyncEach(
result.Contents,
async ({Key})=>{
// _unlink will add the prefix, but Key contains everything
// also we don't need to check if we delete a directory, since the list only return files
await this._s3.deleteObject({
Bucket: this._bucket,
Key,
})
}
await this._s3.deleteObject({
Bucket: this._bucket,
Key,
})
},
{
concurrency: 16
}
)
} while (NextContinuationToken !== undefined)
}

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- [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, Introduced by 5a933bad9 (PR [#6099](https://github.com/vatesfr/xen-orchestra/pull/6099))


### Packages to release

Expand Down

0 comments on commit 6afdffa

Please sign in to comment.