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);
}
Aggregations