use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method singleKeyCommit.
/**
* @param client Node executing cache operation.
* @param ccfg Cache configuration.
* @param c Cache update closure.
* @throws Exception If failed.
*/
private void singleKeyCommit(Ignite client, final CacheConfiguration<Object, Object> ccfg, IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
Ignite ignite = ignite(0);
assertNotSame(ignite, client);
TestRecordingCommunicationSpi commSpiClient = (TestRecordingCommunicationSpi) client.configuration().getCommunicationSpi();
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
final Integer key = primaryKey(cache);
cache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
commSpiClient.record(GridNearTxFinishRequest.class);
commSpi0.record(GridDhtTxFinishRequest.class);
commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtTxFinishRequest;
}
});
c.apply(key, clientCache);
assertEquals(key, cache.localPeek(key));
U.sleep(50);
boolean nearCache = ((IgniteCacheProxy) clientCache).context().isNear();
for (int i = 1; i < NODES; i++) {
Ignite node = ignite(i);
if (nearCache && node == client && !node.affinity(ccfg.getName()).isPrimaryOrBackup(node.cluster().localNode(), key))
assertEquals("Invalid value for node: " + i, key, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
else
assertNull("Invalid value for node: " + i, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
}
commSpi0.stopBlock(true);
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
List<Object> msgs = commSpiClient.recordedMessages(true);
assertEquals(1, msgs.size());
GridNearTxFinishRequest req = (GridNearTxFinishRequest) msgs.get(0);
assertEquals(PRIMARY_SYNC, req.syncMode());
msgs = commSpi0.recordedMessages(true);
assertEquals(ccfg.getBackups(), msgs.size());
clientCache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
c.apply(key, clientCache);
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest in project ignite by apache.
the class TxRecoveryWithConcurrentRollbackTest method doTestRecoveryNotBreakingTxAtomicityOnNearAndPrimaryFail.
/**
* Stop near and primary node after primary tx is rolled back with enabled persistence.
* <p>
* Expected result: after restarting a primary node all partitions are consistent.
*/
private void doTestRecoveryNotBreakingTxAtomicityOnNearAndPrimaryFail(CacheWriteSynchronizationMode syncMode) throws Exception {
backups = 2;
persistence = true;
this.syncMode = syncMode;
final IgniteEx node0 = startGrids(3);
node0.cluster().state(ACTIVE);
final Ignite client = startGrid("client");
final IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
final Integer pk = primaryKey(grid(1).cache(DEFAULT_CACHE_NAME));
IgniteInternalFuture<Void> fut = null;
List<IgniteInternalTx> tx0 = null;
List<IgniteInternalTx> tx2 = null;
try (final Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
cache.put(pk, Boolean.TRUE);
TransactionProxyImpl p = (TransactionProxyImpl) tx;
p.tx().prepare(true);
tx0 = txs(grid(0));
tx2 = txs(grid(2));
spi(grid(1)).blockMessages((node, msg) -> msg instanceof GridDhtTxFinishRequest);
fut = runAsync(() -> {
spi(grid(1)).waitForBlocked(2);
client.close();
grid(1).close();
return null;
});
tx.rollback();
} catch (Exception e) {
// No-op.
}
fut.get();
final IgniteInternalTx tx_0 = tx0.get(0);
tx_0.finishFuture().get();
final IgniteInternalTx tx_2 = tx2.get(0);
tx_2.finishFuture().get();
assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
startGrid(1);
awaitPartitionMapExchange();
assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
}
Aggregations