Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public LockTimeoutType getLockTimeoutType(Timeout timeout) {
return switch (timeout.milliseconds()) {
case WAIT_FOREVER_MILLI -> QUERY;
case NO_WAIT_MILLI -> supportsNoWait ? QUERY : LockTimeoutType.NONE;
// Due to https://github.com/cockroachdb/cockroach/issues/88995, locking doesn't work properly
// without certain configuration options and hence skipping locked rows also doesn't work correctly.
case SKIP_LOCKED_MILLI -> LockTimeoutType.NONE;
// it does not, however, support WAIT as part of for-update, but does support a connection-level lock_timeout setting
default -> CONNECTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ protected void tearDown() {

@Test
@JiraKey( value = "HHH-8786" )
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(dialectClass = InformixDialect.class, reason = "no failure")
public void testLockTimeoutFind() {
final Item item = new Item( "find" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void testFindWithTimeoutHint() {
@RequiresDialectFeature( value = DialectChecks.SupportsLockTimeouts.class,
comment = "Test verifies proper exception throwing when a lock timeout is specified.",
jiraKey = "HHH-7252" )
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase close socket after lock timeout occurred")
public void testFindWithPessimisticWriteLockTimeoutException() {
Lock lock = new Lock();
Expand Down Expand Up @@ -157,7 +156,6 @@ public void testFindWithPessimisticWriteLockTimeoutException() {
@RequiresDialectFeature( value = DialectChecks.SupportsLockTimeouts.class,
comment = "Test verifies proper exception throwing when a lock timeout is specified for Query#getSingleResult.",
jiraKey = "HHH-13364" )
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase close socket after lock timeout occurred")
public void testQuerySingleResultPessimisticWriteLockTimeoutException() {
Lock lock = new Lock();
Expand Down Expand Up @@ -204,7 +202,6 @@ public void testQuerySingleResultPessimisticWriteLockTimeoutException() {
@RequiresDialectFeature( value = DialectChecks.SupportsLockTimeouts.class,
comment = "Test verifies proper exception throwing when a lock timeout is specified for Query#getResultList.",
jiraKey = "HHH-13364" )
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase close socket after lock timeout occurred")
public void testQueryResultListPessimisticWriteLockTimeoutException() {
Lock lock = new Lock();
Expand Down Expand Up @@ -254,7 +251,6 @@ public void testQueryResultListPessimisticWriteLockTimeoutException() {
@RequiresDialectFeature( value = DialectChecks.SupportsLockTimeouts.class,
comment = "Test verifies proper exception throwing when a lock timeout is specified for NamedQuery#getResultList.",
jiraKey = "HHH-13364" )
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase close socket after lock timeout occurred")
public void testNamedQueryResultListPessimisticWriteLockTimeoutException() {
Lock lock = new Lock();
Expand Down Expand Up @@ -298,7 +294,6 @@ public void testNamedQueryResultListPessimisticWriteLockTimeoutException() {

@Test
@RequiresDialectFeature( value = DialectChecks.SupportsSkipLocked.class )
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
public void testUpdateWithPessimisticReadLockSkipLocked() {
Lock lock = new Lock();
lock.setName( "name" );
Expand Down Expand Up @@ -343,7 +338,6 @@ public void testUpdateWithPessimisticReadLockSkipLocked() {

@Test
@RequiresDialectFeature(value = DialectChecks.SupportsLockTimeouts.class)
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
public void testUpdateWithPessimisticReadLockWithoutNoWait() {
Lock lock = new Lock();
lock.setName( "name" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.hibernate.testing.DialectChecks;
Expand All @@ -35,7 +34,6 @@
* @author Andrea Boriero
*/
@RequiresDialectFeature({DialectChecks.SupportsLockTimeouts.class})
@SkipForDialect(value = CockroachDialect.class, comment = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase does not close Statement after lock timeout")
public class StatementIsClosedAfterALockExceptionTest extends BaseEntityManagerFunctionalTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void prepareTest() throws Exception {

@Test
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsLockTimeouts.class )
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Can't commit transaction because Altibase closes socket after lock timeout")
public void testLoading() {
// open a session, begin a transaction and lock row
Expand All @@ -104,7 +103,6 @@ public void testLoading() {

@Test
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsLockTimeouts.class )
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Can't commit transaction because Altibase closes socket after lock timeout")
public void testCriteria() {
// open a session, begin a transaction and lock row
Expand All @@ -128,7 +126,6 @@ public void testCriteria() {

@Test
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsLockTimeouts.class )
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Can't commit transaction because Altibase closes socket after lock timeout")
public void testCriteriaAliasSpecific() {
// open a session, begin a transaction and lock row
Expand All @@ -154,7 +151,6 @@ public void testCriteriaAliasSpecific() {

@Test
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsLockTimeouts.class )
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "for update clause does not imply locking. See https://github.com/cockroachdb/cockroach/issues/88995")
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Can't commit transaction because Altibase closes socket after lock timeout")
public void testQuery() {
// open a session, begin a transaction and lock row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.function.Function;
import jakarta.persistence.EntityManager;

import jakarta.persistence.QueryTimeoutException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.SharedSessionContract;
Expand Down Expand Up @@ -172,7 +173,8 @@ public static void deleteRow(SessionFactoryScope factoryScope, String tableName,
}
catch (RuntimeException re) {
if ( re.getCause() instanceof jakarta.persistence.LockTimeoutException
|| re.getCause() instanceof org.hibernate.exception.LockTimeoutException ) {
|| re.getCause() instanceof org.hibernate.exception.LockTimeoutException
|| re.getCause() instanceof QueryTimeoutException ) {
if ( !expectingToBlock ) {
fail( "Expecting update to " + tableName + " to succeed, but failed due to async timeout (presumably due to locks)", re.getCause() );
}
Expand Down Expand Up @@ -227,7 +229,8 @@ else if ( !expectingToBlock && resultSize == 0 ) {
}
catch (RuntimeException re) {
if ( re.getCause() instanceof jakarta.persistence.LockTimeoutException
|| re.getCause() instanceof org.hibernate.exception.LockTimeoutException ) {
|| re.getCause() instanceof org.hibernate.exception.LockTimeoutException
|| re.getCause() instanceof QueryTimeoutException ) {
if ( !expectingToBlock ) {
fail( "Expecting update to " + tableName + " to succeed, but failed due to async timeout (presumably due to locks)", re.getCause() );
}
Expand Down
3 changes: 2 additions & 1 deletion local-build-plugins/src/main/groovy/local.databases.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ ext {
'jdbc.url' : 'jdbc:postgresql://' + dbHost + ':26257/defaultdb?sslmode=disable&preparedStatementCacheQueries=0&escapeSyntaxCallMode=callIfNoReturn',
'jdbc.datasource' : 'org.postgresql.Driver',
// 'jdbc.datasource' : 'org.postgresql.ds.PGSimpleDataSource',
'connection.init_sql' : ''
// Configure the for-update clause to use proper locks: https://github.com/cockroachdb/cockroach/issues/88995
'connection.init_sql' : 'set enable_durable_locking_for_serializable = on; set optimizer_use_lock_op_for_serializable = on;'
],
firebird : [
'db.dialect' : 'org.hibernate.community.dialect.FirebirdDialect',
Expand Down