Search in sources :

Example 1 with CLIENT

use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT in project ignite by apache.

the class CacheMvccTxRecoveryTest method testUpdateCountersGapIsClosed.

/**
 * @throws Exception if failed.
 */
@Test
public void testUpdateCountersGapIsClosed() throws Exception {
    int srvCnt = 3;
    startGridsMultiThreaded(srvCnt);
    client = true;
    IgniteEx ign = startGrid(srvCnt);
    IgniteCache<Object, Object> cache = ign.getOrCreateCache(basicCcfg().setBackups(2));
    int vid = 1;
    IgniteEx victim = grid(vid);
    ArrayList<Integer> keys = new ArrayList<>();
    Integer part = null;
    Affinity<Object> aff = ign.affinity(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 2000; i++) {
        int p = aff.partition(i);
        if (aff.isPrimary(victim.localNode(), i)) {
            if (part == null)
                part = p;
            if (p == part)
                keys.add(i);
            if (keys.size() == 2)
                break;
        }
    }
    assert keys.size() == 2;
    Transaction txA = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
    // prevent first transaction prepare on backups
    ((TestRecordingCommunicationSpi) victim.configuration().getCommunicationSpi()).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        final AtomicInteger limiter = new AtomicInteger();

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtTxPrepareRequest)
                return limiter.getAndIncrement() < 2;
            return false;
        }
    });
    cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(keys.get(0)));
    txA.commitAsync();
    GridCacheVersion aXidVer = ((TransactionProxyImpl) txA).tx().xidVersion();
    assertConditionEventually(() -> txsOnNode(victim, aXidVer).stream().anyMatch(tx -> tx.state() == PREPARING));
    GridTestUtils.runAsync(() -> {
        try (Transaction txB = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(keys.get(1)));
            txB.commit();
        }
    }).get();
    long victimUpdCntr = updateCounter(victim.cachex(DEFAULT_CACHE_NAME).context(), keys.get(0));
    List<IgniteEx> backupNodes = grids(srvCnt, i -> i != vid);
    List<IgniteInternalTx> backupTxsA = backupNodes.stream().map(node -> txsOnNode(node, aXidVer)).flatMap(Collection::stream).collect(Collectors.toList());
    // drop primary
    victim.close();
    assertConditionEventually(() -> backupTxsA.stream().allMatch(tx -> tx.state() == ROLLED_BACK));
    backupNodes.stream().map(node -> node.cache(DEFAULT_CACHE_NAME)).forEach(c -> {
        assertEquals(1, c.query(new SqlFieldsQuery("select * from Integer")).getAll().size());
    });
    backupNodes.forEach(node -> {
        for (Integer k : keys) assertEquals(victimUpdCntr, updateCounter(node.cachex(DEFAULT_CACHE_NAME).context(), k));
    });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IntPredicate(java.util.function.IntPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) ROLLBAK(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.ROLLBAK) Collection(java.util.Collection) CLIENT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Optional(java.util.Optional) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IntStream(java.util.stream.IntStream) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) Affinity(org.apache.ignite.cache.affinity.Affinity) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) StreamSupport(java.util.stream.StreamSupport) SERVER(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.SERVER) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) G(org.apache.ignite.internal.util.typedef.G) PREPARED(org.apache.ignite.transactions.TransactionState.PREPARED) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) COMMITTED(org.apache.ignite.transactions.TransactionState.COMMITTED) PREPARING(org.apache.ignite.transactions.TransactionState.PREPARING) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) COMMIT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.COMMIT) TimeUnit(java.util.concurrent.TimeUnit) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheMode(org.apache.ignite.cache.CacheMode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) ArrayList(java.util.ArrayList) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) Test(org.junit.Test)

Example 2 with CLIENT

use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT in project ignite by apache.

the class CacheMvccTxRecoveryTest method checkRecoveryPrimaryFailure.

/**
 */
