Search in sources :

Example 1 with GridDhtTxQueryEnlistResponse

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistResponse in project ignite by apache.

the class CacheMvccBackupsAbstractTest method testBackupsCoherenceWithInFlightBatchesOverflow.

/**
 * Checks cache backups consistency with in-flight batches overflow.
 *
 * @throws Exception If failed.
 */
@Test
public void testBackupsCoherenceWithInFlightBatchesOverflow() throws Exception {
    testSpi = true;
    disableScheduledVacuum = true;
    ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 1, DFLT_PARTITION_COUNT).setIndexedTypes(Integer.class, Integer.class);
    final int KEYS_CNT = 30_000;
    assert KEYS_CNT % 2 == 0;
    startGrids(2);
    Ignite node1 = grid(0);
    Ignite node2 = grid(1);
    client = true;
    Ignite client = startGrid();
    awaitPartitionMapExchange();
    IgniteCache<?, ?> clientCache = client.cache(DEFAULT_CACHE_NAME);
    IgniteCache<?, ?> cache1 = node1.cache(DEFAULT_CACHE_NAME);
    IgniteCache<?, ?> cache2 = node2.cache(DEFAULT_CACHE_NAME);
    AtomicInteger keyGen = new AtomicInteger();
    Affinity affinity = affinity(clientCache);
    ClusterNode cNode1 = ((IgniteEx) node1).localNode();
    ClusterNode cNode2 = ((IgniteEx) node2).localNode();
    StringBuilder insert = new StringBuilder("INSERT INTO Integer (_key, _val) values ");
    for (int i = 0; i < KEYS_CNT; i++) {
        if (i > 0)
            insert.append(',');
        // To make big batches in near results future.
        Integer key = i < KEYS_CNT / 2 ? keyForNode(affinity, keyGen, cNode1) : keyForNode(affinity, keyGen, cNode2);
        assert key != null;
        insert.append('(').append(key).append(',').append(key * 10).append(')');
    }
    String qryStr = insert.toString();
    try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        tx.timeout(txLongTimeout);
        SqlFieldsQuery qry = new SqlFieldsQuery(qryStr);
        clientCache.query(qry).getAll();
        tx.commit();
    }
    // Add a delay to simulate batches overflow.
    TestRecordingCommunicationSpi spi1 = TestRecordingCommunicationSpi.spi(node1);
    TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(node2);
    spi1.closure(new IgniteBiInClosure<ClusterNode, Message>() {

        @Override
        public void apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtTxQueryEnlistResponse)
                doSleep(100);
        }
    });
    spi2.closure(new IgniteBiInClosure<ClusterNode, Message>() {

        @Override
        public void apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtTxQueryEnlistResponse)
                doSleep(100);
        }
    });
    qryStr = "DELETE FROM Integer WHERE _key >= " + 10;
    try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        tx.timeout(txLongTimeout);
        SqlFieldsQuery qry = new SqlFieldsQuery(qryStr);
        clientCache.query(qry).getAll();
        tx.commit();
    }
    Map<KeyCacheObject, List<CacheDataRow>> cache1Vers = allVersions(cache1);
    List res1 = getAll(cache1, "Integer");
    stopGrid(0);
    awaitPartitionMapExchange();
    Map<KeyCacheObject, List<CacheDataRow>> cache2Vers = allVersions(cache2);
    assertVersionsEquals(cache1Vers, cache2Vers);
    List res2 = getAll(cache2, "Integer");
    assertEqualsCollections(res1, res2);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtTxQueryEnlistResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistResponse) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) Affinity(org.apache.ignite.cache.affinity.Affinity) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ignite (org.apache.ignite.Ignite)1 Affinity (org.apache.ignite.cache.affinity.Affinity)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 GridDhtTxQueryEnlistResponse (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistResponse)1 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1 Transaction (org.apache.ignite.transactions.Transaction)1 Test (org.junit.Test)1