denis-chudov commented on code in PR #7566:
URL: https://github.com/apache/ignite-3/pull/7566#discussion_r2789569760
##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/AbstractLockManagerTest.java:
##########
@@ -1125,6 +1126,78 @@ public void testAcquireLockAfterFail() {
assertThat(f, willCompleteSuccessfully());
}
+ @Test
+ public void testFailWaiter() {
+ UUID older = TestTransactionIds.newTransactionId();
+ UUID newer = TestTransactionIds.newTransactionId();
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(newer, lockKey(),
X);
+ assertTrue(fut1.isDone());
+
+ // Currently only S locks are allowed to wait.
Review Comment:
What do you mean? It depends only on txn order, test passes with X locks as
well
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java:
##########
@@ -759,6 +801,26 @@ public boolean coarse() {
return false;
}
+ @Override
+ public void tryFail(UUID txId, Exception cause) {
+ WaiterImpl waiter0 = null;
+
+ synchronized (waiters) {
+ WaiterImpl waiter = waiters.get(txId);
+
+ // Waiter can be null if it was invalidate by order conflict
resolution logic.
Review Comment:
```suggestion
// Waiter can be null if it was invalidated by order
conflict resolution logic.
```
##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/AbstractLockManagerTest.java:
##########
@@ -1125,6 +1126,78 @@ public void testAcquireLockAfterFail() {
assertThat(f, willCompleteSuccessfully());
}
+ @Test
+ public void testFailWaiter() {
+ UUID older = TestTransactionIds.newTransactionId();
+ UUID newer = TestTransactionIds.newTransactionId();
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(newer, lockKey(),
X);
+ assertTrue(fut1.isDone());
+
+ // Currently only S locks are allowed to wait.
+ CompletableFuture<Lock> fut2 = lockManager.acquire(older, lockKey(),
S);
+ assertFalse(fut2.isDone());
+
+ // Should do nothing.
+ lockManager.failAllWaiters(newer, new Exception());
+ assertFalse(fut2.isDone());
+
+ lockManager.failAllWaiters(older, new Exception("test"));
+ assertThat(fut2, willThrowWithCauseOrSuppressed(Exception.class,
"test"));
+
+ lockManager.releaseAll(older);
+ lockManager.releaseAll(newer);
+ }
+
+ @Test
+ public void testFailWaiter2() {
+ UUID tx1 = TestTransactionIds.newTransactionId();
+ UUID tx2 = TestTransactionIds.newTransactionId();
+ UUID tx3 = TestTransactionIds.newTransactionId();
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(tx1, lockKey(), S);
+ assertTrue(fut1.isDone());
+
+ CompletableFuture<Lock> fut2 = lockManager.acquire(tx2, lockKey(), S);
+ assertTrue(fut2.isDone());
+
+ CompletableFuture<Lock> fut3 = lockManager.acquire(tx3, lockKey(), S);
+ assertTrue(fut3.isDone());
+
+ CompletableFuture<Lock> fut4 = lockManager.acquire(tx2, lockKey(), X);
+ assertFalse(fut4.isDone());
+
+ lockManager.releaseAll(tx3);
+
+ lockManager.failAllWaiters(tx2, new Exception());
+
+ lockManager.releaseAll(tx2);
Review Comment:
What do you check here?
##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/AbstractLockManagerTest.java:
##########
@@ -1125,6 +1126,78 @@ public void testAcquireLockAfterFail() {
assertThat(f, willCompleteSuccessfully());
}
+ @Test
+ public void testFailWaiter() {
+ UUID older = TestTransactionIds.newTransactionId();
+ UUID newer = TestTransactionIds.newTransactionId();
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(newer, lockKey(),
X);
+ assertTrue(fut1.isDone());
+
+ // Currently only S locks are allowed to wait.
+ CompletableFuture<Lock> fut2 = lockManager.acquire(older, lockKey(),
S);
+ assertFalse(fut2.isDone());
+
+ // Should do nothing.
+ lockManager.failAllWaiters(newer, new Exception());
+ assertFalse(fut2.isDone());
+
+ lockManager.failAllWaiters(older, new Exception("test"));
+ assertThat(fut2, willThrowWithCauseOrSuppressed(Exception.class,
"test"));
+
+ lockManager.releaseAll(older);
+ lockManager.releaseAll(newer);
+ }
+
+ @Test
+ public void testFailWaiter2() {
+ UUID tx1 = TestTransactionIds.newTransactionId();
+ UUID tx2 = TestTransactionIds.newTransactionId();
+ UUID tx3 = TestTransactionIds.newTransactionId();
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(tx1, lockKey(), S);
+ assertTrue(fut1.isDone());
+
+ CompletableFuture<Lock> fut2 = lockManager.acquire(tx2, lockKey(), S);
+ assertTrue(fut2.isDone());
+
+ CompletableFuture<Lock> fut3 = lockManager.acquire(tx3, lockKey(), S);
+ assertTrue(fut3.isDone());
+
+ CompletableFuture<Lock> fut4 = lockManager.acquire(tx2, lockKey(), X);
+ assertFalse(fut4.isDone());
+
+ lockManager.releaseAll(tx3);
+
+ lockManager.failAllWaiters(tx2, new Exception());
+
+ lockManager.releaseAll(tx2);
+ lockManager.releaseAll(tx1);
+ }
+
+ @Test
+ public void testFailWaiter3() {
+ UUID tx1 = TestTransactionIds.newTransactionId();
+ UUID tx2 = TestTransactionIds.newTransactionId();
+ UUID tx3 = TestTransactionIds.newTransactionId();
+
+ CompletableFuture<Lock> fut3 = lockManager.acquire(tx3, lockKey(), S);
+ assertTrue(fut3.isDone());
+
+ CompletableFuture<Lock> fut2 = lockManager.acquire(tx2, lockKey(), X);
+ assertFalse(fut2.isDone());
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(tx1, lockKey(), S);
+ assertTrue(fut1.isDone());
+
+ lockManager.releaseAll(tx3);
+
+ lockManager.failAllWaiters(tx2, new Exception());
+
+ lockManager.releaseAll(tx2);
+ lockManager.releaseAll(tx1);
+ }
+
Review Comment:
you can also add a test where
tx3 acquires S
tx2 tries to acquire X
tx1 tries to acquire X
failAllWaiters on tx2
releaseAll on tx3
tx1 acquires the lock
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]