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

WIP: By-repository mutex to create issues #7894

Closed
wants to merge 2 commits into from

Conversation

guillep2k
Copy link
Member

This should fix a possible race condition in models/issue.go (#7887) if we deem it necessary to fix; I'm not sure it's much of an issue, however.

The idea is to put a lock between select max(index) and insert into issue (index, ....), so there's no chance that two simultaneous requests attempt to insert the same index for two separate issues.

To make sure it doesn't hurt insert performance, I've used per-repository mutexes with a library I've found at go.chromium.org/luci/common/sync/mutexpool; so there's no lock if two inserts go for different repositories.

As I've said, it's probably not worth fixing; but I figured I'd try anyway. The pattern might be useful for other parts of the code.

One more thing: I couldn't figure out a good way of unit testing this modification. I've been looking around but didn't find anything convincing. Suggestions are welcomed.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@4bc4acd). Click here to learn what that means.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #7894   +/-   ##
=========================================
  Coverage          ?   41.41%           
=========================================
  Files             ?      478           
  Lines             ?    63951           
  Branches          ?        0           
=========================================
  Hits              ?    26486           
  Misses            ?    34015           
  Partials          ?     3450
Impacted Files Coverage Δ
models/issue.go 50% <69.23%> (ø)

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 4bc4acd...e6bbc19. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 16, 2019
@lunny
Copy link
Member

lunny commented Aug 17, 2019

@guillep2k I don't think this will work on a scale architecture i.e. gitea.com . There are serval gitea instances shared with databases and file system. This will not work.

I would like a simple but ugly fix to retry the creating when failed because of the max id are already exist.

@guillep2k
Copy link
Member Author

@guillep2k I don't this will work on a scale architecture i.e. gitea.com . There are serval gitea instance shared with databases and file system. This will not work.

I would like a simple but ugly fix to retry the creating when failed because of the max id are already exist.

You are right. I'll close this PR and make another. I'll investigate how to detect duplicate key with xorm.

@guillep2k guillep2k closed this Aug 17, 2019
@guillep2k guillep2k deleted the fix-issue-race branch September 5, 2019 23:28
@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
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants