-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Generate status commit index parallelly failed #24532
Labels
issue/duplicate
The issue has already been reported.
Comments
|
Try this: diff --git a/models/git/commit_status.go b/models/git/commit_status.go
index 82cbb2363..f6e9ce1da 100644
--- a/models/git/commit_status.go
+++ b/models/git/commit_status.go
@@ -82,7 +82,23 @@ func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (in
}
if affected == 0 {
// this slow path is only for the first time of creating a resource index
- _, errIns := e.Exec("INSERT INTO `commit_status_index` (repo_id, sha, max_index) VALUES (?, ?, 0)", repoID, sha)
+ var errIns error
+ for i := 0; i < 5; i++ {
+ // in case mysql deadlock occurs, retry for a few times
+ // Error 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
+ // To reproduce:
+ // * txn1: truncate commit_status_index; begin; update commit_status_index set max_index=max_index+1 where sha='xxx' and repo_id=1;
+ // * txn2: begin; update commit_status_index set max_index=max_index+1 where sha='xxx' and repo_id=1;
+ // * txn1: insert into `commit_status_index` (repo_id, sha, max_index) values (1, 'xxx', 0);
+ // * txn2: insert into `commit_status_index` (repo_id, sha, max_index) values (1, 'xxx', 0); -- then deadlock
+ // * then txn1 can commit, txn2 can retry and commit
+ _, errIns = e.Exec("INSERT INTO `commit_status_index` (repo_id, sha, max_index) VALUES (?, ?, 0)", repoID, sha)
+ if errIns != nil && strings.Contains(errIns.Error(), "Deadlock") {
+ continue
+ } else {
+ break
+ }
+ }
res, err = e.Exec("UPDATE `commit_status_index` SET max_index=max_index+1 WHERE repo_id=? AND sha=?", repoID, sha)
if err != nil {
return 0, err |
Could you help to send the commit to #24567 ? |
No, I have no writer permission. |
lunny
added
issue/duplicate
The issue has already been reported.
and removed
type/bug
labels
May 9, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Description
Gitea Version
8f17237
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
CI with mysql8 database
Database
None
The text was updated successfully, but these errors were encountered: