/** * @param cacheName Cache name. * @return Cache. */ @Nullable private <K, V> IgniteCache<K, V> getCache0(String cacheName) { if (cacheName == null) throw new NullPointerException(); try { return ignite.cache(cacheName); } catch (IllegalArgumentException ignored) { return null; } }
final IgniteCache<Object, Object> cache = g.cache(DEFAULT_CACHE_NAME);
@Override public Void call() throws Exception { IgniteKernal node = (IgniteKernal)ignite(0); IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME); while (!fut1.isDone()) { try { cacheOperations(node, cache); } catch (Exception ignore) { // No-op. } } return null; } }, 2, "tx-thread");
@Override public Void call() throws Exception { int idx = threadIdx.getAndIncrement(); IgniteKernal node = (IgniteKernal)ignite(idx % 3 + 1); IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME); while (true) { try { cacheOperations(node, cache); } catch (Exception ignored) { if (node.isStopping()) break; } } return null; } }, 20, "tx-node-stop-thread");
@Override public void run() { try { Lock lock = node.cache(DEFAULT_CACHE_NAME).lock(key); lock.lock(); try { info(">>> Acquired explicit lock for key: " + key); startLatch.await(); info(">>> Acquiring explicit lock for key: " + key * 10); Lock lock10 = node.cache(DEFAULT_CACHE_NAME).lock(key * 10); lock10.lock(); try { info(">>> Releasing locks [key1=" + key + ", key2=" + key * 10 + ']'); } finally { lock10.unlock(); } } finally { lock.unlock(); } } catch (CacheException e) { info(">>> Failed to perform lock [key=" + key + ", e=" + e + ']'); } catch (InterruptedException ignored) { info(">>> Interrupted while waiting for start latch."); Thread.currentThread().interrupt(); } } }, 1));
@Override public void run() { IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME); try { try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(key, key); commitLatch.await(); tx.commit(); } } catch (CacheException e) { info("Failed to run tx for key [key=" + key + ", e=" + e + ']'); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); info("Got interrupted while waiting for commit latch: " + key); } } }, 1));
@Override public void run() { IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME); try { try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(key, key); info(">>> Locked key, waiting for latch: " + key); commitLatch.await(); tx.commit(); } } catch (CacheException e) { info("Failed to run tx for key [key=" + key + ", e=" + e + ']'); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); info("Got interrupted while waiting for commit latch: " + key); } } }, 1));
@Override public Object call() throws Exception { IgniteCache<Object,Object> cache = g.cache(DEFAULT_CACHE_NAME). withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000))); long key = 0; while (!stop.get()) { cache.put(key, key); key++; } return null; } }, 1);
IgniteCache<Integer, String> cache = grid.cache(DEFAULT_CACHE_NAME);
assertEquals(NODES_CNT * 2, grid2.cluster().nodes().size()); IgniteCache<Integer, Integer> cache = grid2.cache(CACHE_NAME);
IgniteCache<String, String> cache = grid.cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Object> cache2 = grid2.cache(cacheName);
@Override public void applyx() { // Check that no more entries left in the map. assertNull(g.cache(DEFAULT_CACHE_NAME).get(key)); if (!g.internalCache(DEFAULT_CACHE_NAME).context().deferredDelete()) assertNull(g.internalCache(DEFAULT_CACHE_NAME).map().getEntry(g.internalCache(DEFAULT_CACHE_NAME).context(), g.internalCache(DEFAULT_CACHE_NAME).context().toCacheKeyObject(key))); } });
final int expVal = i; assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
/** * @throws Exception If failed. */ @Test public void testTxFinishPartitions() throws Exception { String key = "key"; String val = "value"; IgniteCache<String, String> cache = grid.cache(DEFAULT_CACHE_NAME); int keyPart = grid.<String, String>internalCache(DEFAULT_CACHE_NAME).context().affinity().partition(key); cache.put(key, val); // Wait for tx-enlisted partition. long waitTime = runTransactions(key, keyPart, F.asList(keyPart)); info("Wait time, ms: " + waitTime); // Wait for not enlisted partition. waitTime = runTransactions(key, keyPart, F.asList(keyPart + 1)); info("Wait time, ms: " + waitTime); // Wait for both partitions. waitTime = runTransactions(key, keyPart, F.asList(keyPart, keyPart + 1)); info("Wait time, ms: " + waitTime); }
IgniteCache<Object, Object> cache0 = g.cache(DEFAULT_CACHE_NAME);
/** * @throws Exception If failed. */ @Test public void testSystemTxInsideUserTx() throws Exception { Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10473", MvccFeatureChecker.forcedMvcc()); IgniteKernal ignite = (IgniteKernal)grid(0); IgniteCache<Object, Object> jcache = ignite.cache(DEFAULT_CACHE_NAME); try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { jcache.get("1"); jcache.put("1", "11"); IgniteInternalCache<Object, Object> utilityCache = ignite.context().cache().utilityCache(); utilityCache.getAndPutIfAbsent("2", "2"); try (GridNearTxLocal itx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { assertEquals(null, utilityCache.get("1")); assertEquals("2", utilityCache.get("2")); assertEquals(null, utilityCache.get("3")); utilityCache.getAndPut("3", "3"); itx.commit(); } jcache.put("2", "22"); tx.commit(); } checkTransactionsCommitted(); checkEntries(DEFAULT_CACHE_NAME, "1", "11", "2", "22", "3", null); checkEntries(CU.UTILITY_CACHE_NAME, "1", null, "2", "2", "3", "3"); }
final IgniteKernal kernal0 = (IgniteKernal)grid(g); assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));