private void checkRecoveryPrimaryFailure(TxEndResult endRes, boolean mvccCrd) throws Exception {
    int gridCnt = 4;
    int baseCnt = gridCnt - 1;
    boolean commit = endRes == COMMIT;
    startGridsMultiThreaded(baseCnt);
    client = true;
    IgniteEx nearNode = startGrid(baseCnt);
    IgniteCache<Object, Object> cache = nearNode.getOrCreateCache(basicCcfg().setBackups(1));
    Affinity<Object> aff = nearNode.affinity(DEFAULT_CACHE_NAME);
    List<Integer> keys = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        if (aff.isPrimary(grid(0).localNode(), i) && aff.isBackup(grid(1).localNode(), i)) {
            keys.add(i);
            break;
        }
    }
    for (int i = 0; i < 100; i++) {
        if (aff.isPrimary(grid(1).localNode(), i) && aff.isBackup(grid(2).localNode(), i)) {
            keys.add(i);
            break;
        }
    }
    assert keys.size() == 2;
    int victim, victimBackup;
    if (mvccCrd) {
        victim = 0;
        victimBackup = 1;
    } else {
        victim = 1;
        victimBackup = 2;
    }
    TestRecordingCommunicationSpi victimComm = (TestRecordingCommunicationSpi) grid(victim).configuration().getCommunicationSpi();
    if (commit)
        victimComm.blockMessages(GridNearTxFinishResponse.class, nearNode.name());
    else
        victimComm.blockMessages(GridDhtTxPrepareRequest.class, grid(victimBackup).name());
    GridNearTxLocal nearTx = ((TransactionProxyImpl) nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
    for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k));
    List<IgniteInternalTx> txs = IntStream.range(0, baseCnt).filter(i -> i != victim).mapToObj(i -> txsOnNode(grid(i), nearTx.xidVersion())).flatMap(Collection::stream).collect(Collectors.toList());
    IgniteInternalFuture<IgniteInternalTx> commitFut = nearTx.commitAsync();
    if (commit)
        assertConditionEventually(() -> txs.stream().allMatch(tx -> tx.state() == COMMITTED));
    else
        assertConditionEventually(() -> txs.stream().anyMatch(tx -> tx.state() == PREPARED));
    // drop victim
    grid(victim).close();
    awaitPartitionMapExchange();
    assertConditionEventually(() -> txs.stream().allMatch(tx -> tx.state() == (commit ? COMMITTED : ROLLED_BACK)));
    assert victimComm.hasBlockedMessages();
    if (commit) {
        assertConditionEventually(() -> {
            int rowsCnt = G.allGrids().get(0).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size();
            return rowsCnt == keys.size();
        });
    } else {
        int rowsCnt = G.allGrids().get(0).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size();
        assertEquals(0, rowsCnt);
    }
    assertTrue(commitFut.isDone());
    assertPartitionCountersAreConsistent(keys, grids(baseCnt, i -> i != victim));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IntPredicate(java.util.function.IntPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) ROLLBAK(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.ROLLBAK) Collection(java.util.Collection) CLIENT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Optional(java.util.Optional) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IntStream(java.util.stream.IntStream) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) Affinity(org.apache.ignite.cache.affinity.Affinity) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) StreamSupport(java.util.stream.StreamSupport) SERVER(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.SERVER) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) G(org.apache.ignite.internal.util.typedef.G) PREPARED(org.apache.ignite.transactions.TransactionState.PREPARED) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) COMMITTED(org.apache.ignite.transactions.TransactionState.COMMITTED) PREPARING(org.apache.ignite.transactions.TransactionState.PREPARING) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) COMMIT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.COMMIT) TimeUnit(java.util.concurrent.TimeUnit) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheMode(org.apache.ignite.cache.CacheMode) ArrayList(java.util.ArrayList) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Example 3 with CLIENT

use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT in project ignite by apache.

the class CacheMvccTxRecoveryTest method checkRecoveryNearFailure.

/**
 */
