Skip to content

Commit 21255b1

Browse files
authored
feat: support preheat by peer count (#4066)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent 7a725c7 commit 21255b1

4 files changed

Lines changed: 88 additions & 57 deletions

File tree

internal/job/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type PreheatRequest struct {
3131
Priority int32 `json:"priority" validate:"omitempty"`
3232
Scope string `json:"scope" validate:"omitempty"`
3333
Percentage *uint8 `json:"percentage" validate:"omitempty,gte=1,lte=100"`
34+
Count *uint32 `json:"count" validate:"omitempty,gte=1,lte=200"`
3435
ConcurrentCount int64 `json:"concurrent_count" validate:"omitempty"`
3536
CertificateChain [][]byte `json:"certificate_chain" validate:"omitempty"`
3637
InsecureSkipVerify bool `json:"insecure_skip_verify" validate:"omitempty"`

manager/job/preheat.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func (p *preheat) CreatePreheat(ctx context.Context, schedulers []models.Schedul
145145
Headers: json.Headers,
146146
Scope: json.Scope,
147147
Percentage: json.Percentage,
148+
Count: json.Count,
148149
ConcurrentCount: json.ConcurrentCount,
149150
CertificateChain: p.certificateChain,
150151
InsecureSkipVerify: p.insecureSkipVerify,
@@ -174,7 +175,7 @@ func (p *preheat) createGroupJob(ctx context.Context, files []internaljob.Prehea
174175
for _, file := range files {
175176
args, err := internaljob.MarshalRequest(file)
176177
if err != nil {
177-
logger.Errorf("preheat marshal request: %v, error: %v", file, err)
178+
logger.Errorf("[preheat]: preheat marshal request: %v, error: %v", file, err)
178179
continue
179180
}
180181

@@ -197,9 +198,9 @@ func (p *preheat) createGroupJob(ctx context.Context, files []internaljob.Prehea
197198
tasks = append(tasks, *signature)
198199
}
199200

200-
logger.Infof("create preheat group %s in queues %v, tasks: %#v", group.GroupUUID, queues, tasks)
201+
logger.Infof("[preheat]: create preheat group %s in queues %v, tasks: %#v", group.GroupUUID, queues, tasks)
201202
if _, err := p.job.Server.SendGroupWithContext(ctx, group, 0); err != nil {
202-
logger.Errorf("create preheat group %s failed", group.GroupUUID, err)
203+
logger.Errorf("[preheat]: create preheat group %s failed", group.GroupUUID, err)
203204
return nil, err
204205
}
205206

@@ -372,6 +373,7 @@ func (p *preheat) parseLayers(manifests []distribution.Manifest, args types.Preh
372373
Headers: nethttp.HeaderToMap(header),
373374
Scope: args.Scope,
374375
Percentage: args.Percentage,
376+
Count: args.Count,
375377
ConcurrentCount: args.ConcurrentCount,
376378
CertificateChain: p.certificateChain,
377379
InsecureSkipVerify: p.insecureSkipVerify,

manager/types/job.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,15 @@ type PreheatArgs struct {
145145
// Scope is the scope for preheating, default is single_seed_peer.
146146
Scope string `json:"scope" binding:"omitempty"`
147147

148-
// Percentage is the percentage of the peer to be preheated.
148+
// Percentage is the percentage of peers to be preheated.
149+
// It must be a value between 1 and 100 (inclusive) if provided.
149150
Percentage *uint8 `json:"percentage" binding:"omitempty,gte=1,lte=100"`
150151

152+
// Count is the number of peers to be preheated.
153+
// It must be a value between 1 and 200 (inclusive) if provided.
154+
// If both Percentage and Count are provided, Count will be used.
155+
Count *uint32 `json:"count" binding:"omitempty,gte=1,lte=200"`
156+
151157
// BatchSize is the batch size for preheating all peers, default is 50.
152158
ConcurrentCount int64 `json:"concurrent_count" binding:"omitempty,gte=1,lte=500"`
153159

0 commit comments

Comments
 (0)