-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19551 - Address deficiencies in pessimistic locking #10194
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
Conversation
Excellent! |
hibernate-core/src/main/java/org/hibernate/query/spi/AbstractCommonQueryContract.java
Dismissed
Show dismissed
Hide dismissed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java
Fixed
Show fixed
Hide fixed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
...rnate-core/src/main/java/org/hibernate/sql/ast/internal/StandardForUpdateClauseStrategy.java
Fixed
Show fixed
Hide fixed
Unless I did something silly, this should be just Oracle failures now. Need to investigate those more. |
hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
Dismissed
Show dismissed
Hide dismissed
hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
Dismissed
Show dismissed
Hide dismissed
...rnate-core/src/main/java/org/hibernate/dialect/lock/internal/SqlAstBasedLockingStrategy.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/test/java/org/hibernate/orm/test/locking/options/ScopeTests.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/test/java/org/hibernate/orm/test/locking/options/ScopeTests.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/test/java/org/hibernate/orm/test/locking/options/ScopeTests.java
Fixed
Show fixed
Hide fixed
hibernate-testing/src/main/java/org/hibernate/testing/orm/transaction/TransactionUtil.java
Fixed
Show fixed
Hide fixed
eaede26
to
321fd2e
Compare
hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java
Fixed
Show fixed
Hide fixed
...nate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java
Fixed
Show fixed
Hide fixed
...nate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java
Fixed
Show fixed
Hide fixed
hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java
Fixed
Show fixed
Hide fixed
776d5f6
to
e0e279e
Compare
hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
Fixed
Show fixed
Hide fixed
hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java
Fixed
Show fixed
Hide fixed
535fa89
to
00f0c68
Compare
...e-community-dialects/src/main/java/org/hibernate/community/dialect/MariaDBLegacyDialect.java
Fixed
Show fixed
Hide fixed
About to head out for ~2 weeks of PTO... About test failures:
Some things I'd still like accomplish here...
WRT (2), currently I have: public interface LockingSupport {
Metadata getMetadata();
...
interface Metadata {
LockTimeoutType getLockTimeoutType(Timeout timeout);
RowLockStrategy getReadRowLockStrategy();
RowLockStrategy getWriteRowLockStrategy();
...
}
}
public class Dialect {
...
LockingSupport getLockingSupport();
} Thinking instead of something like: public interface LockingSupport {
Metadata getMetadata();
...
interface Metadata {
LockTimeoutType getLockTimeoutType(Timeout timeout);
RowLockStrategy getRowLockStrategy();
...
}
}
public class Dialect {
...
LockingSupport getWriteLockingSupport();
LockingSupport getReadLockingSupport();
} |
b111da9
to
e82dd20
Compare
if ( factoryHint instanceof Integer number ) { | ||
return number; | ||
} | ||
return Integer.parseInt( factoryHint.toString() ); |
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException Note
return Timeouts.WAIT_FOREVER; | ||
} | ||
assert value.endsWith( "s" ); | ||
final int secondsValue = Integer.parseInt( value.substring( 0, value.length() - 1 ) ); |
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException Note
876b982
to
9429a7a
Compare
Let's see if the MariaDB run still fails. The test failure there makes no sense and I cannot reproduce it locally. It is testing SKIP LOCKED support, which MariaDB supports since 10.3 or 10.6 (I've seen conflicting info online). Locally, at least, the image is:
|
I skipped it for MariaDB. |
03e73da
to
369fa94
Compare
The next steps should be to move actual handling of applying locking from the Dialect into this support contract. With that in mind, I'm thinking something like this: public interface LockingSupport {
/**
* Used as part of {@linkplain org.hibernate.sql.ast.SqlAstTranslator SQL AST translation}.
*/
LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockOptions lockOptions);
/**
* Used with {@linkplain org.hibernate.Session#lock Session-based locking}
*/
LockingStrategy getLockingStrategy(EntityPersister lockable, LockMode lockMode, Locking.Scope lockScope);
/**
* Used to apply locking to simple String-based SQL building, such as
* {@linkplain org.hibernate.Session#createNativeQuery "native" queries}.
*/
String applyLocksToSql(
String sql,
LockOptions aliasedLockOptions,
Map<String, String[]> keyColumnNames);
Metadata getReadLockMetadata();
Metadata getWriteLockMetadata();
OuterJoinLockingType getOuterJoinLockingType();
ConnectionLockTimeoutStrategy getConnectionLockTimeoutStrategy();
interface Metadata {
default PessimisticLockStyle getPessimisticLockStyle() {
return PessimisticLockStyle.CLAUSE;
}
default LockTimeoutType getLockTimeoutType(Timeout timeout) {
// matches legacy definition from Dialect where only "wait forever" was supported
if ( timeout.milliseconds() == Timeouts.WAIT_FOREVER_MILLI ) {
return LockTimeoutType.QUERY;
}
return LockTimeoutType.NONE;
}
default RowLockStrategy getRowLockStrategy() {
// by default, we report no support
return RowLockStrategy.NONE;
}
}
} As we cannot immediately remove methods such as |
Marking as ready for review, but keep in mind that this is just the first steps. I simply want to get this incorporated upstream asap to not have to deal with these painful rebases from upstream. |
// "SELECT FOR UPDATE can only be used with a single-table SELECT statement" | ||
return false; | ||
public LockingSupport getLockingSupport() { | ||
return NoLockingSupport.NO_LOCKING_SUPPORT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return NoLockingSupport.NO_LOCKING_SUPPORT; | |
return LockingSupportSimple.NO_OUTER_JOIN; |
public RowLockStrategy getReadRowLockStrategy() { | ||
return RowLockStrategy.NONE; | ||
public LockingSupport getLockingSupport() { | ||
return NoLockingSupport.NO_LOCKING_SUPPORT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return NoLockingSupport.NO_LOCKING_SUPPORT; | |
return LockingSupportSimple.NO_OUTER_JOIN; |
//TODO: check this! | ||
return false; | ||
public LockingSupport getLockingSupport() { | ||
return NoLockingSupport.NO_LOCKING_SUPPORT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return NoLockingSupport.NO_LOCKING_SUPPORT; | |
return LockingSupportSimple.NO_OUTER_JOIN; |
// https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-dml-select.html#fblangref25-dml-with-lock | ||
return false; | ||
public LockingSupport getLockingSupport() { | ||
return NoLockingSupport.NO_LOCKING_SUPPORT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return NoLockingSupport.NO_LOCKING_SUPPORT; | |
return LockingSupportSimple.NO_OUTER_JOIN; |
* Set the associated lock scope | ||
*/ | ||
public LockOptions setScope(Locking.Scope scope) { | ||
this.scope = scope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we keep the immutability checking code around for the time being to avoid accidental changes to the objects that are represented by the constants in this class?
this.scope = scope; | |
if ( immutable ) { | |
throw new UnsupportedOperationException("immutable global instance of LockOptions"); | |
} | |
this.scope = scope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I wanted to remove all of the constants here. Because having even one requires we have these checks. But one thing we could do is to subclass LockOptions to error on calls to setters to use with the constants.
final ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final ExecutorService executorService = Executors.newSingleThreadExecutor(); | |
try { | |
try ( ExecutorService executorService = Executors.newSingleThreadExecutor() ) { |
final ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final ExecutorService executorService = Executors.newSingleThreadExecutor(); | |
try { | |
try ( ExecutorService executorService = Executors.newSingleThreadExecutor() ) { |
HHH-19551 - Address deficiencies in pessimistic locking
[Please describe here what your change is about]
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19551