repository: add BlobBufferPool to BlobSaverAsync

This commit is contained in:
Michael Eischer committed 2026-11-22 17:54:09 +01:00
1 parent 3446754c41
commit 4718be1aee
4 files changed
+28

No files matched your search

+15
View File
@@ -54,6 +54,8 @@ type Repository struct {
zeroChunkOnce sync.Once
zeroChunkID restic.ID
blobBuffers *restic.BlobBufferPool
}
// internalRepository allows using SaveUnpacked and RemoveUnpacked with all FileTypes
@@ -568,9 +570,18 @@ func (r *Repository) removeUnpacked(ctx context.Context, t restic.FileType, id r
return r.be.Remove(ctx, backend.Handle{Type: backend.FileType(t), Name: id.String()})
}
func (r *Repository) blobBufferCapacity() int {
// add 1kb to account for overhead from crypto / compression
return chunker.MaxSize + 1024
}
func (r *Repository) WithBlobUploader(ctx context.Context, fn func(ctx context.Context, uploader restic.BlobSaverWithAsync) error) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
buffers := restic.NewBlobBufferPool(r.blobBufferCapacity())
r.blobBuffers = buffers
defer func() { r.blobBuffers = nil }()
wg, ctx := errgroup.WithContext(ctx)
// pack uploader + wg.Go below + blob saver (CPU bound)
wg.SetLimit(2 + runtime.GOMAXPROCS(0))
@@ -621,6 +632,10 @@ type blobSaverRepo struct {
repo *Repository
}
func (r *blobSaverRepo) BlobBufferPool() *restic.BlobBufferPool {
return r.repo.blobBuffers
}
func (r *blobSaverRepo) SaveBlob(ctx context.Context, t restic.BlobType, buf []byte, id restic.ID, storeDuplicate bool) (newID restic.ID, known bool, size int, err error) {
return r.repo.saveBlob(ctx, t, buf, id, storeDuplicate)
}