fix(snapshots): fixed --parallel flag when snapshotting (#2392)

Previously the value of --parallel flag was (unintentionally)
capped at max number of CPUs. This PR fixes the logic.
This commit is contained in:
Jarek Kowalski
2022-09-10 20:11:07 -07:00
committed by GitHub
parent 2115d98524
commit 8ff6b6d060
2 changed files with 9 additions and 2 deletions

View File

@@ -727,8 +727,13 @@ func (u *Uploader) maybeIgnoreCachedEntry(ctx context.Context, ent fs.Entry) fs.
func (u *Uploader) effectiveParallelFileReads(pol *policy.Policy) int {
p := u.ParallelUploads
max := pol.UploadPolicy.MaxParallelFileReads.OrDefault(runtime.NumCPU())
if p > 0 {
// command-line override takes precedence.
return p
}
// use policy setting or number of CPUs.
max := pol.UploadPolicy.MaxParallelFileReads.OrDefault(runtime.NumCPU())
if p < 1 || p > max {
return max
}

View File

@@ -679,7 +679,7 @@ func TestParallelUploadUploadsBlobsInParallel(t *testing.T) {
th := newUploadTestHarness(ctx, t)
u := NewUploader(th.repo)
u.ParallelUploads = 10
u.ParallelUploads = 13
// no faults for first blob write - session marker.
th.faulty.AddFault(blobtesting.MethodPutBlob)
@@ -705,6 +705,8 @@ func TestParallelUploadUploadsBlobsInParallel(t *testing.T) {
policyTree := policy.BuildTree(nil, policy.DefaultPolicy)
require.Equal(t, 13, u.effectiveParallelFileReads(policyTree.EffectivePolicy()))
si := snapshot.SourceInfo{
UserName: "user",
Host: "host",