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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ require (
github.com/urfave/cli v1.20.0
github.com/willf/bitset v0.0.0-20180426185212-8ce1146b8621 // indirect
github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53
go.chromium.org/luci v0.0.0-20190816194131-4b600c9efb12
go.etcd.io/bbolt v1.3.2 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53 h1:HsIQ6yAjfjQ3Ix
github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53/go.mod h1:f6elajwZV+xceiaqgRL090YzLEDGSbqr3poGL3ZgXYo=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.chromium.org/luci v0.0.0-20190816194131-4b600c9efb12 h1:mY6O4bEXDOKJNhqkv17p5Pxjk3hM9RoRPeMc2CJWM2A=
go.chromium.org/luci v0.0.0-20190816194131-4b600c9efb12/go.mod h1:MIQewVTLvOvc0UioV0JNqTNO/RspKFS0XEeoKrOxsdM=
go.etcd.io/bbolt v1.3.2 h1:Z/90sZLPOeCy2PwprqkFa25PdkusRzaj9P8zm/KNyvk=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
Expand Down
26 changes: 19 additions & 7 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/Unknwon/com"
"github.com/go-xorm/xorm"
"go.chromium.org/luci/common/sync/mutexpool"
"xorm.io/builder"
)

Expand Down Expand Up @@ -70,6 +71,7 @@ type Issue struct {
var (
issueTasksPat *regexp.Regexp
issueTasksDonePat *regexp.Regexp
issueIDLock mutexpool.P
)

const issueTasksRegexpStr = `(^\s*[-*]\s\[[\sx]\]\s.)|(\n\s*[-*]\s\[[\sx]\]\s.)`
Expand Down Expand Up @@ -1052,14 +1054,22 @@ func getMaxIndexOfIssue(e Engine, repoID int64) (int64, error) {
return maxIndex, nil
}

func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)

maxIndex, err := getMaxIndexOfIssue(e, opts.Issue.RepoID)
func issueSyncCreate(e *xorm.Session, issue *Issue) error {
maxIndex, err := getMaxIndexOfIssue(e, issue.RepoID)
if err != nil {
return err
}
opts.Issue.Index = maxIndex + 1
issue.Index = maxIndex + 1

if _, err = e.Insert(issue); err != nil {
return err
}

return nil
}

func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)

if opts.Issue.MilestoneID > 0 {
milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID)
Expand Down Expand Up @@ -1108,8 +1118,10 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
}
}

// Milestone and assignee validation should happen before insert actual object.
if _, err = e.Insert(opts.Issue); err != nil {
// Calculate Issue.Index and create; make sure nobody else is doing the same for this RepoID
if issueIDLock.WithMutex(opts.Issue.RepoID, func() {
err = issueSyncCreate(e, opts.Issue)
}); err != nil {
return err
}

Expand Down
14 changes: 14 additions & 0 deletions vendor/go.chromium.org/luci/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions vendor/go.chromium.org/luci/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

202 changes: 202 additions & 0 deletions vendor/go.chromium.org/luci/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading