/** * @param tx Transaction. * @param syncMode Expected write synchronization mode. */ private void checkSyncMode(Transaction tx, CacheWriteSynchronizationMode syncMode) { assertEquals(syncMode, ((TransactionProxyImpl)tx).tx().syncMode()); }
/** */ private void checkScenario(IgniteEx ign, int srvCnt, ImmutableMap<UUID, Set<UUID>> txNodes, Runnable r) throws Exception { try (Transaction userTx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { r.run(); GridNearTxLocal nearTx = ((TransactionProxyImpl)userTx).tx(); nearTx.prepareNearTxLocal().get(); List<IgniteInternalTx> txs = IntStream.range(0, srvCnt) .mapToObj(i -> txsOnNode(grid(i), nearTx.nearXidVersion())) .flatMap(Collection::stream) .collect(Collectors.toList()); assertFalse(txs.isEmpty()); txs.forEach(tx -> assertEquals(txNodes, repack(tx.transactionNodes()))); } }
@Override public Object call() throws Exception { IgniteCache<Integer, String> cache = txIgniteNode.cache(DEFAULT_CACHE_NAME); assertNotNull(cache); TransactionProxyImpl tx = (TransactionProxyImpl)txIgniteNode.transactions().txStart(); GridNearTxLocal txEx = tx.tx(); assertTrue(txEx.optimistic()); cache.putAll(map); try { txEx.prepareNearTxLocal().get(3, TimeUnit.SECONDS); } catch (IgniteFutureTimeoutCheckedException ignored) { info("Failed to wait for prepare future completion: " + partial); } return null; } }).get();
@Override public void run() { IgniteCache<Object, Object> c = jcache(0); try { Transaction tx = grid(0).transactions().txStart(mode, REPEATABLE_READ); for (Integer key : keys) c.put(key, "val" + key); if (prepare) ((TransactionProxyImpl)tx).tx().prepare(true); } catch (IgniteCheckedException e) { info("Failed to put keys to cache: " + e.getMessage()); } } }, 1);
/** * Checks if transaction has given key enlisted. * * @param tx Transaction to check. * @param key Key to check. * @return {@code True} if key was enlisted. */ private boolean txContainsKey(Transaction tx, String key) { TransactionProxyImpl<String, Integer> proxy = (TransactionProxyImpl<String, Integer>)tx; IgniteInternalTx txEx = proxy.tx(); IgniteTxEntry entry = txEx.entry(context(0).txKey(context(0).toCacheKeyObject(key))); return entry != null; } }
involvedTxs.add(((TransactionProxyImpl)tx).tx());
/** */ 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; }); }
/** * @param tx Transaction. * @param commit Commit flag. */ protected void checkFastTxFinish(Transaction tx, boolean commit) { if (commit) tx.commit(); else tx.rollback(); IgniteInternalTx tx0 = ((TransactionProxyImpl)tx).tx(); assertNull(fieldValue(tx0, "prepFut")); assertTrue(fieldValue(tx0, "finishFut") instanceof GridNearTxFastFinishFuture); }
IgniteInternalTx tx0 = ((TransactionProxyImpl)tx).tx();
GridCacheVersion aXidVer = ((TransactionProxyImpl)txA).tx().xidVersion();
.blockMessages(GridDhtTxPrepareRequest.class, grid(0).name()); GridNearTxLocal nearTx = ((TransactionProxyImpl)ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
/** {@inheritDoc} */ @Override public long processInLongOutLong(int type, long val) throws IgniteCheckedException { switch (type) { case OP_PREPARE: ((TransactionProxyImpl)tx(val)).tx().prepare(true); return TRUE; case OP_COMMIT: tx(val).commit(); return txClose(val); case OP_ROLLBACK: tx(val).rollback(); return txClose(val); case OP_CLOSE: return txClose(val); case OP_SET_ROLLBACK_ONLY: return tx(val).setRollbackOnly() ? TRUE : FALSE; case OP_STATE: return tx(val).state().ordinal(); case OP_RESET_METRICS: txs.resetMetrics(); return TRUE; } return super.processInLongOutLong(type, val); }
/** * @param tx Transaction. * @param commit Commit flag. */ protected void checkNormalTxFinish(Transaction tx, boolean commit) { IgniteInternalTx tx0 = ((TransactionProxyImpl)tx).tx(); if (commit) { tx.commit(); assertNotNull(fieldValue(tx0, "prepFut")); assertNotNull(fieldValue(tx0, "finishFut")); } else { tx.rollback(); assertNull(fieldValue(tx0, "prepFut")); assertNotNull(fieldValue(tx0, "finishFut")); } }
= ((TransactionProxyImpl)nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
= ((TransactionProxyImpl)nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)).tx();
/** * @throws Exception if failed. */ @Test public void testRecoveryCommit() throws Exception { startGridsMultiThreaded(2); client = true; IgniteEx ign = startGrid(2); IgniteCache<Object, Object> cache = ign.getOrCreateCache(basicCcfg()); AtomicInteger keyCntr = new AtomicInteger(); ArrayList<Integer> keys = new ArrayList<>(); ign.cluster().forServers().nodes() .forEach(node -> keys.add(keyForNode(ign.affinity(DEFAULT_CACHE_NAME), keyCntr, node))); GridTestUtils.runAsync(() -> { // run in separate thread to exclude tx from thread-local map Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ); for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k)); ((TransactionProxyImpl)tx).tx().prepareNearTxLocal().get(); return null; }).get(); // drop near stopGrid(2, true); IgniteEx srvNode = grid(0); assertConditionEventually( () -> srvNode.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size() == 2 ); assertPartitionCountersAreConsistent(keys, G.allGrids()); }
GridNearTxLocal txEx = txProxy.tx();
clientTx = ((TransactionProxyImpl)tx).tx();
/** {@inheritDoc} */ @Override public long processInLongOutLong(int type, long val) throws IgniteCheckedException { switch (type) { case OP_PREPARE: ((TransactionProxyImpl)tx(val)).tx().prepare(true); return TRUE; case OP_COMMIT: tx(val).commit(); return txClose(val); case OP_ROLLBACK: tx(val).rollback(); return txClose(val); case OP_CLOSE: return txClose(val); case OP_SET_ROLLBACK_ONLY: return tx(val).setRollbackOnly() ? TRUE : FALSE; case OP_STATE: return tx(val).state().ordinal(); case OP_RESET_METRICS: txs.resetMetrics(); return TRUE; } return super.processInLongOutLong(type, val); }