mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-26 08:13:39 +00:00
Add lock for a repository pull mirror (#33876)
Fix #33647 This PR add a global lock for repository pulling mirror.
This commit is contained in:
parent
7e8168f555
commit
3e2e7bf4e5
@ -15,6 +15,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
giturl "code.gitea.io/gitea/modules/git/url"
|
giturl "code.gitea.io/gitea/modules/git/url"
|
||||||
"code.gitea.io/gitea/modules/gitrepo"
|
"code.gitea.io/gitea/modules/gitrepo"
|
||||||
|
"code.gitea.io/gitea/modules/globallock"
|
||||||
"code.gitea.io/gitea/modules/lfs"
|
"code.gitea.io/gitea/modules/lfs"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/process"
|
"code.gitea.io/gitea/modules/process"
|
||||||
@ -425,6 +426,10 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
return parseRemoteUpdateOutput(output, m.GetRemoteName()), true
|
return parseRemoteUpdateOutput(output, m.GetRemoteName()), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRepoPullMirrorLockKey(repoID int64) string {
|
||||||
|
return fmt.Sprintf("repo_pull_mirror_%d", repoID)
|
||||||
|
}
|
||||||
|
|
||||||
// SyncPullMirror starts the sync of the pull mirror and schedules the next run.
|
// SyncPullMirror starts the sync of the pull mirror and schedules the next run.
|
||||||
func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||||
log.Trace("SyncMirrors [repo_id: %v]", repoID)
|
log.Trace("SyncMirrors [repo_id: %v]", repoID)
|
||||||
@ -437,6 +442,13 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||||||
log.Error("PANIC whilst SyncMirrors[repo_id: %d] Panic: %v\nStacktrace: %s", repoID, err, log.Stack(2))
|
log.Error("PANIC whilst SyncMirrors[repo_id: %d] Panic: %v\nStacktrace: %s", repoID, err, log.Stack(2))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
releaser, err := globallock.Lock(ctx, getRepoPullMirrorLockKey(repoID))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("globallock.Lock(): %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer releaser()
|
||||||
|
|
||||||
m, err := repo_model.GetMirrorByRepoID(ctx, repoID)
|
m, err := repo_model.GetMirrorByRepoID(ctx, repoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v", repoID, err)
|
log.Error("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v", repoID, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user