From 8c7e7e8a062539466cec9ecbae9acf0c2a189b19 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 26 Mar 2022 09:52:05 +0000 Subject: [PATCH 1/3] Touch mirrors on even on fail to update If a mirror fails to be synchronised it should be pushed to the bottom of the queue of the awaiting mirrors to be synchronised. At present if there LIMIT number of broken mirrors they can effectively prevent all other mirrors from being synchronized as their last_updated time will remain earlier than other mirrors. Signed-off-by: Andrew Thornton --- models/repo/mirror.go | 11 +++++++++++ services/mirror/mirror_pull.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/models/repo/mirror.go b/models/repo/mirror.go index 8494331ff710..1573049dc615 100644 --- a/models/repo/mirror.go +++ b/models/repo/mirror.go @@ -113,6 +113,17 @@ func UpdateMirror(m *Mirror) error { return updateMirror(db.GetEngine(db.DefaultContext), m) } +func touchMirror(e db.Engine, m *Mirror) error { + m.UpdatedUnix = timeutil.TimeStampNow() + _, err := e.ID(m.ID).Cols("updated_unix").Update(m) + return err +} + +// TouchMirror updates the mirror updatedUnix +func TouchMirror(m *Mirror) error { + return touchMirror(db.GetEngine(db.DefaultContext), m) +} + // DeleteMirrorByRepoID deletes a mirror by repoID func DeleteMirrorByRepoID(repoID int64) error { _, err := db.GetEngine(db.DefaultContext).Delete(&Mirror{RepoID: repoID}) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 979ef7f03cf1..12f76c3c41c9 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -399,6 +399,10 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Trace("SyncMirrors [repo: %-v]: Running Sync", m.Repo) results, ok := runSync(ctx, m) if !ok { + if err = repo_model.TouchMirror(m); err != nil { + log.Error("SyncMirrors [repo: %-v]: failed to TouchMirror: %v", m.Repo, err) + return false + } return false } From 55fd119319ea7264036094701f99760ada85e79c Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 26 Mar 2022 17:51:54 +0000 Subject: [PATCH 2/3] as per review Signed-off-by: Andrew Thornton --- models/repo/mirror.go | 11 ++++------- services/mirror/mirror_pull.go | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/models/repo/mirror.go b/models/repo/mirror.go index 1573049dc615..df4e320752b1 100644 --- a/models/repo/mirror.go +++ b/models/repo/mirror.go @@ -6,6 +6,7 @@ package repo import ( + "context" "errors" "fmt" "time" @@ -113,17 +114,13 @@ func UpdateMirror(m *Mirror) error { return updateMirror(db.GetEngine(db.DefaultContext), m) } -func touchMirror(e db.Engine, m *Mirror) error { +// TouchMirror updates the mirror updatedUnix +func TouchMirror(ctx context.Context, m *Mirror) error { m.UpdatedUnix = timeutil.TimeStampNow() - _, err := e.ID(m.ID).Cols("updated_unix").Update(m) + _, err := db.GetEngine(ctx).ID(m.ID).Cols("updated_unix").Update(m) return err } -// TouchMirror updates the mirror updatedUnix -func TouchMirror(m *Mirror) error { - return touchMirror(db.GetEngine(db.DefaultContext), m) -} - // DeleteMirrorByRepoID deletes a mirror by repoID func DeleteMirrorByRepoID(repoID int64) error { _, err := db.GetEngine(db.DefaultContext).Delete(&Mirror{RepoID: repoID}) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 12f76c3c41c9..9cd624fb28c4 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -399,7 +399,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Trace("SyncMirrors [repo: %-v]: Running Sync", m.Repo) results, ok := runSync(ctx, m) if !ok { - if err = repo_model.TouchMirror(m); err != nil { + if err = repo_model.TouchMirror(ctx, m); err != nil { log.Error("SyncMirrors [repo: %-v]: failed to TouchMirror: %v", m.Repo, err) return false } From 68bbcfc573e291b59e0ed4d43f0632e49b49fe49 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 27 Mar 2022 12:31:12 +0100 Subject: [PATCH 3/3] Update services/mirror/mirror_pull.go Co-authored-by: Lunny Xiao --- services/mirror/mirror_pull.go | 1 - 1 file changed, 1 deletion(-) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 9cd624fb28c4..36d9cc5fe602 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -401,7 +401,6 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { if !ok { if err = repo_model.TouchMirror(ctx, m); err != nil { log.Error("SyncMirrors [repo: %-v]: failed to TouchMirror: %v", m.Repo, err) - return false } return false }