use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx in project ignite by apache.
the class MvccProcessorImpl method ackTxRollback.
/**
* {@inheritDoc}
*/
@Override
public void ackTxRollback(MvccVersion updateVer) {
assert updateVer != null;
MvccCoordinator crd = curCrd;
if (crd.disconnected() || crd.version() != updateVer.coordinatorVersion())
return;
MvccAckRequestTx msg = new MvccAckRequestTx((long) -1, updateVer.counter());
msg.skipResponse(true);
try {
sendMessage(crd.nodeId(), msg);
} catch (ClusterTopologyCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to send tx rollback ack, node left [msg=" + msg + ", node=" + crd.nodeId() + ']');
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send tx rollback ack [msg=" + msg + ", node=" + crd.nodeId() + ']', e);
}
}
use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx in project ignite by apache.
the class CacheMvccTransactionsTest method testWaitPreviousTxAck.
/**
* @throws Exception If failed.
*/
@Test
public void testWaitPreviousTxAck() throws Exception {
testSpi = true;
startGrid(0);
client = true;
final Ignite ignite = startGrid(1);
final IgniteCache<Object, Object> cache = ignite.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, 16));
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(1, 1);
cache.put(2, 1);
tx.commit();
}
TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(ignite);
clientSpi.blockMessages((node, msg) -> msg instanceof MvccAckRequestTx);
IgniteInternalFuture<?> txFut1 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(1, 2);
tx.commit();
}
return null;
}
});
IgniteInternalFuture<?> txFut2 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(2, 3);
tx.commit();
}
// Should see changes made by both tx1 and tx2.
Map<Object, Object> res = checkAndGetAll(false, cache, F.asSet(1, 2), SCAN, GET);
assertEquals(2, res.get(1));
assertEquals(3, res.get(2));
return null;
}
});
clientSpi.waitForBlocked(2);
Thread.sleep(1000);
clientSpi.stopBlock(true);
txFut1.get();
txFut2.get();
Map<Object, Object> res = checkAndGetAll(false, cache, F.asSet(1, 2), SCAN, GET);
assertEquals(2, res.get(1));
assertEquals(3, res.get(2));
}
use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx 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