Skip to content

Commit 66b8a43

Browse files
author
Gusted
authored
Refactor mirror code & fix StartToMirror (#18904) (#19075)
- Backport #18904.
1 parent d285905 commit 66b8a43

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

services/mirror/mirror.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ const (
2929

3030
// SyncRequest for the mirror queue
3131
type SyncRequest struct {
32-
Type SyncType
33-
RepoID int64
32+
Type SyncType
33+
ReferenceID int64 // RepoID for pull mirror, MirrorID fro push mirror
3434
}
3535

3636
// doMirrorSync causes this request to mirror itself
3737
func doMirrorSync(ctx context.Context, req *SyncRequest) {
38+
if req.ReferenceID == 0 {
39+
log.Warn("Skipping mirror sync request, no reference ID was specified")
40+
return
41+
}
3842
switch req.Type {
3943
case PushMirrorType:
40-
_ = SyncPushMirror(ctx, req.RepoID)
44+
_ = SyncPushMirror(ctx, req.ReferenceID)
4145
case PullMirrorType:
42-
_ = SyncPullMirror(ctx, req.RepoID)
46+
_ = SyncPullMirror(ctx, req.ReferenceID)
4347
default:
44-
log.Error("Unknown Request type in queue: %v for RepoID[%d]", req.Type, req.RepoID)
48+
log.Error("Unknown Request type in queue: %v for ReferenceID[%d]", req.Type, req.ReferenceID)
4549
}
4650
}
4751

@@ -67,8 +71,8 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
6771
}
6872
repo = m.Repo
6973
item = SyncRequest{
70-
Type: PullMirrorType,
71-
RepoID: m.RepoID,
74+
Type: PullMirrorType,
75+
ReferenceID: m.RepoID,
7276
}
7377
} else if m, ok := bean.(*repo_model.PushMirror); ok {
7478
if m.Repo == nil {
@@ -77,8 +81,8 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
7781
}
7882
repo = m.Repo
7983
item = SyncRequest{
80-
Type: PushMirrorType,
81-
RepoID: m.RepoID,
84+
Type: PushMirrorType,
85+
ReferenceID: m.ID,
8286
}
8387
} else {
8488
log.Error("Unknown bean: %v", bean)
@@ -162,8 +166,8 @@ func StartToMirror(repoID int64) {
162166
}
163167
go func() {
164168
err := mirrorQueue.Push(&SyncRequest{
165-
Type: PullMirrorType,
166-
RepoID: repoID,
169+
Type: PullMirrorType,
170+
ReferenceID: repoID,
167171
})
168172
if err != nil {
169173
log.Error("Unable to push sync request for to the queue for push mirror repo[%d]: Error: %v", repoID, err)
@@ -178,8 +182,8 @@ func AddPushMirrorToQueue(mirrorID int64) {
178182
}
179183
go func() {
180184
err := mirrorQueue.Push(&SyncRequest{
181-
Type: PushMirrorType,
182-
RepoID: mirrorID,
185+
Type: PushMirrorType,
186+
ReferenceID: mirrorID,
183187
})
184188
if err != nil {
185189
log.Error("Unable to push sync request to the queue for pull mirror repo[%d]: Error: %v", mirrorID, err)

0 commit comments

Comments
 (0)