/** * Create data transfer object for given cache. * * @param ca Internal cache. * @param collectMetrics Collect cache metrics flag. * @throws IgniteCheckedException If failed to create data transfer object. */ public VisorCache(IgniteEx ignite, GridCacheAdapter ca, boolean collectMetrics) throws IgniteCheckedException { assert ca != null; GridCacheContext cctx = ca.context(); CacheConfiguration cfg = ca.configuration(); name = ca.name(); dynamicDeploymentId = cctx.dynamicDeploymentId(); mode = cfg.getCacheMode(); primarySize = ca.localSizeLong(PEEK_ONHEAP_PRIMARY); backupSize = ca.localSizeLong(PEEK_ONHEAP_BACKUP); nearSize = ca.nearSize(); size = primarySize + backupSize + nearSize; partitions = ca.affinity().partitions(); near = cctx.isNear(); if (collectMetrics) metrics = new VisorCacheMetrics(ignite, name); sys = ignite.context().cache().systemCache(name); statisticsEnabled = ca.clusterMetrics().isStatisticsEnabled(); }
/** {@inheritDoc} */ @Override public final V getAndPut(K key, V val) throws IgniteCheckedException { return getAndPut(key, val, null); }
/** {@inheritDoc} */ @Override public final boolean put(final K key, final V val) throws IgniteCheckedException { return put(key, val, null); }
/** * @param cache Cache. */ public void cache(GridCacheAdapter<K, V> cache) { this.cache = cache; deferredDel = cache.isDht() || cache.isDhtAtomic() || cache.isColocated() || (cache.isNear() && cache.configuration().getAtomicityMode() == ATOMIC); }
/** * @param keys Keys to clear. * @throws IgniteCheckedException In case of error. */ private void clear(@Nullable Set<? extends K> keys) throws IgniteCheckedException { //TODO IGNITE-7952 MvccUtils.verifyMvccOperationSupport(ctx, "Clear"); if (isLocal()) { if (keys == null) clearLocally(true, false, false); else clearLocallyAll(keys, true, false, false); } else { executeClearTask(keys, false).get(); executeClearTask(keys, true).get(); } }
/** * @return Cache object context. */ private CacheObjectContext objectContext() { if (ctx == null) return null; return ctx.cache().internalCache(cacheName).context().cacheObjectContext(); }
assertTrue(near.isNear()); GridCacheEntryEx nearEntry = near.peekEx(key); boolean expectDht = near.affinity().isPrimaryOrBackup(ignite.cluster().localNode(), key); CU.value(nearEntry.info().value(), near.context(), false)); ignite.cache(near.name()).localPeek(key, CachePeekMode.ONHEAP)); ignite.cache(near.name()).localPeek(key, CachePeekMode.ONHEAP)); assertNull("Unexpected peek value for grid: " + ignite.name(), ignite.cache(near.name()).localPeek(key, CachePeekMode.ONHEAP));
/** {@inheritDoc} */ @Override public IgnitePair<Long> call(Ignite ignite, IgniteCache<String, Integer> cache) throws Exception { GridCacheAdapter<?, ?> internalCache = internalCache0(cache); if (useDhtForNearCache && internalCache.context().isNear()) internalCache = internalCache.context().near().dht(); GridCacheEntryEx entry = internalCache.entryEx(key); entry.unswap(); IgnitePair<Long> pair = new IgnitePair<>(entry.ttl(), entry.expireTime()); if (!entry.isNear()) entry.context().cache().removeEntry(entry); return pair; } }
/** * @param ldr Class loader. * @param keys Keys. * @param cache Cache. */ private void addEntries(ClassLoader ldr, Collection<KeyCacheObject> keys, GridCacheAdapter cache) { GridCacheContext cacheCtx = cache.context(); for (GridCacheEntryEx e : (Iterable<GridCacheEntryEx>)cache.entries()) { boolean undeploy = cacheCtx.isNear() ? undeploy(ldr, e, cacheCtx.near()) || undeploy(ldr, e, cacheCtx.near().dht()) : undeploy(ldr, e, cacheCtx.cache()); if (undeploy) keys.add(e.key()); } }
@Override public boolean applyx() { try { if (c.get(key) != null) return false; // Get "cache" field from GridCacheProxyImpl. GridCacheAdapter c0 = cacheFromCtx(c); if (!c0.context().deferredDelete()) { GridCacheEntryEx e0 = c0.entryEx(key); return e0 == null || (e0.rawGet() == null && e0.valueBytes() == null); } else return true; } catch (GridCacheEntryRemovedException e) { throw new RuntimeException(e); } } }, Math.min(ttl * 10, getTestTimeout())));
/** * @param cache Cache. * @throws IgniteCheckedException If failed. */ private void onKernalStart(GridCacheAdapter<?, ?> cache) throws IgniteCheckedException { GridCacheContext<?, ?> ctx = cache.context(); // Start DHT cache as well. if (isNearEnabled(ctx)) { GridDhtCacheAdapter dht = ctx.near().dht(); GridCacheContext<?, ?> dhtCtx = dht.context(); for (GridCacheManager mgr : dhtManagers(dhtCtx)) mgr.onKernalStart(); dht.onKernalStart(); if (log.isDebugEnabled()) log.debug("Executed onKernalStart() callback for DHT cache: " + dht.name()); } for (GridCacheManager mgr : F.view(ctx.managers(), F0.notContains(dhtExcludes(ctx)))) mgr.onKernalStart(); cache.onKernalStart(); if (ctx.events().isRecordable(EventType.EVT_CACHE_STARTED)) ctx.events().addEvent(EventType.EVT_CACHE_STARTED); if (log.isDebugEnabled()) log.debug("Executed onKernalStart() callback for cache [name=" + cache.name() + ", mode=" + cache.configuration().getCacheMode() + ']'); }
/** {@inheritDoc} */ @Nullable @Override public IndexingQueryCacheFilter forCache(String cacheName) { final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName); // REPLICATED -> nothing to filter (explicit partitions are not supported). if (cache.context().isReplicated()) return null; // No backups and explicit partitions -> nothing to filter. if (cache.configuration().getBackups() == 0 && parts == null) return null; return new IndexingQueryCacheFilter(cache.context().affinity(), parts, topVer, ctx.discovery().localNode()); } }
/** {@inheritDoc} */ @Override public long getNonHeapMemoryUsed() { Collection<GridCacheAdapter<?, ?>> caches = ctx.cache().internalCaches(); long nonHeapUsed = vmMetrics.getNonHeapMemoryUsed(); for (GridCacheAdapter<?, ?> cache : caches) if (cache.context().statisticsEnabled() && cache.context().started() && cache.context().affinity().affinityTopologyVersion().topologyVersion() > 0) nonHeapUsed += cache.metrics0().getOffHeapAllocatedSize(); return nonHeapUsed; }
/** * @param idx Grid index. * @return DHT cache. */ protected <K, V> GridDhtCacheAdapter<K, V> dht(int idx) { GridCacheAdapter<K, V> internalCache = ((IgniteKernal)grid(idx)).internalCache(DEFAULT_CACHE_NAME); return internalCache.isNear() ? internalCache.context().near().dht() : internalCache.context().dht(); }
@Override public Boolean call() throws Exception { boolean retVal; try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new AddProcessor(id, 1)).get(); if (idx != null) { checkRemoved(idx); cache.getAndPut(itemKey(idx), item); retVal = true; } else retVal = false; tx.commit(); return retVal; } } });
/** * Test Optimistic repeatable read write-through. * * @throws Exception If failed. */ @Test public void testOptimisticTxWriteThrough() throws Exception { IgniteCache<Object, Object> near = jcache(); GridCacheAdapter<Integer, String> dht = dht(); try (Transaction tx = grid().transactions().txStart(OPTIMISTIC, REPEATABLE_READ) ) { near.put(2, "2"); near.put(3, "3"); assert "2".equals(near.get(2)); assert "3".equals(near.get(3)); GridCacheEntryEx entry = dht.peekEx(2); assert entry == null || entry.rawGet() == null : "Invalid entry: " + entry; tx.commit(); } assert "2".equals(near.get(2)); assert "3".equals(near.get(3)); assert "2".equals(dht.get(2)); assert "3".equals(dht.get(3)); assertEquals(2, near.size()); assertEquals(2, near.size()); assertEquals(2, dht.size()); assertEquals(2, dht.size()); }