Skip to content

Commit a14b6f3

Browse files
Gustedlunny
Gusted
andauthored
Refactor mirror code & fix StartToMirror (#18904)
* Use MirrorID instead of RepoID - Use the MirrorID as index(SQL uses `id` column not the `repo_id`). Passes the Mirror ID's into the Sync functions. * Check for MirrorID == 0 * Fix `StartToMirror` + refactor * Update services/mirror/mirror.go Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent a90041d commit a14b6f3

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

services/mirror/mirror.go

Lines changed: 19 additions & 14 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 mirror 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 MirrorID[%d]", req.Type, req.ReferenceID)
4549
}
4650
}
4751

@@ -65,8 +69,8 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
6569
}
6670
repo = m.Repo
6771
item = SyncRequest{
68-
Type: PullMirrorType,
69-
RepoID: m.RepoID,
72+
Type: PullMirrorType,
73+
ReferenceID: m.RepoID,
7074
}
7175
} else if m, ok := bean.(*repo_model.PushMirror); ok {
7276
if m.Repo == nil {
@@ -75,8 +79,8 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
7579
}
7680
repo = m.Repo
7781
item = SyncRequest{
78-
Type: PushMirrorType,
79-
RepoID: m.RepoID,
82+
Type: PushMirrorType,
83+
ReferenceID: m.ID,
8084
}
8185
} else {
8286
log.Error("Unknown bean: %v", bean)
@@ -161,11 +165,12 @@ func StartToMirror(repoID int64) {
161165
}
162166
go func() {
163167
err := mirrorQueue.Push(&SyncRequest{
164-
Type: PullMirrorType,
165-
RepoID: repoID,
168+
Type: PullMirrorType,
169+
ReferenceID: repoID,
166170
})
167171
if err != nil {
168-
log.Error("Unable to push sync request for to the queue for push mirror repo[%d]: Error: %v", repoID, err)
172+
log.Error("Unable to push sync request for to the queue for pull mirror repo[%d]: Error: %v", repoID, err)
173+
return
169174
}
170175
}()
171176
}
@@ -177,8 +182,8 @@ func AddPushMirrorToQueue(mirrorID int64) {
177182
}
178183
go func() {
179184
err := mirrorQueue.Push(&SyncRequest{
180-
Type: PushMirrorType,
181-
RepoID: mirrorID,
185+
Type: PushMirrorType,
186+
ReferenceID: mirrorID,
182187
})
183188
if err != nil {
184189
log.Error("Unable to push sync request to the queue for pull mirror repo[%d]: Error: %v", mirrorID, err)

0 commit comments

Comments
 (0)