Alexei Scherbakov created IGNITE-6405: -----------------------------------------
Summary: Deadlock is not detected if timed out on client. Key: IGNITE-6405 URL: https://issues.apache.org/jira/browse/IGNITE-6405 Project: Ignite Issue Type: Bug Affects Versions: 2.1 Reporter: Alexei Scherbakov Priority: Minor Fix For: 2.3 Timeout exception is thrown instead. Reproducer: {noformat} /* * 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.transactions; import java.util.Collections; import java.util.concurrent.CountDownLatch; import javax.cache.CacheException; import org.apache.ignite.Ignite; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.TransactionConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionDeadlockException; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; /** * Tests an ability to eagerly rollback timed out transactions. */ public class TxPessimisticDeadlockDetectionClient extends GridCommonAbstractTest { /** */ private static final long TX_MIN_TIMEOUT = 1; /** */ private static final long TX_TIMEOUT = 300; /** */ private static final long TX_DEFAULT_TIMEOUT = 3_000; /** */ private static final String CACHE_NAME = "test"; /** IP finder. */ private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); /** */ private static final int GRID_CNT = 3; /** */ private final CountDownLatch blocked = new CountDownLatch(1); /** */ private final CountDownLatch unblocked = new CountDownLatch(1); /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setClientMode("client".equals(igniteInstanceName)); ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); TransactionConfiguration txCfg = new TransactionConfiguration(); txCfg.setDefaultTxTimeout(TX_DEFAULT_TIMEOUT); cfg.setTransactionConfiguration(txCfg); CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME); ccfg.setAtomicityMode(TRANSACTIONAL); ccfg.setBackups(2); cfg.setCacheConfiguration(ccfg); return cfg; } /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); startGridsMultiThreaded(GRID_CNT); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { super.afterTest(); stopAllGrids(); } /** */ protected void validateException(Exception e) { assertEquals("Deadlock report is expected", TransactionDeadlockException.class, e.getCause().getCause().getClass()); } /** * Tests if deadlock is resolved on timeout with correct message. * * @throws Exception If failed. */ public void testDeadlockUnblockedOnTimeout() throws Exception { Ignite client = startGrid("client"); testDeadlockUnblockedOnTimeout0(client, ignite(0)); } /** * Tests if deadlock is resolved on timeout with correct message. * @throws Exception */ private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2) throws Exception { final CountDownLatch l = new CountDownLatch(2); IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() { @Override public void run() { try { try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) { node1.cache(CACHE_NAME).put(1, 1); l.countDown(); U.awaitQuiet(l); node1.cache(CACHE_NAME).putAll(Collections.singletonMap(2, 2)); tx.commit(); fail(); } } catch (CacheException e) { // No-op. validateException(e); } } }, 1, "First"); IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() { @Override public void run() { try (Transaction tx = node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) { node2.cache(CACHE_NAME).put(2, 2); l.countDown(); U.awaitQuiet(l); node2.cache(CACHE_NAME).put(1, 1); tx.commit(); } } }, 1, "Second"); fut1.get(); fut2.get(); assertTrue(node1.cache(CACHE_NAME).containsKey(1)); assertTrue(node1.cache(CACHE_NAME).containsKey(2)); } } {noformat} -- This message was sent by Atlassian JIRA (v6.4.14#64029)