Skip to content

Commit 7541e92

Browse files
authored
IGNITE-27285 Make common approach to Lock exceptions with the same message (#7271)
1 parent e0f2ec7 commit 7541e92

File tree

8 files changed

+94
-15
lines changed

8 files changed

+94
-15
lines changed

modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/exception/OperationLockException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class OperationLockException extends LockException {
3636
public OperationLockException(RequestType requestOperationType, LockException cause) {
3737
super(
3838
cause.code(),
39-
format("Lock acquiring failed during request handling [requestOperationType={}].", requestOperationType),
39+
format("Failed to acquire a lock during request handling [requestOperationType={}].", requestOperationType),
4040
cause
4141
);
4242
}

modules/platforms/cpp/tests/odbc-test/transaction_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ TEST_F(transaction_test, transaction_error) {
591591
try {
592592
insert_test_value(conn2.m_statement, 2, "test_2");
593593
} catch (const odbc_exception &err) {
594-
EXPECT_THAT(err.message, testing::HasSubstr("Lock acquiring failed during request handling"));
594+
EXPECT_THAT(err.message, testing::HasSubstr("Failed to acquire a lock during request handling"));
595595
EXPECT_EQ(err.sql_state, "25000");
596596
throw;
597597
}

modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItTableScanTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ private static void assertPossibleDeadLockExceptionOnReadWriteSingleRowOperation
10831083
TransactionException.class,
10841084
Transactions.ACQUIRE_LOCK_ERR,
10851085
operation,
1086-
"Lock acquiring failed during request handling"
1086+
"Failed to acquire a lock during request handling"
10871087
);
10881088

10891089
Throwable rootCause = unwrapRootCause(transactionException);

modules/table/src/testFixtures/java/org/apache/ignite/internal/table/TxAbstractTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ protected void testTransactionAlreadyFinished(
23822382

23832383
private static void assertTransactionLockException(Exception e) {
23842384
assertInstanceOf(TransactionException.class, e);
2385-
assertThat(e.getMessage(), containsString("Lock acquiring failed during request handling"));
2385+
assertThat(e.getMessage(), containsString("Failed to acquire a lock during request handling"));
23862386

23872387
Throwable rootCause = unwrapRootCause(e);
23882388
assertInstanceOf(LockException.class, rootCause);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.tx;
19+
20+
import static org.apache.ignite.lang.ErrorGroups.Transactions.ACQUIRE_LOCK_TIMEOUT_ERR;
21+
22+
/**
23+
* This exception is thrown when a lock cannot be acquired in a timeout boundaries.
24+
*/
25+
public class AcquireLockTimeoutException extends LockException {
26+
/**
27+
* Constructor.
28+
*
29+
* @param waiter Waiter for lock acquisition.
30+
* @param exceededTimeout Exceeded timeout value in milliseconds.
31+
*/
32+
public AcquireLockTimeoutException(Waiter waiter, long exceededTimeout) {
33+
super(
34+
ACQUIRE_LOCK_TIMEOUT_ERR,
35+
"Failed to acquire a lock due to timeout [txId=" + waiter.txId()
36+
+ ", waiter=" + waiter
37+
+ ", timeoutMs=" + exceededTimeout
38+
+ ']'
39+
);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.tx;
19+
20+
import static org.apache.ignite.lang.ErrorGroups.Transactions.ACQUIRE_LOCK_ERR;
21+
22+
import java.util.UUID;
23+
24+
/**
25+
* This exception is thrown when the lock map size exceeded and new lock cannot be acquired and placed there.
26+
*/
27+
public class LockTableOverflowException extends LockException {
28+
/**
29+
* Constructor.
30+
*
31+
* @param failedTx Transaction that couldn't acquire a lock.
32+
* @param lockMapSizeLimit Current lock map size limit that was exceeded.
33+
*/
34+
public LockTableOverflowException(UUID failedTx, int lockMapSizeLimit) {
35+
super(
36+
ACQUIRE_LOCK_ERR,
37+
"Failed to acquire a lock due to lock table overflow [failedTxId=" + failedTx
38+
+ ", lockMapSizeLimit=" + lockMapSizeLimit + ']'
39+
);
40+
}
41+
}

modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.apache.ignite.internal.tx.event.LockEvent.LOCK_CONFLICT;
2424
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
2525
import static org.apache.ignite.lang.ErrorGroups.Transactions.ACQUIRE_LOCK_ERR;
26-
import static org.apache.ignite.lang.ErrorGroups.Transactions.ACQUIRE_LOCK_TIMEOUT_ERR;
2726

2827
import java.util.ArrayList;
2928
import java.util.Collection;
@@ -51,12 +50,14 @@
5150
import org.apache.ignite.internal.lang.IgniteBiTuple;
5251
import org.apache.ignite.internal.tostring.IgniteToStringExclude;
5352
import org.apache.ignite.internal.tostring.S;
53+
import org.apache.ignite.internal.tx.AcquireLockTimeoutException;
5454
import org.apache.ignite.internal.tx.DeadlockPreventionPolicy;
5555
import org.apache.ignite.internal.tx.Lock;
5656
import org.apache.ignite.internal.tx.LockException;
5757
import org.apache.ignite.internal.tx.LockKey;
5858
import org.apache.ignite.internal.tx.LockManager;
5959
import org.apache.ignite.internal.tx.LockMode;
60+
import org.apache.ignite.internal.tx.LockTableOverflowException;
6061
import org.apache.ignite.internal.tx.PossibleDeadlockOnLockAcquireException;
6162
import org.apache.ignite.internal.tx.Waiter;
6263
import org.apache.ignite.internal.tx.event.LockEvent;
@@ -165,10 +166,7 @@ public CompletableFuture<Lock> acquire(UUID txId, LockKey lockKey, LockMode lock
165166
LockState state = acquireLockState(lockKey);
166167

167168
if (state == null) {
168-
return failedFuture(new LockException(
169-
ACQUIRE_LOCK_ERR,
170-
"Failed to acquire a lock due to lock table overflow [txId=" + txId + ", limit=" + lockMapSize + ']'
171-
));
169+
return failedFuture(new LockTableOverflowException(txId, lockMapSize));
172170
}
173171

174172
IgniteBiTuple<CompletableFuture<Void>, LockMode> futureTuple = state.tryAcquire(txId, lockMode);
@@ -900,7 +898,8 @@ private boolean isWaiterReadyToNotify(WaiterImpl waiter, boolean skipFail) {
900898
} else if (deadlockPreventionPolicy.waitTimeout() == 0) {
901899
waiter.fail(new PossibleDeadlockOnLockAcquireException(
902900
waiter.txId,
903-
tmp.txId, intendedLockMode,
901+
tmp.txId,
902+
intendedLockMode,
904903
currentlyAcquiredLockMode
905904
));
906905

@@ -1047,9 +1046,7 @@ private List<WaiterImpl> unlockCompatibleWaiters() {
10471046
private void setWaiterTimeout(WaiterImpl waiter) {
10481047
delayedExecutor.execute(() -> {
10491048
if (!waiter.fut.isDone()) {
1050-
waiter.fut.completeExceptionally(new LockException(ACQUIRE_LOCK_TIMEOUT_ERR, "Failed to acquire a lock due to "
1051-
+ "timeout [txId=" + waiter.txId() + ", waiter=" + waiter
1052-
+ ", timeout=" + deadlockPreventionPolicy.waitTimeout() + ']'));
1049+
waiter.fut.completeExceptionally(new AcquireLockTimeoutException(waiter, deadlockPreventionPolicy.waitTimeout()));
10531050
}
10541051
});
10551052
}

modules/transactions/src/test/java/org/apache/ignite/internal/tx/HeapLockManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testLockTableOverflow() throws Exception {
7171
CompletableFuture<Lock> overflowLockFut = lockManager.acquire(overflowTx, new LockKey(overflowTx, overflowTx), LockMode.S);
7272

7373
assertThat(overflowLockFut, willThrowWithCauseOrSuppressed(
74-
LockException.class,
74+
LockTableOverflowException.class,
7575
"Failed to acquire a lock due to lock table overflow"
7676
));
7777

@@ -107,7 +107,7 @@ public void testLockTooManyKeysInTx() throws Exception {
107107
CompletableFuture<Lock> overflowLockFut = lockManager.acquire(txId, new LockKey(i, i), LockMode.S);
108108

109109
assertThat(overflowLockFut, willThrowWithCauseOrSuppressed(
110-
LockException.class,
110+
LockTableOverflowException.class,
111111
"Failed to acquire a lock due to lock table overflow"
112112
));
113113
}

0 commit comments

Comments
 (0)