/** {@inheritDoc} */ @Override public GridCacheContext<K, V> context() { return delegate.context(); }
/** * Safely get CacheGateway. * * @return Cache Gateway. */ @Nullable private GridCacheGateway<K, V> gate() { GridCacheContext<K, V> cacheContext = delegate.context(); return cacheContext != null ? cacheContext.gate() : null; }
/** * @param cache Cache. * @throws IgniteCheckedException If cache without near cache was already started. */ private void checkNearCacheStarted(IgniteCacheProxy<?, ?> cache) throws IgniteCheckedException { if (!cache.context().isNear()) throw new IgniteCheckedException("Failed to start near cache " + "(a cache with the same name without near cache is already started)"); }
/** */ private void pringStatistics(IgniteCacheProxy cache, String msg) { System.out.println(msg + " {{"); cache.context().printMemoryStats(); System.out.println("}} " + msg); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public Collection<GridCacheSqlMetadata> call() throws Exception { IgniteCache cache = ignite.cache(cacheName); return ((IgniteCacheProxy)cache).context().queries().sqlMetadataV2(); } }
/** * @return Cache context. */ protected GridCacheContext cacheContext() { return ((IgniteCacheProxy)grid(0).cache(DEFAULT_CACHE_NAME)).context(); }
/** * @param cache Cache. */ private static boolean storeValue(IgniteCache cache) { return ((IgniteCacheProxy)cache).context().cacheObjectContext().storeValue(); }
/** * @param c Cache. * @param client If it must be a client cache. */ private void assertClient(IgniteCache<?,?> c, boolean client) { assertTrue(((IgniteCacheProxy)c).context().affinityNode() == !client); }
/** {@inheritDoc} */ @Override public GatewayProtectedCacheProxy<K, V> withExpiryPolicy(ExpiryPolicy plc) { CacheOperationGate opGate = onEnter(); try { MvccUtils.verifyMvccOperationSupport(delegate.context(), "withExpiryPolicy"); return new GatewayProtectedCacheProxy<>(delegate, opCtx.withExpiryPolicy(plc), lock); } finally { onLeave(opGate); } }
/** * @param cache Cache. */ private static boolean storeValue(IgniteCache cache) { return ((IgniteCacheProxy)cache).context().cacheObjectContext().storeValue(); }
/** {@inheritDoc} */ @Override protected Map<String, VisorCacheConfiguration> run(VisorCacheConfigurationCollectorTaskArg arg) { Collection<IgniteCacheProxy<?, ?>> caches = ignite.context().cache().jcaches(); Pattern ptrn = arg.getRegex() != null ? Pattern.compile(arg.getRegex()) : null; boolean all = F.isEmpty(arg.getCacheNames()); boolean hasPtrn = ptrn != null; Map<String, VisorCacheConfiguration> res = U.newHashMap(caches.size()); for (IgniteCacheProxy<?, ?> cache : caches) { String cacheName = cache.getName(); boolean matched = hasPtrn ? ptrn.matcher(cacheName).find() : all || arg.getCacheNames().contains(cacheName); if (!VisorTaskUtils.isRestartingCache(ignite, cacheName) && matched) { VisorCacheConfiguration cfg = config(cache.getConfiguration(CacheConfiguration.class), cache.context().dynamicDeploymentId()); res.put(cacheName, cfg); } } return res; }
/** * @param cacheName Cache name to close. * @return Future that will be completed when cache is closed. */ IgniteInternalFuture<?> dynamicCloseCache(String cacheName) { assert cacheName != null; IgniteCacheProxy<?, ?> proxy = jcacheProxy(cacheName, false); if (proxy == null || proxy.isProxyClosed()) return new GridFinishedFuture<>(); // No-op. checkEmptyTransactions(); if (proxy.context().isLocal()) return dynamicDestroyCache(cacheName, false, true, false, null); return startClientCacheChange(null, Collections.singleton(cacheName)); }
/** * @param ignite Ignite. * @return Cache. */ protected IgniteCacheProxy<Integer, Integer> fillCache(Ignite ignite) { IgniteCacheProxy<Integer, Integer> cache = (IgniteCacheProxy<Integer, Integer>)ignite.<Integer, Integer>cache(DEFAULT_CACHE_NAME); for (int i = 0; i < KEYS_CNT; i++) { cache.put(i, i); int part = cache.context().affinity().partition(i); Map<Integer, Integer> partEntries = entries.get(part); if (partEntries == null) entries.put(part, partEntries = new HashMap<>()); partEntries.put(i, i); } return cache; }
/** * @param cache Cache. * @param plcName Policy name. */ private void verifyCacheMemoryPolicy(IgniteCache cache, String plcName) { GridCacheContext ctx = ((IgniteCacheProxy) cache).context(); assertEquals(plcName, ctx.dataRegion().config().getName()); }
/** * @param cache Cache. * @param key Key. * @return Collection of versioned rows. * @throws IgniteCheckedException if failed. */ private List<CacheDataRow> allKeyVersions(IgniteCache cache, Object key) throws IgniteCheckedException { IgniteCacheProxy cache0 = (IgniteCacheProxy)cache; GridCacheContext cctx = cache0.context(); KeyCacheObject key0 = cctx.toCacheKeyObject(key); GridCursor<CacheDataRow> cur = cctx.offheap().mvccAllVersionsCursor(cctx, key0, null); List<CacheDataRow> rows = new ArrayList<>(); while (cur.next()) { CacheDataRow row = cur.get(); rows.add(row); } return rows; }
/** * @param ignite Ignite. * @return Local partitions. */ private Set<Integer> localPartitions(Ignite ignite) { GridCacheContext cctx = ((IgniteCacheProxy)ignite.cache(DEFAULT_CACHE_NAME)).context(); Collection<GridDhtLocalPartition> owningParts = F.view(cctx.topology().localPartitions(), new IgnitePredicate<GridDhtLocalPartition>() { @Override public boolean apply(GridDhtLocalPartition part) { return part.state() == GridDhtPartitionState.OWNING; } }); return new HashSet<>(F.transform(owningParts, new IgniteClosure<GridDhtLocalPartition, Integer>() { @Override public Integer apply(GridDhtLocalPartition part) { return part.id(); } })); }
/** * Checks update counter value on all nodes. * * @param cacheName Cache name. * @param p Part number. * @param val Expected partition counter value. */ private void checkUpdateCounters(String cacheName, int p, long val) { for (Ignite node : G.allGrids()) { if (!node.configuration().isClientMode()) { IgniteCacheProxy cache = (IgniteCacheProxy)node.cache(cacheName); GridDhtLocalPartition part = cache.context().topology().localPartition(p); if (!cache.context().mvccEnabled() || part == null) continue; assertEquals("part=" + p, val, part.updateCounter()); } } } }
/** * @param obj Object. * @param cache Cache. */ private static Object getValue(CacheObject obj, IgniteCache cache) { if (obj instanceof BinaryObject) return ((BinaryObject)obj).field("val"); else { if (storeValue(cache)) return ((TestValue)U.field(obj, "val")).val(); else return CU.<TestValue>value(obj, ((IgniteCacheProxy)cache).context(), false).val(); } }
/** */ private void checkAllVersionsHints(IgniteCache cache) throws IgniteCheckedException { IgniteCacheProxy cache0 = (IgniteCacheProxy)cache; GridCacheContext cctx = cache0.context(); assert cctx.mvccEnabled(); for (Object e : cache) { IgniteBiTuple entry = (IgniteBiTuple)e; KeyCacheObject key = cctx.toCacheKeyObject(entry.getKey()); GridCursor<CacheDataRow> cur = cctx.offheap().mvccAllVersionsCursor(cctx, key, CacheDataRowAdapter.RowData.LINK_WITH_HEADER); while (cur.next()) { CacheDataRow row = cur.get(); assertTrue(row.mvccTxState() != 0); } } }
/** * @param cache Cache. * @param key Key. * @param expVal Expected value. */ private static void assertBinaryEnum(IgniteCache<Object, Object> cache, int key, TestEnum expVal) { Marshaller marsh = ((IgniteCacheProxy)cache).context().marshaller(); if (marsh instanceof BinaryMarshaller) { BinaryObject enumObj = (BinaryObject)cache.withKeepBinary().get(key); assertEquals(expVal.ordinal(), enumObj.enumOrdinal()); assertTrue(enumObj.type().isEnum()); assertTrue(enumObj instanceof BinaryEnumObjectImpl); } }