private void checkRecoveryNearFailure(TxEndResult endRes, NodeMode nearNodeMode) throws Exception {
    int gridCnt = 4;
    int baseCnt = gridCnt - 1;
    boolean commit = endRes == COMMIT;
    startGridsMultiThreaded(baseCnt);
    // tweak client/server near
    client = nearNodeMode == CLIENT;
    IgniteEx nearNode = startGrid(baseCnt);
    IgniteCache<Object, Object> cache = nearNode.getOrCreateCache(basicCcfg().setBackups(1));
    Affinity<Object> aff = nearNode.affinity(DEFAULT_CACHE_NAME);
    List<Integer> keys = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        if (aff.isPrimary(grid(0).localNode(), i) && aff.isBackup(grid(1).localNode(), i)) {
            keys.add(i);
            break;
        }
    }
    for (int i = 0; i < 100; i++) {
        if (aff.isPrimary(grid(1).localNode(), i) && aff.isBackup(grid(2).localNode(), i)) {
            keys.add(i);
            break;
        }
    }
    assert keys.size() == 2;
    TestRecordingCommunicationSpi nearComm = (TestRecordingCommunicationSpi) nearNode.configuration().getCommunicationSpi();
    if (!commit)
        nearComm.blockMessages(GridNearTxPrepareRequest.class, grid(1).name());
    GridTestUtils.runAsync(() -> {
        // run in separate thread to exclude tx from thread-local map
        GridNearTxLocal nearTx = ((TransactionProxyImpl) nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
        for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k));
        List<IgniteInternalTx> txs = IntStream.range(0, baseCnt).mapToObj(i -> txsOnNode(grid(i), nearTx.xidVersion())).flatMap(Collection::stream).collect(Collectors.toList());
        IgniteInternalFuture<?> prepareFut = nearTx.prepareNearTxLocal();
        if (commit)
            prepareFut.get();
        else
            assertConditionEventually(() -> txs.stream().anyMatch(tx -> tx.state() == PREPARED));
        // drop near
        nearNode.close();
        assertConditionEventually(() -> txs.stream().allMatch(tx -> tx.state() == (commit ? COMMITTED : ROLLED_BACK)));
        return null;
    }).get();
    if (commit) {
        assertConditionEventually(() -> {
            int rowsCnt = grid(0).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size();
            return rowsCnt == keys.size();
        });
    } else {
        int rowsCnt = G.allGrids().get(0).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size();
        assertEquals(0, rowsCnt);
    }
    assertPartitionCountersAreConsistent(keys, grids(baseCnt, i -> true));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IntPredicate(java.util.function.IntPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) ROLLBAK(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.ROLLBAK) Collection(java.util.Collection) CLIENT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Optional(java.util.Optional) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IntStream(java.util.stream.IntStream) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) Affinity(org.apache.ignite.cache.affinity.Affinity) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) StreamSupport(java.util.stream.StreamSupport) SERVER(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.SERVER) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) G(org.apache.ignite.internal.util.typedef.G) PREPARED(org.apache.ignite.transactions.TransactionState.PREPARED) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) COMMITTED(org.apache.ignite.transactions.TransactionState.COMMITTED) PREPARING(org.apache.ignite.transactions.TransactionState.PREPARING) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) COMMIT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.COMMIT) TimeUnit(java.util.concurrent.TimeUnit) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheMode(org.apache.ignite.cache.CacheMode) ArrayList(java.util.ArrayList) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Collection(java.util.Collection) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with CLIENT

use of org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT in project ignite by apache.

the class CacheMvccTxRecoveryTest method testCountersNeighborcastServerFailed.

/**
 * @throws Exception if failed.
 */
