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

feat!: EXPOSED-740 Add support for modes (SKIP LOCKED or NOWAIT) with ForUpdate and ForShare Option for MySQL #2421

Merged

Conversation

mfazalul
Copy link
Contributor

@mfazalul mfazalul commented Feb 23, 2025

Description

Summary of the change: Adds the SKIP LOCKED and NO WAIT modes when using SELECT ... FOR UPDATE. Also adds tests to make sure that the queries are generated as expected. Breaking change: Moved ForUpdateBase outside Postgres.

Detailed description:

  • What:

    • Added the MODE option for MySQL, that can be used to define modes for ForUpdate and ForShare.
    • Refactored the ForUpdateOption class so that some of the methods are available across DBs
    • The ForUpdateBase class has been moved out of Postgres, which is a breaking change.
    • Mostly repackages the tests for Postgres.
  • Why:

    • Since MySQL 8.0.1, there has been support for ForUpdate and ForShare modes.
    • https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html
    • However, the implementation only supported it for Postgres.
    • For work, I've been having to use raw SQL when I needed the functionality. This would help avoid the need for that for myself as well as others.
  • How:

    • I'm new to the repo (and Kotlin), so I tried to make sure I minimize the amount of code I touched.
    • ForUpdateBase was moved outside the Postgres implementation to make it available for MySQL as well.
    • Introduced a sealed interface which allows us to define the enum in different DBs accordingly. All DBs do not always support all the modes we have.
    • Since we use an enum, I could not use a sealed class, and there is some conditional logic to get statements in ForUpdateOption.

Type of Change

  • Bug fix
  • New feature
  • Documentation update

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • MariaDB
  • Mysql5
  • Mysql8
  • Oracle
  • Postgres
  • SqlServer
  • H2
  • SQLite

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

return table.selectAll().where { table.id eq id }.forUpdate(option).city()
}

withDb(TestDB.MYSQL_V8) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know how it's implemented in Postgres tests, but it would be better if you replace the part:

withDb(TestDB.MYSQL_V8) {
  withTable {
  <code>
  }
}

with the following code:

withTables(excludeSettings = TestDB.ALL - TestDB.MYSQL_V8, <table>) {
  <code>
}

and remove the method withTable for that one particular table.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if you update Postgres's test like in #2425 also, just some cleanup if we touched that functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the updates to both tests, ty

@obabichevjb
Copy link
Collaborator

In general it looks good to me.

If I'm right this PR contains breaking change. At least the public class ForUpdateOption.PostgreSQL.ForUpdateBase class was public, and now it's removed. If somebody was using this class directly it will cause compilation error.

Could you mark title of the PR as feat!: and add small notice about it into description?

@mfazalul mfazalul force-pushed the mfazalul/add-forupdate-options-mysql branch from a5f26b8 to 20ae3d4 Compare February 24, 2025 14:20
@mfazalul mfazalul changed the title feat: EXPOSED-740 Add support for modes (SKIP LOCKED or NOWAIT) with ForUpdate and ForShare Option for MySQL feat!: EXPOSED-740 Add support for modes (SKIP LOCKED or NOWAIT) with ForUpdate and ForShare Option for MySQL Feb 24, 2025
@mfazalul mfazalul requested a review from obabichevjb February 24, 2025 14:24
@obabichevjb
Copy link
Collaborator

obabichevjb commented Feb 25, 2025

@mfazalul Hi, CI has failed. Quite recently we introduced requirements for commit messages to follow conventional commits, and CI validates it. It would be good, if you add prefix feat!: to all commit messages, or just squash all of them.

You could also recheck gradle detekt and gradle apiDump to be sure that there no problems with linter and api files state.

@mfazalul mfazalul force-pushed the mfazalul/add-forupdate-options-mysql branch from 20ae3d4 to bceef5f Compare February 25, 2025 12:40
@mfazalul
Copy link
Contributor Author

@obabichevjb updated, ty. I also see a message

Merge is not an allowed merge method in this repository. This branch must not contain merge commits.

I do not seem to have an option to change the merge method, is that something you can do when merging?

@obabichevjb obabichevjb merged commit e0e025c into JetBrains:main Feb 26, 2025
5 checks passed
@obabichevjb
Copy link
Collaborator

Thank you for the PR,

I do not seem to have an option to change the merge method

I'm not sure you have access for it (as well as for merging PR), but you have option to squash commits in your branch and force push them, in this case PR will be left with only one commit.

Anyway, the commits can be squashed in the moment of merge, so it's only the question of passing check for commit names.

@mfazalul mfazalul deleted the mfazalul/add-forupdate-options-mysql branch February 26, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants