Skip to content

Commit 275b940

Browse files
authored
refactor!: update the type of Concurrency options to int (#376)
Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
1 parent a5be49a commit 275b940

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

content.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
const (
3939
// defaultTagConcurrency is the default concurrency of tagging.
40-
defaultTagConcurrency int64 = 5 // This value is consistent with dockerd
40+
defaultTagConcurrency int = 5 // This value is consistent with dockerd
4141

4242
// defaultTagNMaxMetadataBytes is the default value of
4343
// TagNOptions.MaxMetadataBytes.
@@ -58,7 +58,7 @@ var DefaultTagNOptions TagNOptions
5858
type TagNOptions struct {
5959
// Concurrency limits the maximum number of concurrent tag tasks.
6060
// If less than or equal to 0, a default (currently 5) is used.
61-
Concurrency int64
61+
Concurrency int
6262

6363
// MaxMetadataBytes limits the maximum size of metadata that can be cached
6464
// in the memory.
@@ -118,7 +118,7 @@ func TagN(ctx context.Context, target Target, srcReference string, dstReferences
118118
return err
119119
}
120120

121-
eg, egCtx := syncutil.LimitGroup(ctx, int(opts.Concurrency))
121+
eg, egCtx := syncutil.LimitGroup(ctx, opts.Concurrency)
122122
for _, dstRef := range dstReferences {
123123
eg.Go(func(dst string) func() error {
124124
return func() error {
@@ -137,7 +137,7 @@ func TagN(ctx context.Context, target Target, srcReference string, dstReferences
137137
if err != nil {
138138
return err
139139
}
140-
eg, egCtx := syncutil.LimitGroup(ctx, int(opts.Concurrency))
140+
eg, egCtx := syncutil.LimitGroup(ctx, opts.Concurrency)
141141
for _, dstRef := range dstReferences {
142142
eg.Go(func(dst string) func() error {
143143
return func() error {
@@ -354,7 +354,7 @@ var DefaultTagBytesNOptions TagBytesNOptions
354354
type TagBytesNOptions struct {
355355
// Concurrency limits the maximum number of concurrent tag tasks.
356356
// If less than or equal to 0, a default (currently 5) is used.
357-
Concurrency int64
357+
Concurrency int
358358
}
359359

360360
// TagBytesN describes the contentBytes using the given mediaType, pushes it,
@@ -369,7 +369,7 @@ func TagBytesN(ctx context.Context, target Target, mediaType string, contentByte
369369
if opts.Concurrency <= 0 {
370370
opts.Concurrency = defaultTagConcurrency
371371
}
372-
eg, egCtx := syncutil.LimitGroup(ctx, int(opts.Concurrency))
372+
eg, egCtx := syncutil.LimitGroup(ctx, opts.Concurrency)
373373
if refPusher, ok := target.(registry.ReferencePusher); ok {
374374
for _, reference := range references {
375375
eg.Go(func(ref string) func() error {

copy.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
// defaultConcurrency is the default value of CopyGraphOptions.Concurrency.
37-
const defaultConcurrency = 3 // This value is consistent with dockerd and containerd.
37+
const defaultConcurrency int = 3 // This value is consistent with dockerd and containerd.
3838

3939
// errSkipDesc signals copyNode() to stop processing a descriptor.
4040
var errSkipDesc = errors.New("skip descriptor")
@@ -89,7 +89,7 @@ var DefaultCopyGraphOptions CopyGraphOptions
8989
type CopyGraphOptions struct {
9090
// Concurrency limits the maximum number of concurrent copy tasks.
9191
// If less than or equal to 0, a default (currently 3) is used.
92-
Concurrency int64
92+
Concurrency int
9393
// MaxMetadataBytes limits the maximum size of the metadata that can be
9494
// cached in the memory.
9595
// If less than or equal to 0, a default (currently 4 MiB) is used.
@@ -178,7 +178,7 @@ func copyGraph(ctx context.Context, src content.ReadOnlyStorage, dst content.Sto
178178
if opts.Concurrency <= 0 {
179179
opts.Concurrency = defaultConcurrency
180180
}
181-
limiter := semaphore.NewWeighted(opts.Concurrency)
181+
limiter := semaphore.NewWeighted(int64(opts.Concurrency))
182182
// track content status
183183
tracker := status.NewTracker()
184184

copy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ func TestCopyGraph_WithConcurrencyLimit(t *testing.T) {
14881488
opts := oras.DefaultCopyGraphOptions
14891489
for i := 1; i <= directSuccessorsNum; i++ {
14901490
dst := cas.NewMemory()
1491-
opts.Concurrency = int64(i)
1491+
opts.Concurrency = i
14921492
if err := oras.CopyGraph(ctx, src, dst, root, opts); err != nil {
14931493
t.Fatalf("CopyGraph(concurrency: %d) error = %v, wantErr %v", i, err, false)
14941494
}

0 commit comments

Comments
 (0)