@Test
public void testCountersNeighborcastServerFailed() throws Exception {
    // Reopen https://issues.apache.org/jira/browse/IGNITE-10766 if starts failing
    int srvCnt = 4;
    startGridsMultiThreaded(srvCnt);
    client = true;
    IgniteEx ign = startGrid(srvCnt);
    IgniteCache<Object, Object> cache = ign.getOrCreateCache(basicCcfg().setBackups(2));
    ArrayList<Integer> keys = new ArrayList<>();
    int vid = 3;
    IgniteEx victim = grid(vid);
    Affinity<Object> aff = ign.affinity(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 100; i++) {
        if (aff.isPrimary(victim.localNode(), i) && !aff.isBackup(grid(0).localNode(), i)) {
            keys.add(i);
            break;
        }
    }
    for (int i = 0; i < 100; i++) {
        if (aff.isPrimary(victim.localNode(), i) && !aff.isBackup(grid(1).localNode(), i)) {
            keys.add(i);
            break;
        }
    }
    assert keys.size() == 2 && !keys.contains(99);
    // prevent prepare on one backup
    ((TestRecordingCommunicationSpi) victim.configuration().getCommunicationSpi()).blockMessages(GridDhtTxPrepareRequest.class, grid(0).name());
    GridNearTxLocal nearTx = ((TransactionProxyImpl) ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
    for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k));
    List<IgniteInternalTx> txs = IntStream.range(0, srvCnt).mapToObj(this::grid).filter(g -> g != victim).map(g -> txsOnNode(g, nearTx.xidVersion())).flatMap(Collection::stream).collect(Collectors.toList());
    nearTx.commitAsync();
    // await tx partially prepared
    assertConditionEventually(() -> txs.stream().anyMatch(tx -> tx.state() == PREPARED));
    CountDownLatch latch1 = new CountDownLatch(1);
    CountDownLatch latch2 = new CountDownLatch(1);
    IgniteInternalFuture<Object> backgroundTxFut = GridTestUtils.runAsync(() -> {
        try (Transaction ignored = ign.transactions().txStart()) {
            boolean upd = false;
            for (int i = 100; i < 200; i++) {
                if (!aff.isPrimary(victim.localNode(), i)) {
                    cache.put(i, 11);
                    upd = true;
                    break;
                }
            }
            assert upd;
            latch1.countDown();
            latch2.await(getTestTimeout(), TimeUnit.MILLISECONDS);
        }
        return null;
    });
    latch1.await(getTestTimeout(), TimeUnit.MILLISECONDS);
    // drop primary
    victim.close();
    // do all assertions before rebalance
    assertConditionEventually(() -> txs.stream().allMatch(tx -> tx.state() == ROLLED_BACK));
    List<IgniteEx> liveNodes = grids(srvCnt, i -> i != vid);
    assertPartitionCountersAreConsistent(keys, liveNodes);
    latch2.countDown();
    backgroundTxFut.get(getTestTimeout());
    assertTrue(liveNodes.stream().map(node -> node.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll()).allMatch(Collection::isEmpty));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IntPredicate(java.util.function.IntPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) ROLLBAK(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.ROLLBAK) Collection(java.util.Collection) CLIENT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.CLIENT) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Optional(java.util.Optional) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IntStream(java.util.stream.IntStream) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) Affinity(org.apache.ignite.cache.affinity.Affinity) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) StreamSupport(java.util.stream.StreamSupport) SERVER(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.NodeMode.SERVER) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) G(org.apache.ignite.internal.util.typedef.G) PREPARED(org.apache.ignite.transactions.TransactionState.PREPARED) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) COMMITTED(org.apache.ignite.transactions.TransactionState.COMMITTED) PREPARING(org.apache.ignite.transactions.TransactionState.PREPARING) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) COMMIT(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxRecoveryTest.TxEndResult.COMMIT) TimeUnit(java.util.concurrent.TimeUnit) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheMode(org.apache.ignite.cache.CacheMode) ArrayList(java.util.ArrayList) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) CountDownLatch(java.util.concurrent.CountDownLatch) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 Optional (java.util.Optional)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 TimeUnit (java.util.concurrent.TimeUnit)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IntPredicate (java.util.function.IntPredicate)4 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 StreamSupport (java.util.stream.StreamSupport)4 Ignite (org.apache.ignite.Ignite)4 IgniteCache (org.apache.ignite.IgniteCache)4 TRANSACTIONAL (org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL)4 TRANSACTIONAL_SNAPSHOT (org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)4 CacheMode (org.apache.ignite.cache.CacheMode)4 PARTITIONED (org.apache.ignite.cache.CacheMode.PARTITIONED)4 Affinity (org.apache.ignite.cache.affinity.Affinity)4 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4