use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.
the class CacheMvccTransactionsTest method testGetVersionRequestFailover.
/**
* @throws Exception If failed.
*/
@Test
public void testGetVersionRequestFailover() throws Exception {
final int NODES = 5;
testSpi = true;
startGridsMultiThreaded(NODES - 1);
client = true;
Ignite client = startGrid(NODES - 1);
final List<String> cacheNames = new ArrayList<>();
final Map<Integer, Integer> vals = new HashMap<>();
for (int i = 0; i < 100; i++) vals.put(i, i);
for (CacheConfiguration ccfg : cacheConfigurations()) {
ccfg.setName("cache-" + cacheNames.size());
ccfg.setNodeFilter(new TestCacheNodeExcludingFilter(getTestIgniteInstanceName(0)));
cacheNames.add(ccfg.getName());
IgniteCache cache = client.createCache(ccfg);
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
writeAllByMode(cache, vals, PUT, INTEGER_CODEC);
tx.commit();
}
}
final AtomicInteger nodeIdx = new AtomicInteger(1);
final AtomicBoolean done = new AtomicBoolean();
try {
IgniteInternalFuture getFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite node = ignite(nodeIdx.getAndIncrement());
int cnt = 0;
while (!done.get()) {
for (String cacheName : cacheNames) {
// TODO IGNITE-6754 add SQL and SCAN support.
Map<Integer, Integer> res = readAllByMode(node.cache(cacheName), vals.keySet(), GET, INTEGER_CODEC);
assertEquals(vals, res);
}
cnt++;
}
log.info("Finished [node=" + node.name() + ", cnt=" + cnt + ']');
return null;
}
}, NODES - 1, "get-thread");
doSleep(1000);
TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(ignite(0));
crdSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof MvccSnapshotResponse;
}
});
crdSpi.waitForBlocked();
stopGrid(0);
doSleep(1000);
done.set(true);
getFut.get();
} finally {
done.set(true);
}
}
use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse in project ignite by apache.
the class CacheMvccTransactionsTest method cleanupWaitsForGet3.
/**
* @param updates Number of updates.
* @throws Exception If failed.
*/
private void cleanupWaitsForGet3(int updates) throws Exception {
/*
Simulate case when coordinator assigned query version has active transaction,
query is delayed, after this active transaction finish and the same key is
updated several more times before query starts.
*/
testSpi = true;
client = false;
startGrids(1);
client = true;
final Ignite client = startGrid(1);
awaitPartitionMapExchange();
final IgniteCache<Object, Object> cache = client.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, 16));
final Integer key1 = 1;
final Integer key2 = 2;
for (int i = 0; i < updates; i++) {
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(key1, i);
cache.put(key2, i);
tx.commit();
}
}
TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(grid(0));
TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(client);
clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
/**
*/
private boolean blocked;
@Override
public boolean apply(ClusterNode node, Message msg) {
if (!blocked && (msg instanceof MvccAckRequestTx)) {
blocked = true;
return true;
}
return false;
}
});
final IgniteInternalFuture<?> putFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(key2, 3);
tx.commit();
}
return null;
}
}, "put");
clientSpi.waitForBlocked();
for (int i = 0; i < updates; i++) {
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(key1, i + 3);
tx.commit();
}
}
// Delay version for getAll.
crdSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
/**
*/
private boolean blocked;
@Override
public boolean apply(ClusterNode node, Message msg) {
if (!blocked && (msg instanceof MvccSnapshotResponse)) {
blocked = true;
return true;
}
return false;
}
});
final IgniteInternalFuture<?> getFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
final Map<Object, Object> res1 = checkAndGetAll(false, cache, F.asSet(key1, key2), SCAN);
final Map<Object, Object> res2 = checkAndGetAll(false, cache, F.asSet(key1, key2), GET);
assertEquals(2, res1.size());
assertEquals(2, res2.size());
return null;
}
}, "get");
crdSpi.waitForBlocked();
clientSpi.stopBlock(true);
putFut.get();
for (int i = 0; i < updates; i++) {
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(key2, i + 4);
tx.commit();
}
}
crdSpi.stopBlock(true);
getFut.get();
}
Aggregations