This is an automated email from the ASF dual-hosted git repository.
vldpyatkov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 6cc1855d36e IGNITE-29279 Enforce transactional lock wait timeouts on
primary nodes (#13817)
6cc1855d36e is described below
commit 6cc1855d36e59ee37847b42e8b0cae29bc1f2c1a
Author: Vladislav Pyatkov <[email protected]>
AuthorDate: Sun Nov 15 21:15:23 2026 +0300
IGNITE-29279 Enforce transactional lock wait timeouts on primary nodes
(#13817)
---
.../integration/SqlPlanHistoryIntegrationTest.java | 5 +-
.../dht/colocated/GridDhtColocatedLockFuture.java | 54 +++---
.../cache/distributed/near/GridNearLockFuture.java | 55 +++---
.../distributed/near/GridNearLockRequest.java | 10 +-
.../cache/distributed/near/GridNearTxLocal.java | 8 +-
.../processors/cache/CacheLockWaitTimeoutTest.java | 188 +++++++++++++++++++++
.../snapshot/IgniteClusterSnapshotCheckTest.java | 3 +-
.../ScanQueryConcurrentUpdatesAbstractTest.java | 15 +-
.../apache/ignite/testframework/GridTestUtils.java | 11 ++
.../ignite/testsuites/IgniteCacheTestSuite4.java | 3 +
10 files changed, 273 insertions(+), 79 deletions(-)
diff --git
a/modules/calcite-testing/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlPlanHistoryIntegrationTest.java
b/modules/calcite-testing/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlPlanHistoryIntegrationTest.java
index b4a02664bd6..7d1fcba57b2 100644
---
a/modules/calcite-testing/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlPlanHistoryIntegrationTest.java
+++
b/modules/calcite-testing/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlPlanHistoryIntegrationTest.java
@@ -65,6 +65,7 @@ import static
org.apache.ignite.configuration.SqlConfiguration.DFLT_SQL_PLAN_HIS
import static
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.startCollectStatistics;
import static
org.apache.ignite.internal.processors.query.running.RunningQueryManager.SQL_PLAN_HIST_VIEW;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+import static
org.apache.ignite.testframework.GridTestUtils.waitForNextClockTick;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@@ -445,9 +446,7 @@ public class SqlPlanHistoryIntegrationTest extends
GridCommonAbstractWrapperTest
firstTs = F.first(getSqlPlanHistory()).lastStartTime().getTime();
- long curTs = U.currentTimeMillis();
-
- assertTrue(waitForCondition(() -> (U.currentTimeMillis() != curTs),
1000));
+ waitForNextClockTick();
cacheQuery(new SqlFieldsQuery(SQL), "A");
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
index 1dc33ad6887..ff611bd6699 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
@@ -140,6 +140,9 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
/** Lock wait timeout. */
private final long waitTimeout;
+ /** Time when the first primary batch starts, or zero before mapping. */
+ private long lockWaitStartTime;
+
/** Transaction. */
@GridToStringExclude
private final GridNearTxLocal tx;
@@ -805,7 +808,7 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
if (isDone()) // Possible due to async rollback.
return;
- if (lockTimeout() > 0) {
+ if (timeout > 0) {
timeoutObj = new LockTimeoutObject();
cctx.time().addTimeoutObject(timeoutObj);
@@ -1124,7 +1127,6 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
isolation(),
isInvalidate(),
timeout,
- waitTimeout,
mappedKeys.size(),
inTx() ? tx.size() : mappedKeys.size(),
inTx() && tx.syncMode() == FULL_SYNC,
@@ -1250,9 +1252,24 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
final Collection<KeyCacheObject> mappedKeys = map.distributedKeys();
final ClusterNode node = map.node();
+ long remainingWaitTimeout = waitTimeout;
+
+ if (waitTimeout > 0) {
+ long now = U.currentTimeMillis();
+
+ if (lockWaitStartTime == 0)
+ lockWaitStartTime = now;
+
+ long elapsed = now - lockWaitStartTime;
+
+ remainingWaitTimeout = elapsed < waitTimeout ? waitTimeout -
elapsed : -1;
+ }
+
if (node.isLocal())
- lockLocally(mappedKeys, req.topologyVersion());
+ lockLocally(mappedKeys, req.topologyVersion(),
remainingWaitTimeout);
else {
+ req.waitTimeout(remainingWaitTimeout);
+
final MiniFuture fut = new MiniFuture(node, mappedKeys, ++miniId);
req.miniId(fut.futureId());
@@ -1280,10 +1297,12 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
* Locks given keys directly through dht cache.
* @param keys Collection of keys.
* @param topVer Topology version to lock on.
+ * @param remainingWaitTimeout Remaining lock wait budget for this batch.
*/
private void lockLocally(
final Collection<KeyCacheObject> keys,
- AffinityTopologyVersion topVer
+ AffinityTopologyVersion topVer,
+ long remainingWaitTimeout
) {
if (log.isDebugEnabled())
log.debug("Before locally locking keys : " + keys);
@@ -1297,7 +1316,7 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
read,
retval,
timeout,
- waitTimeout,
+ remainingWaitTimeout,
createTtl,
accessTtl,
skipStore,
@@ -1418,7 +1437,7 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
tx.addKeyMapping(cctx.txKey(key), cctx.localNode());
}
- lockLocally(distributedKeys, topVer);
+ lockLocally(distributedKeys, topVer, waitTimeout);
}
GridDhtPartitionsExchangeFuture lastFinishedFut =
cctx.shared().exchange().lastFinishedFuture();
@@ -1525,13 +1544,6 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
return false;
}
- /**
- * @return Timeout value for this lock future.
- */
- private long lockTimeout() {
- return CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout) ?
waitTimeout : timeout;
- }
-
/**
* Lock request timeout object.
*/
@@ -1540,7 +1552,7 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
* Default constructor.
*/
LockTimeoutObject() {
- super(lockTimeout());
+ super(timeout);
}
/** Requested keys. */
@@ -1551,20 +1563,6 @@ public final class GridDhtColocatedLockFuture extends
GridCacheCompoundIdentityF
if (log.isDebugEnabled())
log.debug("Timed out waiting for lock response: " + this);
- if (CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout)) {
- synchronized (GridDhtColocatedLockFuture.this) {
- requestedKeys = requestedKeys0();
-
- clear(); // Stop response processing.
- }
-
- synchronized (this) {
- onComplete(false, true, false);
- }
-
- return;
- }
-
if (inTx()) {
if (cctx.tm().deadlockDetectionEnabled()) {
synchronized (GridDhtColocatedLockFuture.this) {
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
index c5eb21e6b31..73e780ed6a9 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
@@ -137,6 +137,9 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
/** Lock wait timeout. */
private final long waitTimeout;
+ /** Time when the first primary batch starts, or zero before mapping. */
+ private long lockWaitStartTime;
+
/** Transaction. */
@GridToStringExclude
private final GridNearTxLocal tx;
@@ -356,7 +359,7 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
threadId,
lockVer,
topVer,
- lockTimeout(),
+ timeout,
!inTx(),
inTx(),
implicitSingleTx(),
@@ -371,16 +374,11 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
entries.add(entry);
- if (c == null && lockTimeout() < 0) {
+ if (c == null && timeout < 0) {
if (log.isDebugEnabled())
log.debug("Failed to acquire lock with negative timeout: " +
entry);
- if (CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout)) {
- onComplete(false, true, false);
- }
- else {
- onFailed();
- }
+ onFailed();
return null;
}
@@ -817,7 +815,7 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
if (isDone()) // Possible due to async rollback.
return;
- if (lockTimeout() > 0) {
+ if (timeout > 0) {
timeoutObj = new LockTimeoutObject();
cctx.time().addTimeoutObject(timeoutObj);
@@ -1088,7 +1086,6 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
isolation(),
isInvalidate(),
timeout,
- waitTimeout,
mappedKeys.size(),
inTx() ? tx.size() :
mappedKeys.size(),
inTx() && tx.syncMode() ==
FULL_SYNC,
@@ -1206,6 +1203,21 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
final Collection<KeyCacheObject> mappedKeys = map.distributedKeys();
final ClusterNode node = map.node();
+ long remainingWaitTimeout = waitTimeout;
+
+ if (waitTimeout > 0) {
+ long now = U.currentTimeMillis();
+
+ if (lockWaitStartTime == 0)
+ lockWaitStartTime = now;
+
+ long elapsed = now - lockWaitStartTime;
+
+ remainingWaitTimeout = elapsed < waitTimeout ? waitTimeout -
elapsed : -1;
+ }
+
+ req.waitTimeout(remainingWaitTimeout);
+
if (node.isLocal()) {
req.miniId(-1);
@@ -1420,13 +1432,6 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
return topEx;
}
- /**
- * @return Timeout value for this lock future.
- */
- private long lockTimeout() {
- return CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout) ?
waitTimeout : timeout;
- }
-
/**
* Lock request timeout object.
*/
@@ -1435,7 +1440,7 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
* Default constructor.
*/
LockTimeoutObject() {
- super(lockTimeout());
+ super(timeout);
}
/** Requested keys. */
@@ -1448,20 +1453,6 @@ public final class GridNearLockFuture extends
GridCacheCompoundIdentityFuture<Bo
timedOut = true;
- if (CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout)) {
- synchronized (GridNearLockFuture.this) {
- requestedKeys = requestedKeys0();
-
- clear(); // Stop response processing.
- }
-
- synchronized (this) {
- onComplete(false, true, false);
- }
-
- return;
- }
-
txLockTimedOut = true;
if (inTx()) {
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
index 46fae249ebd..401c014cf26 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
@@ -103,7 +103,6 @@ public class GridNearLockRequest extends
GridDistributedLockRequest {
* @param isolation Transaction isolation.
* @param isInvalidate Invalidation flag.
* @param timeout Transaction timeout.
- * @param waitTimeout Lock wait timeout.
* @param keyCnt Number of keys.
* @param txSize Expected transaction size.
* @param syncCommit Synchronous commit flag.
@@ -128,7 +127,6 @@ public class GridNearLockRequest extends
GridDistributedLockRequest {
TransactionIsolation isolation,
boolean isInvalidate,
long timeout,
- long waitTimeout,
int keyCnt,
int txSize,
boolean syncCommit,
@@ -168,7 +166,6 @@ public class GridNearLockRequest extends
GridDistributedLockRequest {
this.taskNameHash = taskNameHash;
this.createTtl = createTtl;
this.accessTtl = accessTtl;
- this.waitTimeout = waitTimeout;
this.txLbl = txLbl;
@@ -221,6 +218,13 @@ public class GridNearLockRequest extends
GridDistributedLockRequest {
return waitTimeout;
}
+ /**
+ * @param timeout Remaining lock wait budget for this primary batch.
+ */
+ public void waitTimeout(long timeout) {
+ waitTimeout = timeout;
+ }
+
/**
* @return Topology version.
*/
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 36630c33fb4..9a99fe2ec3f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -647,7 +647,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter
implements GridTimeou
IgniteInternalFuture<Boolean> fut =
cacheCtx.cache().txLockAsync(enlisted,
timeout,
- timeout,
+ /*waitTimeout*/0,
this,
/*read*/entryProc != null, // Needed to force load from
store.
retval,
@@ -822,7 +822,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter
implements GridTimeou
IgniteInternalFuture<Boolean> fut =
cacheCtx.cache().txLockAsync(enlisted,
timeout,
- timeout,
+ /*waitTimeout*/0,
this,
/*read*/invokeVals != null, // Needed to force load from
store.
retval,
@@ -1725,7 +1725,7 @@ public class GridNearTxLocal extends
GridDhtTxLocalAdapter implements GridTimeou
IgniteInternalFuture<Boolean> fut =
cacheCtx.cache().txLockAsync(enlisted,
timeout,
- timeout,
+ /*waitTimeout*/0,
this,
false,
retval,
@@ -1918,7 +1918,7 @@ public class GridNearTxLocal extends
GridDhtTxLocalAdapter implements GridTimeou
IgniteInternalFuture<Boolean> fut =
cacheCtx.cache().txLockAsync(lockKeys,
timeout,
- timeout,
+ /*waitTimeout*/0,
this,
true,
true,
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLockWaitTimeoutTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLockWaitTimeoutTest.java
new file mode 100644
index 00000000000..c429817357c
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLockWaitTimeoutTest.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheEntry;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.TestRecordingCommunicationSpi;
+import
org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest;
+import
org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.internal.TestRecordingCommunicationSpi.spi;
+import static
org.apache.ignite.testframework.GridTestUtils.waitForNextClockTick;
+import static
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Tests primary-side lock wait deadlines independently of response delivery.
*/
+@RunWith(Parameterized.class)
+public class CacheLockWaitTimeoutTest extends GridCommonAbstractTest {
+ /** Lock wait budget, shorter than the transaction timeout. */
+ private static final long WAIT_TIMEOUT = 500;
+
+ /** Whether the initiating client uses a near cache. */
+ @Parameterized.Parameter
+ public boolean near;
+
+ /** @return Cache configurations. */
+ @Parameterized.Parameters(name = "near={0}")
+ public static Collection<Boolean> parameters() {
+ return List.of(false, true);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String name)
throws Exception {
+ return super.getConfiguration(name).setCommunicationSpi(new
TestRecordingCommunicationSpi());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(2);
+ startClientGrid(2);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ grid(0).createCache(new CacheConfiguration<Integer,
Integer>(DEFAULT_CACHE_NAME)
+ .setAtomicityMode(TRANSACTIONAL)
+ .setBackups(1)
+ .setWriteSynchronizationMode(FULL_SYNC));
+
+ if (near)
+ grid(2).createNearCache(DEFAULT_CACHE_NAME, new
NearCacheConfiguration<>());
+ else
+ grid(2).cache(DEFAULT_CACHE_NAME);
+
+ awaitPartitionMapExchange();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ TestRecordingCommunicationSpi.stopBlockAll();
+ grid(0).destroyCache(DEFAULT_CACHE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /** A successful primary response remains valid after the coordinator's
lock wait budget expires. */
+ @Test
+ public void testDelayedSuccessfulResponse() throws Exception {
+ IgniteCache<Integer, Integer> cache =
grid(2).cache(DEFAULT_CACHE_NAME);
+ int key = primaryKey(grid(0).cache(DEFAULT_CACHE_NAME));
+
+ cache.put(key, 0);
+
+ CacheEntry<Integer, Integer> entry = cache.getEntry(key);
+
+ spi(grid(0)).blockMessages(GridNearLockResponse.class, grid(2).name());
+
+ IgniteInternalFuture<Boolean> fut = lockAsync(cache, List.of(entry));
+
+ try {
+ assertTrue(spi(grid(0)).waitForBlocked(1, 10_000));
+ assertFalse(fut.isDone());
+ }
+ finally {
+ spi(grid(0)).stopBlock();
+ }
+
+ assertTrue(fut.get(10_000));
+ }
+
+ /** Later primary batches must not receive a fresh lock wait budget. */
+ @Test
+ public void testWaitBudgetIsSharedByPrimaryBatches() throws Exception {
+ IgniteCache<Integer, Integer> cache =
grid(2).cache(DEFAULT_CACHE_NAME);
+ IgniteCache<Integer, Integer> holderCache =
grid(1).cache(DEFAULT_CACHE_NAME);
+ int first = primaryKey(grid(0).cache(DEFAULT_CACHE_NAME));
+ int second = primaryKey(holderCache);
+
+ cache.put(first, 0);
+ cache.put(second, 0);
+
+ List<CacheEntry<Integer, Integer>> entries =
List.of(cache.getEntry(first), cache.getEntry(second));
+
+ try (Transaction holder = grid(1).transactions().txStart(PESSIMISTIC,
READ_COMMITTED)) {
+ holderCache.put(second, 1);
+
+ spi(grid(2)).record(GridNearLockRequest.class);
+ spi(grid(0)).blockMessages(GridNearLockResponse.class,
grid(2).name());
+
+ IgniteInternalFuture<Boolean> fut = lockAsync(cache, entries);
+
+ try {
+ assertTrue(spi(grid(0)).waitForBlocked(1, 10_000));
+
+ // Send the second batch on a later clock tick so that its
remaining wait budget is smaller.
+ waitForNextClockTick();
+
+ assertFalse(fut.isDone());
+ }
+ finally {
+ spi(grid(0)).stopBlock();
+ }
+
+ assertFalse(fut.get(10_000));
+
+ List<Object> requests = spi(grid(2)).recordedMessages(true);
+
+ assertEquals(2, requests.size());
+
+ long firstWaitTimeout =
((GridNearLockRequest)requests.get(0)).waitTimeout();
+ long secondWaitTimeout =
((GridNearLockRequest)requests.get(1)).waitTimeout();
+
+ assertTrue(firstWaitTimeout > 0);
+ assertTrue("The next primary must receive a smaller lock wait
budget [first=" + firstWaitTimeout +
+ ", second=" + secondWaitTimeout + ']',
+ secondWaitTimeout < firstWaitTimeout);
+ }
+ }
+
+ /**
+ * @param cache Client cache.
+ * @param entries Entries to lock, in primary mapping order.
+ * @return Lock result after transaction cleanup.
+ */
+ @SuppressWarnings("unchecked")
+ private IgniteInternalFuture<Boolean> lockAsync(
+ IgniteCache<Integer, Integer> cache,
+ List<CacheEntry<Integer, Integer>> entries
+ ) {
+ return GridTestUtils.runAsync(() -> {
+ try (Transaction tx = grid(2).transactions().txStart(PESSIMISTIC,
READ_COMMITTED, 30_000, 0)) {
+ return
cache.unwrap(IgniteCacheProxy.class).internalProxy().lockTxEntries(entries,
WAIT_TIMEOUT);
+ }
+ });
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
index 695c3b42fa3..f1668a08597 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
@@ -124,6 +124,7 @@ import static
org.apache.ignite.testframework.GridTestUtils.assertNotContains;
import static
org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause;
import static org.apache.ignite.testframework.GridTestUtils.cartesianProduct;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+import static
org.apache.ignite.testframework.GridTestUtils.waitForNextClockTick;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
@@ -746,7 +747,7 @@ public class IgniteClusterSnapshotCheckTest extends
AbstractSnapshotSelfTest {
long blockedMills = U.currentTimeMillis();
- assertTrue(waitForCondition(() -> U.currentTimeMillis() >
blockedMills, getTestTimeout()));
+ waitForNextClockTick();
for (int i = 0; i < G.allGrids().size(); ++i) {
if (stoppedNodes0.contains(i))
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryConcurrentUpdatesAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryConcurrentUpdatesAbstractTest.java
index 87a51d85cfc..42fe5e4dd18 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryConcurrentUpdatesAbstractTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryConcurrentUpdatesAbstractTest.java
@@ -25,11 +25,12 @@ import javax.cache.expiry.Duration;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.query.ScanQuery;
-import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;
+import static
org.apache.ignite.testframework.GridTestUtils.waitForNextClockTick;
+
/**
* A base for tests that check the behaviour of scan queries run on a data set
that is modified concurrently.
* Actual tests should implement a way of cache creation, modification and
destruction.
@@ -110,8 +111,9 @@ public abstract class
ScanQueryConcurrentUpdatesAbstractTest extends GridCommonA
* Tests behaviour of scan queries with entries expired and modified
concurrently.
*
* @param cache Cache to test.
+ * @throws Exception If failed.
*/
- private void testExpiringDataset(IgniteCache<Integer, Integer> cache) {
+ private void testExpiringDataset(IgniteCache<Integer, Integer> cache)
throws Exception {
int iterations = 100;
int recordsNum = 100;
@@ -119,8 +121,6 @@ public abstract class
ScanQueryConcurrentUpdatesAbstractTest extends GridCommonA
for (int i = 0; i < iterations; i++) {
updateCache(cache, recordsNum);
- long updateTime = U.currentTimeMillis();
-
List<Cache.Entry<Integer, Integer>> res = cache.query(new
ScanQuery<Integer, Integer>()).getAll();
assertTrue("Query result set is too big: " + res.size(),
res.size() <= recordsNum);
@@ -128,8 +128,7 @@ public abstract class
ScanQueryConcurrentUpdatesAbstractTest extends GridCommonA
for (Cache.Entry<Integer, Integer> e : res)
assertEquals(e.getKey(), e.getValue());
- while (U.currentTimeMillis() == updateTime)
- doSleep(10L);
+ waitForNextClockTick();
}
}
finally {
@@ -195,14 +194,14 @@ public abstract class
ScanQueryConcurrentUpdatesAbstractTest extends GridCommonA
/** */
@Test
- public void testPartitionedShortExpiry() {
+ public void testPartitionedShortExpiry() throws Exception {
testExpiringDataset(createCache("partitioned_short_expiry",
CacheMode.PARTITIONED, new Duration(TimeUnit.MILLISECONDS, 1)));
}
/** */
@Test
- public void testReplicatedShortExpiry() {
+ public void testReplicatedShortExpiry() throws Exception {
testExpiringDataset(createCache("partitioned_short_expiry",
CacheMode.REPLICATED, new Duration(TimeUnit.MILLISECONDS, 1)));
}
diff --git
a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 3b428455a09..8e0ea33a396 100644
---
a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -1986,6 +1986,17 @@ public final class GridTestUtils {
return i + 1;
}
+ /**
+ * Waits until the cached Ignite clock advances beyond its current value.
+ *
+ * @throws IgniteInterruptedCheckedException If interrupted.
+ */
+ public static void waitForNextClockTick() throws
IgniteInterruptedCheckedException {
+ long now = U.currentTimeMillis();
+
+ assertTrue("Ignite clock did not advance", waitForCondition(() ->
U.currentTimeMillis() > now, 1_000, 1));
+ }
+
/**
* Waits for condition, polling in busy wait loop.
*
diff --git
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
index 5cd49400af7..e5a4c644758 100644
---
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
+++
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java
@@ -27,6 +27,7 @@ import
org.apache.ignite.internal.processors.cache.CacheConnectionLeakStoreTxTes
import
org.apache.ignite.internal.processors.cache.CacheGetEntryOptimisticSerializableSelfTest;
import
org.apache.ignite.internal.processors.cache.CacheGetEntryPessimisticReadCommittedSelfTest;
import
org.apache.ignite.internal.processors.cache.CacheGetEntryPessimisticSerializableSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheLockWaitTimeoutTest;
import
org.apache.ignite.internal.processors.cache.CacheOffheapMapEntrySelfTest;
import
org.apache.ignite.internal.processors.cache.CacheOperationContextTransactionalLockTest;
import
org.apache.ignite.internal.processors.cache.CacheReadThroughReplicatedAtomicRestartSelfTest;
@@ -165,6 +166,8 @@ public class IgniteCacheTestSuite4 {
GridTestUtils.addTestIfNeeded(suite,
CacheReadThroughReplicatedAtomicRestartSelfTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite,
CacheVersionedEntryPartitionedAtomicSelfTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite,
CacheVersionedEntryReplicatedTransactionalSelfTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite, CacheLockWaitTimeoutTest.class,
ignoredTests);
+
GridTestUtils.addTestIfNeeded(suite,
CacheVersionedEntryTransactionalLockTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, LockTxEntryOneNodeTest.class,
ignoredTests);
GridTestUtils.addTestIfNeeded(suite,
CacheOperationContextTransactionalLockTest.class, ignoredTests);