more aggressive batching

This commit is contained in:
Michael Eischer 2025-11-23 21:46:03 +01:00
parent 857b42fca4
commit e79b01d82f

View file

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/restic/restic/internal/data" "github.com/restic/restic/internal/data"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
@ -193,13 +194,17 @@ func copyTreeBatched(ctx context.Context, srcRepo restic.Repository, dstRepo res
// remember already processed trees across all snapshots // remember already processed trees across all snapshots
visitedTrees := restic.NewIDSet() visitedTrees := restic.NewIDSet()
targetSize := uint64(dstRepo.PackSize()) * 100
minDuration := 1 * time.Minute
for len(selectedSnapshots) > 0 { for len(selectedSnapshots) > 0 {
var batch []*data.Snapshot var batch []*data.Snapshot
batchSize := uint64(0) batchSize := uint64(0)
targetSize := uint64(dstRepo.PackSize()) * 10 startTime := time.Now()
// call WithBlobUploader() once and then loop over all selectedSnapshots // call WithBlobUploader() once and then loop over all selectedSnapshots
err := dstRepo.WithBlobUploader(ctx, func(ctx context.Context, uploader restic.BlobSaver) error { err := dstRepo.WithBlobUploader(ctx, func(ctx context.Context, uploader restic.BlobSaver) error {
for len(selectedSnapshots) > 0 && batchSize < targetSize { for len(selectedSnapshots) > 0 && (batchSize < targetSize || time.Since(startTime) < minDuration) {
sn := selectedSnapshots[0] sn := selectedSnapshots[0]
selectedSnapshots = selectedSnapshots[1:] selectedSnapshots = selectedSnapshots[1:]
batch = append(batch, sn) batch = append(batch, sn)