Skip to content

Commit 2003602

Browse files
committed
Revert "PullService lock via pullID (go-gitea#19520)" (for now...)
This reverts commit 6cde7c9159a5ea75a10356feb7b8c7ad4c434a9a.
1 parent d9c07c9 commit 2003602

File tree

7 files changed

+15
-34
lines changed

7 files changed

+15
-34
lines changed

services/pull/check.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
asymkey_service "code.gitea.io/gitea/services/asymkey"
2929
)
3030

31-
// prPatchCheckerQueue represents a queue to handle update pull request tests
32-
var prPatchCheckerQueue queue.UniqueQueue
31+
// prQueue represents a queue to handle update pull request tests
32+
var prQueue queue.UniqueQueue
3333

3434
var (
3535
ErrIsClosed = errors.New("pull is cosed")
@@ -43,7 +43,7 @@ var (
4343

4444
// AddToTaskQueue adds itself to pull request test task queue.
4545
func AddToTaskQueue(pr *models.PullRequest) {
46-
err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
46+
err := prQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
4747
pr.Status = models.PullRequestStatusChecking
4848
err := pr.UpdateColsIfNotMerged("status")
4949
if err != nil {
@@ -151,7 +151,7 @@ func checkAndUpdateStatus(pr *models.PullRequest) {
151151
}
152152

153153
// Make sure there is no waiting test to process before leaving the checking status.
154-
has, err := prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
154+
has, err := prQueue.Has(strconv.FormatInt(pr.ID, 10))
155155
if err != nil {
156156
log.Error("Unable to check if the queue is waiting to reprocess pr.ID %d. Error: %v", pr.ID, err)
157157
}
@@ -300,7 +300,7 @@ func InitializePullRequests(ctx context.Context) {
300300
case <-ctx.Done():
301301
return
302302
default:
303-
if err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(prID, 10), func() error {
303+
if err := prQueue.PushFunc(strconv.FormatInt(prID, 10), func() error {
304304
log.Trace("Adding PR ID: %d to the pull requests patch checking queue", prID)
305305
return nil
306306
}); err != nil {
@@ -321,8 +321,6 @@ func handle(data ...queue.Data) []queue.Data {
321321
}
322322

323323
func testPR(id int64) {
324-
pullWorkingPool.CheckIn(fmt.Sprint(id))
325-
defer pullWorkingPool.CheckOut(fmt.Sprint(id))
326324
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("Test PR[%d] from patch checking queue", id))
327325
defer finished()
328326

@@ -367,13 +365,13 @@ func CheckPrsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName strin
367365

368366
// Init runs the task queue to test all the checking status pull requests
369367
func Init() error {
370-
prPatchCheckerQueue = queue.CreateUniqueQueue("pr_patch_checker", handle, "")
368+
prQueue = queue.CreateUniqueQueue("pr_patch_checker", handle, "")
371369

372-
if prPatchCheckerQueue == nil {
370+
if prQueue == nil {
373371
return fmt.Errorf("Unable to create pr_patch_checker Queue")
374372
}
375373

376-
go graceful.GetManager().RunWithShutdownFns(prPatchCheckerQueue.Run)
374+
go graceful.GetManager().RunWithShutdownFns(prQueue.Run)
377375
go graceful.GetManager().RunWithShutdownContext(InitializePullRequests)
378376
return nil
379377
}

services/pull/check_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
4141
queueShutdown := []func(){}
4242
queueTerminate := []func(){}
4343

44-
prPatchCheckerQueue = q.(queue.UniqueQueue)
44+
prQueue = q.(queue.UniqueQueue)
4545

4646
pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
4747
AddToTaskQueue(pr)
@@ -51,11 +51,11 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
5151
return pr.Status == models.PullRequestStatusChecking
5252
}, 1*time.Second, 100*time.Millisecond)
5353

54-
has, err := prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
54+
has, err := prQueue.Has(strconv.FormatInt(pr.ID, 10))
5555
assert.True(t, has)
5656
assert.NoError(t, err)
5757

58-
prPatchCheckerQueue.Run(func(shutdown func()) {
58+
prQueue.Run(func(shutdown func()) {
5959
queueShutdown = append(queueShutdown, shutdown)
6060
}, func(terminate func()) {
6161
queueTerminate = append(queueTerminate, terminate)
@@ -68,7 +68,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
6868
assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
6969
}
7070

71-
has, err = prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
71+
has, err = prQueue.Has(strconv.FormatInt(pr.ID, 10))
7272
assert.False(t, has)
7373
assert.NoError(t, err)
7474

@@ -82,5 +82,5 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
8282
callback()
8383
}
8484

85-
prPatchCheckerQueue = nil
85+
prQueue = nil
8686
}

services/pull/merge.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
// Merge merges pull request to base repository.
3636
// Caller should check PR is ready to be merged (review and status checks)
37+
// FIXME: add repoWorkingPull make sure two merges does not happen at same time.
3738
func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) (err error) {
3839
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
3940
log.Error("LoadHeadRepo: %v", err)
@@ -43,9 +44,6 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
4344
return fmt.Errorf("LoadBaseRepo: %v", err)
4445
}
4546

46-
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
47-
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
48-
4947
// Removing an auto merge pull and ignore if not exist
5048
if err := pull_model.RemoveScheduledAutoMerge(ctx, doer, pr.ID, false); err != nil && !models.IsErrNotExist(err) {
5149
return err
@@ -730,9 +728,6 @@ func CheckPRReadyToMerge(ctx context.Context, pr *models.PullRequest, skipProtec
730728

731729
// MergedManually mark pr as merged manually
732730
func MergedManually(ctx context.Context, pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, commitID string) (err error) {
733-
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
734-
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
735-
736731
prUnit, err := pr.BaseRepo.GetUnitCtx(ctx, unit.TypePullRequests)
737732
if err != nil {
738733
return

services/pull/pull.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ import (
2525
"code.gitea.io/gitea/modules/notification"
2626
"code.gitea.io/gitea/modules/process"
2727
"code.gitea.io/gitea/modules/setting"
28-
"code.gitea.io/gitea/modules/sync"
2928
issue_service "code.gitea.io/gitea/services/issue"
3029
)
3130

32-
// TODO: use clustered lock (unique queue? or *abuse* cache)
33-
var pullWorkingPool = sync.NewExclusivePool()
34-
3531
// NewPullRequest creates new pull request with labels for repository.
3632
func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, assigneeIDs []int64) error {
3733
if err := TestPatch(pr); err != nil {
@@ -128,9 +124,6 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
128124

129125
// ChangeTargetBranch changes the target branch of this pull request, as the given user.
130126
func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_model.User, targetBranch string) (err error) {
131-
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
132-
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
133-
134127
// Current target branch is already the same
135128
if pr.BaseBranch == targetBranch {
136129
return nil

services/pull/update.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User
2424
style repo_model.MergeStyle
2525
)
2626

27-
pullWorkingPool.CheckIn(fmt.Sprint(pull.ID))
28-
defer pullWorkingPool.CheckOut(fmt.Sprint(pull.ID))
29-
3027
if rebase {
3128
pr = pull
3229
style = repo_model.MergeStyleRebaseUpdate

services/repository/transfer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
)
2020

2121
// repoWorkingPool represents a working pool to order the parallel changes to the same repository
22-
// TODO: use clustered lock (unique queue? or *abuse* cache)
2322
var repoWorkingPool = sync.NewExclusivePool()
2423

2524
// TransferOwnership transfers all corresponding setting from old user to new one.

services/wiki/wiki.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import (
2727

2828
var (
2929
reservedWikiNames = []string{"_pages", "_new", "_edit", "raw"}
30-
// TODO: use clustered lock (unique queue? or *abuse* cache)
31-
wikiWorkingPool = sync.NewExclusivePool()
30+
wikiWorkingPool = sync.NewExclusivePool()
3231
)
3332

3433
func nameAllowed(name string) error {

0 commit comments

Comments
 (0)