use of org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl in project ignite by apache.
the class MvccDeadlockDetectionTest method blockProbe.
/**
*/
private static void blockProbe(IgniteEx ign, Transaction tx) {
((TestRecordingCommunicationSpi) ign.configuration().getCommunicationSpi()).blockMessages((node, msg) -> {
if (msg instanceof DeadlockProbe) {
DeadlockProbe msg0 = (DeadlockProbe) msg;
GridNearTxLocal tx0 = ((TransactionProxyImpl) tx).tx();
return msg0.initiatorVersion().equals(tx0.xidVersion());
}
return false;
});
}
use of org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl in project ignite by apache.
the class CacheMvccTxRecoveryTest method checkRecoveryNearFailure.
/**
*/
private void checkRecoveryNearFailure(TxEndResult endRes, NodeMode nearNodeMode) throws Exception {
int gridCnt = 4;
int baseCnt = gridCnt - 1;
boolean commit = endRes == COMMIT;
startGridsMultiThreaded(baseCnt);
// tweak client/server near
client = nearNodeMode == CLIENT;
IgniteEx nearNode = startGrid(baseCnt);
IgniteCache<Object, Object> cache = nearNode.getOrCreateCache(basicCcfg().setBackups(1));
Affinity<Object> aff = nearNode.affinity(DEFAULT_CACHE_NAME);
List<Integer> keys = new ArrayList<>();
for (int i = 0; i < 100; i++) {
if (aff.isPrimary(grid(0).localNode(), i) && aff.isBackup(grid(1).localNode(), i)) {
keys.add(i);
break;
}
}
for (int i = 0; i < 100; i++) {
if (aff.isPrimary(grid(1).localNode(), i) && aff.isBackup(grid(2).localNode(), i)) {
keys.add(i);
break;
}
}
assert keys.size() == 2;
TestRecordingCommunicationSpi nearComm = (TestRecordingCommunicationSpi) nearNode.configuration().getCommunicationSpi();
if (!commit)
nearComm.blockMessages(GridNearTxPrepareRequest.class, grid(1).name());
GridTestUtils.runAsync(() -> {
// run in separate thread to exclude tx from thread-local map
GridNearTxLocal nearTx = ((TransactionProxyImpl) nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k));
List<IgniteInternalTx> txs = IntStream.range(0, baseCnt).mapToObj(i -> txsOnNode(grid(i), nearTx.xidVersion())).flatMap(Collection::stream).collect(Collectors.toList());
IgniteInternalFuture<?> prepareFut = nearTx.prepareNearTxLocal();
if (commit)
prepareFut.get();
else
assertConditionEventually(() -> txs.stream().anyMatch(tx -> tx.state() == PREPARED));
// drop near
nearNode.close();
assertConditionEventually(() -> txs.stream().allMatch(tx -> tx.state() == (commit ? COMMITTED : ROLLED_BACK)));
return null;
}).get();
if (commit) {
assertConditionEventually(() -> {
int rowsCnt = grid(0).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size();
return rowsCnt == keys.size();
});
} else {
int rowsCnt = G.allGrids().get(0).cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size();
assertEquals(0, rowsCnt);
}
assertPartitionCountersAreConsistent(keys, grids(baseCnt, i -> true));
}
use of org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl in project ignite by apache.
the class CacheMvccTxRecoveryTest method testTxRecoveryWithLostFullMessageOnJoiningBackupNode.
/**
* @throws Exception if failed.
*/
@Test
public void testTxRecoveryWithLostFullMessageOnJoiningBackupNode() throws Exception {
CountDownLatch success = new CountDownLatch(1);
int joiningBackupNodeId = 2;
IgniteEx crd = startGrid(0);
IgniteEx partOwner = startGrid(1);
IgniteCache<Object, Object> cache = partOwner.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAtomicityMode(TRANSACTIONAL).setCacheMode(PARTITIONED).setIndexedTypes(Integer.class, Integer.class).setBackups(2));
// prevent FullMassage on joining backup node
((TestRecordingCommunicationSpi) crd.configuration().getCommunicationSpi()).blockMessages(GridDhtPartitionsFullMessage.class, getTestIgniteInstanceName(joiningBackupNodeId));
new Thread(() -> {
try {
startGrid(joiningBackupNodeId);
} catch (Exception e) {
e.printStackTrace();
}
success.countDown();
}).start();
assertTrue(GridTestUtils.waitForCondition(() -> crd.cluster().nodes().size() == 3, 10_000));
ArrayList<Integer> keys = new ArrayList<>();
Affinity<Object> aff = crd.affinity(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) {
if (aff.isPrimary(partOwner.localNode(), i)) {
keys.add(i);
break;
}
}
((TestRecordingCommunicationSpi) partOwner.configuration().getCommunicationSpi()).blockMessages(GridDhtTxPrepareRequest.class, getTestIgniteInstanceName(joiningBackupNodeId));
GridNearTxLocal nearTx = ((TransactionProxyImpl) partOwner.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
for (Integer k : keys) cache.put(k, k);
nearTx.commitAsync();
// Checks that PartitionCountersNeighborcastRequest will be sent after primary node left.
IgniteTxManager tm = crd.context().cache().context().tm();
assertTrue(GridTestUtils.waitForCondition(() -> !tm.activeTransactions().isEmpty(), 10_000));
assertTrue(GridTestUtils.waitForCondition(() -> tm.activeTransactions().iterator().next().state().equals(PREPARED), 10_000));
// Primary node left.
partOwner.close();
// Node with backup fetch lost FullMessage and starts.
((TestRecordingCommunicationSpi) crd.configuration().getCommunicationSpi()).stopBlock();
success.await();
awaitPartitionMapExchange();
assertEquals(2, crd.cluster().nodes().size());
}
use of org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl in project ignite by apache.
the class CacheMvccTxRecoveryTest method testCountersNeighborcastServerFailed.
/**
* @throws Exception if failed.
*/
@Test
public void testCountersNeighborcastServerFailed() throws Exception {
// Reopen https://issues.apache.org/jira/browse/IGNITE-10766 if starts failing
int srvCnt = 4;
startGridsMultiThreaded(srvCnt);
client = true;
IgniteEx ign = startGrid(srvCnt);
IgniteCache<Object, Object> cache = ign.getOrCreateCache(basicCcfg().setBackups(2));
ArrayList<Integer> keys = new ArrayList<>();
int vid = 3;
IgniteEx victim = grid(vid);
Affinity<Object> aff = ign.affinity(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) {
if (aff.isPrimary(victim.localNode(), i) && !aff.isBackup(grid(0).localNode(), i)) {
keys.add(i);
break;
}
}
for (int i = 0; i < 100; i++) {
if (aff.isPrimary(victim.localNode(), i) && !aff.isBackup(grid(1).localNode(), i)) {
keys.add(i);
break;
}
}
assert keys.size() == 2 && !keys.contains(99);
// prevent prepare on one backup
((TestRecordingCommunicationSpi) victim.configuration().getCommunicationSpi()).blockMessages(GridDhtTxPrepareRequest.class, grid(0).name());
GridNearTxLocal nearTx = ((TransactionProxyImpl) ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k));
List<IgniteInternalTx> txs = IntStream.range(0, srvCnt).mapToObj(this::grid).filter(g -> g != victim).map(g -> txsOnNode(g, nearTx.xidVersion())).flatMap(Collection::stream).collect(Collectors.toList());
nearTx.commitAsync();
// await tx partially prepared
assertConditionEventually(() -> txs.stream().anyMatch(tx -> tx.state() == PREPARED));
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
IgniteInternalFuture<Object> backgroundTxFut = GridTestUtils.runAsync(() -> {
try (Transaction ignored = ign.transactions().txStart()) {
boolean upd = false;
for (int i = 100; i < 200; i++) {
if (!aff.isPrimary(victim.localNode(), i)) {
cache.put(i, 11);
upd = true;
break;
}
}
assert upd;
latch1.countDown();
latch2.await(getTestTimeout(), TimeUnit.MILLISECONDS);
}
return null;
});
latch1.await(getTestTimeout(), TimeUnit.MILLISECONDS);
// drop primary
victim.close();
// do all assertions before rebalance
assertConditionEventually(() -> txs.stream().allMatch(tx -> tx.state() == ROLLED_BACK));
List<IgniteEx> liveNodes = grids(srvCnt, i -> i != vid);
assertPartitionCountersAreConsistent(keys, liveNodes);
latch2.countDown();
backgroundTxFut.get(getTestTimeout());
assertTrue(liveNodes.stream().map(node -> node.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll()).allMatch(Collection::isEmpty));
}
Aggregations