/** {@inheritDoc} */ @Override protected void operation(int key) throws Exception { cache.put(key, key); } }
/** {@inheritDoc} */ @Override public boolean put(Object key, Object val) throws IgniteCheckedException { return delegate.get().put(keyTransformer.transform(key), val); }
/** {@inheritDoc} */ @Override public boolean put(K key, V val) throws IgniteCheckedException { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.put(key, val); } finally { gate.leave(prev); } }
/** * Stores the given block in data cache. * * @param blockSize The size of the block. * @param key The data cache key of the block. * @param data The new value of the block. * @throws IgniteCheckedException If failed. */ private void putBlock(int blockSize, IgfsBlockKey key, byte[] data) throws IgniteCheckedException { if (data.length < blockSize) // partial (incomplete) block: dataCachePrj.invoke(key, new IgfsDataPutProcessor(data)); else { // whole block: assert data.length == blockSize; dataCachePrj.put(key, data); } }
@Override public Void call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheAtomicReferenceValue<T> ref = cacheView.get(key); if (ref == null) throw new IgniteException("Failed to find atomic reference with given name: " + name); cacheView.put(key, new GridCacheAtomicReferenceValue<>(val)); tx.commit(); } return null; } });
@Override public Void call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheAtomicStampedValue<T, S> ref = cacheView.get(key); if (ref == null) throw new IgniteException("Failed to find atomic stamped with given name: " + name); cacheView.put(key, new GridCacheAtomicStampedValue<>(val, stamp)); tx.commit(); } return null; } });
/** {@inheritDoc} */ @Override public void put(K key, V val) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) setFuture(putAsync0(key, val)); else delegate.put(key, val); } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
@Override public T call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheAtomicReferenceValue<T> ref = cacheView.get(key); if (ref == null) throw new IgniteException("Failed to find atomic reference with given name: " + name); T curVal = ref.get(); if (!F.eq(expVal, curVal)) return curVal; else { cacheView.put(key, new GridCacheAtomicReferenceValue<>(newVal)); tx.commit(); return expVal; } } } });
@Override public Boolean call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheAtomicReferenceValue<T> ref = cacheView.get(key); if (ref == null) throw new IgniteException("Failed to find atomic reference with given name: " + name); T curVal = ref.get(); if (!F.eq(expVal, curVal)) return false; else { cacheView.put(key, new GridCacheAtomicReferenceValue<>(newVal)); tx.commit(); return true; } } } });
/** * Fill cache. * * @throws IgniteCheckedException if failed. */ private static Set<Integer> populateCache(IgniteEx ignite, boolean loc, int cnt, IgnitePredicate<Integer> expectedEntryFilter) throws IgniteCheckedException { IgniteInternalCache<Integer, Person> cache = ignite.cachex(PERSON_CACHE); assertNotNull(cache); Random rand = new Random(); HashSet<Integer> exp = new HashSet<>(); Affinity<Integer> aff = cache.affinity(); ClusterNode localNode = cache.context().localNode(); for (int i = 0; i < cnt; i++) { int val = rand.nextInt(cnt); cache.put(val, new Person(String.valueOf(val), val)); if (expectedEntryFilter.apply(val) && (!loc || aff.isPrimary(localNode, val))) exp.add(val); } return exp; }
@Override public Boolean call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheAtomicStampedValue<T, S> val = cacheView.get(key); if (val == null) throw new IgniteException("Failed to find atomic stamped with given name: " + name); if (F.eq(expVal, val.value()) && F.eq(expStamp, val.stamp())) { cacheView.put(key, new GridCacheAtomicStampedValue<>(newVal, newStamp)); tx.commit(); return true; } return false; } } });
/** {@inheritDoc} */ @Override public Integer call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheCountDownLatchValue latchVal = cacheView.get(key); if (latchVal == null) { if (log.isDebugEnabled()) log.debug("Failed to find count down latch with given name: " + name); return 0; } int retVal; if (val > 0) { retVal = latchVal.get() - val; if (retVal < 0) retVal = 0; } else retVal = 0; latchVal.set(retVal); cacheView.put(key, latchVal); tx.commit(); return retVal; } } }
cacheView.put(key, val);
cache.put(key, ret.get2());
/** * Success if explicit tx doesn't fail. * * @param cache Cache instance. * @throws Exception If failed. */ protected void checkStartTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception { try (final GridNearTxLocal tx = CU.txStartInternal(cache.context(), cache, PESSIMISTIC, REPEATABLE_READ)) { assert tx != null; sleepForTxFailure(); cache.put("key", "val"); tx.commit(); } assert cache.containsKey("key"); cache.clear(); }
cache.put(1, 1);
/** * @throws Exception If failed. */ @Test public void testGridNearTxLocalDuplicateAsyncCommit() throws Exception { IgniteKernal ignite = (IgniteKernal)grid(0); IgniteInternalCache<Object, Object> utilityCache = ignite.context().cache().utilityCache(); try (GridNearTxLocal itx = MvccFeatureChecker.forcedMvcc() ? utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ) : utilityCache.txStartEx(OPTIMISTIC, SERIALIZABLE)) { utilityCache.put("1", "1"); itx.commitNearTxLocalAsync(); itx.commitNearTxLocalAsync().get(); } }
sysCache.put(key, new GridServiceAssignments(svcCfg, nodeId, ignite.cluster().topologyVersion()));
/** * Test node invalidation when cache meta is corrupted. */ @Test public void testCacheMetaCorruption() throws Exception { IgniteEx ignite = startGrid(0); ignite.cluster().active(true); IgniteInternalCache cache = ignite.cachex(CACHE_NAME1); cache.put(1, 1); int partId = cache.affinity().partition(1); int grpId = cache.context().group().groupId(); corruptTreeRoot(ignite, (PageMemoryEx)cache.context().dataRegion().pageMemory(), grpId, partId); ignite.cluster().active(false); stopGrid(0); try { startGrid(0); ignite.cluster().active(true); cache.put(1, 1); } catch (Exception e) { // No-op. } waitFailure(StorageException.class); }
/** * @throws Exception If failed. */ @Test public void testNodeStopWhileThereAreCacheActivitiesInServiceProcessor() throws Exception { Assume.assumeTrue(!isEventDrivenServiceProcessorEnabled()); final int nodesCnt = 2; final int maxSvc = 1024; startGridsMultiThreaded(nodesCnt); IgniteEx ignite = grid(0); IgniteInternalCache<GridServiceAssignmentsKey, Object> sysCache = ignite.utilityCache(); // Adding some assignments without deployments. for (int i = 0; i < maxSvc; i++) { String name = "svc-" + i; ServiceConfiguration svcCfg = new ServiceConfiguration(); svcCfg.setName(name); GridServiceAssignmentsKey key = new GridServiceAssignmentsKey(name); UUID nodeId = grid(i % nodesCnt).localNode().id(); sysCache.put(key, new GridServiceAssignments(svcCfg, nodeId, ignite.cluster().topologyVersion())); } // Simulate exchange with merge. GridTestUtils.runAsync(() -> startGrid(nodesCnt)); GridTestUtils.runAsync(() -> startGrid(nodesCnt + 1)); startGrid(nodesCnt + 2); Thread.sleep((int)(1000 * ThreadLocalRandom.current().nextDouble())); stopAllGrids(); }