@Override public Void call() throws Exception { Ignite node = ignite(COORD_NODES); List<IgniteCache> caches = new ArrayList<>(); for (String cacheName : cacheNames) caches.add(node.cache(cacheName)); Integer val = 1; while (!done.get()) { Map<Integer, Integer> vals = new LinkedHashMap<>(); for (int i = 0; i < KEYS; i++) vals.put(i, val); for (IgniteCache cache : caches) { try { try (Transaction tx = node.transactions().txStart(concurrency, isolation)) { tx.timeout(TX_TIMEOUT); writeAllByMode(cache, vals, writeMode, INTEGER_CODEC); tx.commit(); } } catch (Exception e) { handleTxException(e); } } val++; } return null; } }, "putAll-thread");
/** {@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); }
/** * Gets DB transaction isolation level based on ongoing cache transaction isolation. * * @return DB transaction isolation. */ private TransactionDefinition definition(Transaction tx, String cacheName) { assert tx != null; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']'); def.setIsolationLevel(isolationLevel(tx.isolation())); long timeoutSec = (tx.timeout() + 500) / 1000; if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE) def.setTimeout((int)timeoutSec); return def; }
@Override public void write(BinaryRawWriterEx writer, Transaction tx) { writer.writeLong(registerTx(tx)); writer.writeInt(tx.concurrency().ordinal()); writer.writeInt(tx.isolation().ordinal()); writer.writeLong(tx.timeout()); } });
tx.timeout(1); tx.setRollbackOnly(); tx.commit(); tx.commitAsync(); tx.suspend(); tx.resume(); tx.rollback(); tx.rollbackAsync().get();
@Override public Object call() throws Exception { Thread.currentThread().setName("put-thread"); try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { for (Map.Entry<Integer, Integer> e : map.entrySet()) cache.put(e.getKey(), e.getValue()); tx.commit(); } return null; } });
/** * @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); }
tx.commit(); break; tx.commitAsync().get(); break; tx.rollback(); break; tx.rollbackAsync().get(); break;
if (tx.timeout() < 200) tx.setRollbackOnly(); cache.put(1, 1); tx.commit(); cache.put(1, 2); tx.commit(); cache.put(1, 3); tx.commit();
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (TransactionIsolation tx1Isolation : TransactionIsolation.values()) { for (TransactionIsolation tx2Isolation : TransactionIsolation.values()) { Transaction tx1 = ignite.transactions().txStart(OPTIMISTIC, tx1Isolation); cache.put(1, 1); tx1.suspend(); assertFalse(cache.containsKey(1)); Transaction tx2 = ignite.transactions().txStart(OPTIMISTIC, tx2Isolation); cache.put(1, 2); tx2.commit(); assertEquals(2, (int)cache.get(1)); tx1.resume(); assertEquals(1, (int)cache.get(1)); tx1.close(); cache.removeAll(); } } } });
@Override public void run() { doSleep(delay); tx.rollback(); } }, 1, "tx-rollback-thread");
/** * */ @Test public void testLabelFilledLocalGuarantee() throws Exception { Ignite ignite = startGrid(0); ignite.events().localListen((IgnitePredicate<Event>)e -> { assert e instanceof TransactionStateChangedEvent; TransactionStateChangedEvent evt = (TransactionStateChangedEvent)e; Transaction tx = evt.tx(); if (tx.label() == null) tx.setRollbackOnly(); return true; }, EVT_TX_STARTED); IgniteCache cache = ignite.getOrCreateCache(defaultCacheConfiguration()); try (Transaction tx = ignite.transactions().withLabel("test").txStart()) { cache.put(1, 1); tx.commit(); } try (Transaction tx = ignite.transactions().txStart()) { cache.put(1, 2); tx.commit(); fail("Should fail prior this line."); } catch (CacheException ignored) { // No-op. } }
txA.commitAsync(); cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(keys.get(1))); txB.commit();