Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check for conflicts/merging if the PR has not been merged in the interim #10132

Merged
merged 37 commits into from Feb 9, 2020

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Feb 3, 2020

The current code for checking PRs suffers from a race with being merged in the interim. This PR reduces the likelihood of this race occurring.

(We would need temporary locks and to extend the state counter for PRs to include merging etc. for this to be completely fixed.)

@zeripath zeripath added this to the 1.12.0 milestone Feb 3, 2020
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 3, 2020
models/pull.go Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Feb 4, 2020

Codecov Report

Merging #10132 into master will increase coverage by <.01%.
The diff coverage is 7.4%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10132      +/-   ##
==========================================
+ Coverage   43.63%   43.64%   +<.01%     
==========================================
  Files         576      576              
  Lines       79716    79718       +2     
==========================================
+ Hits        34788    34789       +1     
- Misses      40631    40635       +4     
+ Partials     4297     4294       -3
Impacted Files Coverage Δ
routers/user/profile.go 50.69% <0%> (-0.97%) ⬇️
routers/routes/routes.go 86.47% <100%> (-0.05%) ⬇️
models/pull.go 42.03% <50%> (+0.1%) ⬆️
models/unit.go 37.03% <0%> (-2.47%) ⬇️
modules/queue/unique_queue_disk_channel.go 52.56% <0%> (-1.93%) ⬇️
routers/repo/view.go 39.13% <0%> (-0.87%) ⬇️
modules/log/event.go 65.64% <0%> (+1.02%) ⬆️
services/pull/pull.go 33.93% <0%> (+1.5%) ⬆️
services/pull/check.go 35.97% <0%> (+3.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0140315...7955006. Read the comment docs.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 5, 2020
models/pull.go Outdated Show resolved Hide resolved
@lafriks
Copy link
Member

lafriks commented Feb 6, 2020

Still CI error :P

@zeripath
Copy link
Contributor Author

zeripath commented Feb 9, 2020

Finally!! Ready for re-review @lafriks @guillep2k

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 9, 2020
Copy link
Member

@guillep2k guillep2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! This thing was very difficult! Sorry about the "affected rows" count not working. 😞

Here's a couple of nits. I think the pr.Issue = nil suggestion is important.

models/pull.go Show resolved Hide resolved
models/pull.go Outdated Show resolved Hide resolved
models/pull.go Outdated Show resolved Hide resolved
zeripath and others added 2 commits February 9, 2020 20:57
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
@guillep2k
Copy link
Member

Nope that wasn't it - I think the issue is the count doesn't seem to be returned on MySQL.

This is probably a bug on xorm or the MySQL driver.

@lafriks
Copy link
Member

lafriks commented Feb 9, 2020

@guillep2k no, MS SQL Server does not allow updating ID key

models/pull.go Outdated Show resolved Hide resolved
models/pull.go Outdated Show resolved Hide resolved
models/pull.go Outdated Show resolved Hide resolved
models/pull.go Outdated Show resolved Hide resolved
zeripath and others added 2 commits February 9, 2020 22:13
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
@guillep2k
Copy link
Member

@guillep2k no, MS SQL Server does not allow updating ID key

Oh, right, because it's auto-increment. I forgot about that.

@lafriks lafriks merged commit 875c5e1 into go-gitea:master Feb 9, 2020
@zeripath zeripath deleted the improve-pr-check branch February 10, 2020 07:47
6543 pushed a commit to 6543-forks/gitea that referenced this pull request Feb 10, 2020
… interim (go-gitea#10132)

* Only check for merging if the PR has not been merged in the interim

* fixup! Only check for merging if the PR has not been merged in the interim

* Try to fix test failure

* Use PR2 not PR1 in tests as PR1 merges automatically

* return already merged error

* enforce locking

* move pullrequest checking to after merge

This might improve the chance that the race does not affect us but does not prevent it.

* Remove minor race with getting merge commit id

move check pr after merge

* Remove unnecessary prepareTestEnv - onGiteaRun does this for us

* Add information about when merging occuring

* More logging

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
@6543
Copy link
Member

6543 commented Feb 10, 2020

@zeripath send backport (had to do some reorder)

@lafriks lafriks added the backport/done All backports for this PR have been created label Feb 10, 2020
zeripath added a commit that referenced this pull request Feb 10, 2020
… interim (#10132) (#10206)

* Only check for conflicts/merging if the PR has not been merged in the interim (#10132)

* Only check for merging if the PR has not been merged in the interim

* fixup! Only check for merging if the PR has not been merged in the interim

* Try to fix test failure

* Use PR2 not PR1 in tests as PR1 merges automatically

* return already merged error

* enforce locking

* move pullrequest checking to after merge

This might improve the chance that the race does not affect us but does not prevent it.

* Remove minor race with getting merge commit id

move check pr after merge

* Remove unnecessary prepareTestEnv - onGiteaRun does this for us

* Add information about when merging occuring

* More logging

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>

* re order

Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants