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

Move from max( id ) to max( index ) for latest commit statuses #30076

Merged
merged 6 commits into from
Mar 28, 2024

Conversation

stevapple
Copy link
Contributor

@stevapple stevapple commented Mar 25, 2024

This PR replaces the use of max( id ), and instead using max( `index` ) for determining the latest commit status. Building business logic over an auto_increment primary key like id is risky and there’re already plenty of discussions on the Internet.

There‘s no guarantee for auto_increment values to be monotonic, especially upon failures or with a cluster. In the specific case, we met the problem of commit statuses being outdated when using TiDB as the database. As being documented, auto_increment values assigned to an insert statement will only be monotonic on a per server (node) basis.

Closes #30074.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 25, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 25, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Mar 25, 2024
@stevapple stevapple force-pushed the fix-commit-status branch 2 times, most recently from 638fea7 to 1b48878 Compare March 25, 2024 19:41
@stevapple
Copy link
Contributor Author

Ping for a review

@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 Mar 27, 2024
@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 Mar 28, 2024
@lunny lunny added this to the 1.22.0 milestone Mar 28, 2024
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 28, 2024
@stevapple
Copy link
Contributor Author

@lunny May it be back-ported to v1.21, or is v1.22 around the corner?

@stevapple stevapple changed the title Move from max( id ) to max ( index ) for latest commit statuses Move from max( id ) to max( index ) for latest commit statuses Mar 28, 2024
@lunny lunny added the backport/v1.21 This PR should be backported to Gitea 1.21 label Mar 28, 2024
@lunny lunny merged commit 7443a10 into go-gitea:main Mar 28, 2024
26 checks passed
@GiteaBot
Copy link
Contributor

I was unable to create a backport for 1.21. @stevapple, please send one manually. 🍵

go run ./contrib/backport 30076
...  // fix git conflicts if any
go run ./contrib/backport --continue

@GiteaBot GiteaBot added backport/manual No power to the bots! Create your backport yourself! and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Mar 28, 2024
stevapple added a commit to stevapple/gitea that referenced this pull request Mar 28, 2024
…o-gitea#30076)

This PR replaces the use of `max( id )`, and instead using ``max(
`index` )`` for determining the latest commit status. Building business
logic over an `auto_increment` primary key like `id` is risky and
there’re already plenty of discussions on the Internet.

There‘s no guarantee for `auto_increment` values to be monotonic,
especially upon failures or with a cluster. In the specific case, we met
the problem of commit statuses being outdated when using TiDB as the
database. As [being
documented](https://docs.pingcap.com/tidb/stable/auto-increment),
`auto_increment` values assigned to an `insert` statement will only be
monotonic on a per server (node) basis.

Closes go-gitea#30074.
silverwind pushed a commit that referenced this pull request Mar 28, 2024
…30076) (#30155)

Backport #30076.

This PR replaces the use of `max( id )`, and instead using ``max(
`index` )`` for determining the latest commit status. Building business
logic over an `auto_increment` primary key like `id` is risky and
there’re already plenty of discussions on the Internet.

There‘s no guarantee for `auto_increment` values to be monotonic,
especially upon failures or with a cluster. In the specific case, we met
the problem of commit statuses being outdated when using TiDB as the
database. As [being
documented](https://docs.pingcap.com/tidb/stable/auto-increment),
`auto_increment` values assigned to an `insert` statement will only be
monotonic on a per server (node) basis.

Closes #30074.
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 29, 2024
* upstream/main:
  Remove fomantic checkbox module (go-gitea#30162)
  Refactor topic Find functions and add more tests for pagination (go-gitea#30127)
  replace jquery-minicolors with coloris (go-gitea#30055)
  Add API for `Variables` (go-gitea#29520)
  Fix `DEFAULT_SHOW_FULL_NAME=false` has no effect in commit list and commit graph page (go-gitea#30096)
  Fix migration v292 (go-gitea#30153)
  Adjust VS Code debug filename match in .gitignore (go-gitea#30158)
  Prevent re-review and dismiss review actions on closed and merged PRs (go-gitea#30065)
  Render code tags in commit messages (go-gitea#30146)
  Bump `@github/relative-time-element` to v4.4.0 (go-gitea#30154)
  Migrate font-family to tailwind (go-gitea#30118)
  Move from `max( id )` to `max( index )` for latest commit statuses (go-gitea#30076)
  Remember login for a month by default (go-gitea#30150)
@lunny lunny added the backport/done All backports for this PR have been created label Apr 12, 2024
lunny pushed a commit that referenced this pull request Apr 30, 2024
Caused by #30076. 

There may be some duplicate status check contexts when setting status
checks for a branch protection rule. The duplicate contexts should be
removed.

Before:
<img
src="https://github.com/go-gitea/gitea/assets/15528715/97f4de2d-4868-47a3-8a99-5a180f9ac0a3"
width="600px" />

After:
<img
src="https://github.com/go-gitea/gitea/assets/15528715/ff7289c5-9793-4090-ba31-e8cb3c85f8a3"
width="600px" />
Zettat123 added a commit to Zettat123/gitea that referenced this pull request Apr 30, 2024
Caused by go-gitea#30076.

There may be some duplicate status check contexts when setting status
checks for a branch protection rule. The duplicate contexts should be
removed.

Before:
<img
src="https://github.com/go-gitea/gitea/assets/15528715/97f4de2d-4868-47a3-8a99-5a180f9ac0a3"
width="600px" />

After:
<img
src="https://github.com/go-gitea/gitea/assets/15528715/ff7289c5-9793-4090-ba31-e8cb3c85f8a3"
width="600px" />
lunny pushed a commit that referenced this pull request Apr 30, 2024
Backport #30660.

Caused by #30076.

There may be some duplicate status check contexts when setting status
checks for a branch protection rule. The duplicate contexts should be
removed.

Before:
<img

src="https://github.com/go-gitea/gitea/assets/15528715/97f4de2d-4868-47a3-8a99-5a180f9ac0a3"
width="600px" />

After:
<img

src="https://github.com/go-gitea/gitea/assets/15528715/ff7289c5-9793-4090-ba31-e8cb3c85f8a3"
width="600px" />
Zettat123 added a commit to Zettat123/gitea that referenced this pull request Apr 30, 2024
Caused by go-gitea#30076. 

There may be some duplicate status check contexts when setting status
checks for a branch protection rule. The duplicate contexts should be
removed.

Before:
<img
src="https://github.com/go-gitea/gitea/assets/15528715/97f4de2d-4868-47a3-8a99-5a180f9ac0a3"
width="600px" />

After:
<img
src="https://github.com/go-gitea/gitea/assets/15528715/ff7289c5-9793-4090-ba31-e8cb3c85f8a3"
width="600px" />
lunny pushed a commit that referenced this pull request May 1, 2024
Backport #30660.

Caused by #30076. 

There may be some duplicate status check contexts when setting status
checks for a branch protection rule. The duplicate contexts should be
removed.

Before:
<img

src="https://github.com/go-gitea/gitea/assets/15528715/97f4de2d-4868-47a3-8a99-5a180f9ac0a3"
width="600px" />

After:
<img

src="https://github.com/go-gitea/gitea/assets/15528715/ff7289c5-9793-4090-ba31-e8cb3c85f8a3"
width="600px" />
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 26, 2024
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 backport/manual No power to the bots! Create your backport yourself! backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gitea shows outdated commit status with distributed DB backend (eg. TiDB)
4 participants