/** * @return Cache object context. */ private CacheObjectContext objectContext() { if (ctx == null) return null; return ctx.cache().internalCache(cacheName).context().cacheObjectContext(); }
/** * @param cacheName Cache name. * @return Cache object context. */ private CacheObjectContext cacheObjectContext(String cacheName) { return ctx.cache().internalCache(cacheName).context().cacheObjectContext(); }
/** * @param cacheName Cache name. * @return If replicated cache with given name is locally available. */ private boolean replicatedCacheAvailable(String cacheName) { GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName); return cache != null && cache.configuration().getCacheMode() == REPLICATED; }
/** * USED ONLY FOR TESTING. * * @param name Cache name. * @param <K> Key type. * @param <V> Value type. * @return Internal cache instance. */ /*@java.test.only*/ public <K, V> GridCacheAdapter<K, V> internalCache(String name) { CU.validateCacheName(name); checkClusterState(); return ctx.cache().internalCache(name); }
/** {@inheritDoc} */ @Override public Void call() throws IgniteCheckedException { assert ignite != null; GridCacheAdapter cache = ((IgniteKernal)ignite).context().cache().internalCache(cacheName); // On non-affinity node cache starts on demand, so it may not be running. if (cache != null) cache.context().dataStructures().blockSet(setId); return null; }
/** {@inheritDoc} */ @Override public void unregister(UUID routineId, GridKernalContext ctx) { assert routineId != null; assert ctx != null; GridCacheAdapter<K, V> cache = ctx.cache().internalCache(cacheName); if (cache != null) cache.context().continuousQueries().unregisterListener(internal, routineId); }
@Override public <K> Affinity<K> affinity(String cacheName) { CU.validateCacheName(cacheName); checkClusterState(); GridCacheAdapter<K, ?> cache = ctx.cache().internalCache(cacheName); if (cache != null) return cache.affinity(); return ctx.affinity().affinityProxy(cacheName); }
/** {@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()); } }
@Override public boolean apply() { for (Ignite g : G.allGrids()) { GridCacheAdapter<Object, Object> cache = ((IgniteEx)g).context().cache().internalCache(name); if (cache == null) return true; if (!cache.isEmpty()) return false; } return true; } }, getTestTimeout());
/** {@inheritDoc} */ @Override public Void call() throws Exception { GridCacheAdapter<K, V> cache = ((IgniteKernal)ignite).context().cache().internalCache(cacheName); assert cache != null : cacheName; cache.context().gate().enter(); try { if (update) cache.localLoadAndUpdate(keys); else cache.localLoad(keys, plc, keepBinary); } finally { cache.context().gate().leave(); } return null; }
/** * @param ignite Ignite instance. * @param orgId Organization ID. * @return {@code true} if partition for the given organization ID is primary on the given node. */ private static boolean primaryPartition(IgniteEx ignite, int orgId) { int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId); GridCacheAdapter<?, ?> cacheAdapterPers = ignite.context().cache() .internalCache(Person.class.getSimpleName()); GridDhtLocalPartition pPers = cacheAdapterPers.context().topology() .localPartition(part, AffinityTopologyVersion.NONE, false); return pPers.primary(AffinityTopologyVersion.NONE); }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { for (String cacheName : new String[] {DEFAULT_CACHE_NAME, CU.UTILITY_CACHE_NAME}) { IgniteKernal kernal = (IgniteKernal)ignite(0); GridCacheAdapter<Object, Object> cache = kernal.context().cache().internalCache(cacheName); cache.removeAll(F.asList("1", "2", "3")); } }
/** * @param node Node. * @param topVer Topology version. * @param cache Cache name. * @return Affinity assignments. */ private List<List<ClusterNode>> affinity(Ignite node, AffinityTopologyVersion topVer, String cache) { GridCacheContext cctx = ((IgniteKernal)node).context().cache().internalCache(cache).context(); return cctx.affinity().assignments(topVer); }
/** {@inheritDoc} */ @Override public Object call() throws IgniteCheckedException { if (topVer != null) { GridCacheAffinityManager aff = ((IgniteKernal)ignite).context().cache().internalCache(CACHE_NAME).context().affinity(); ClusterNode loc = ignite.cluster().localNode(); if (loc.equals(aff.primaryByKey(key, topVer))) return true; AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer.topologyVersion() + 1, 0); assertEquals(loc, aff.primaryByKey(key, topVer0)); } return null; } }
/** * @param ignite Grid to take store from. * @param map Expected values in store. * @throws Exception If failed. */ private void checkStore(Ignite ignite, Map<Integer, String> map) throws Exception { String cacheName = ignite.configuration().getCacheConfiguration()[0].getName(); GridCacheContext ctx = ((IgniteKernal)grid()).context().cache().internalCache(cacheName).context(); CacheStore store = ctx.store().configuredStore(); assertEquals(map, ((GridCacheTestStore)store).getMap()); }
/** * Clears all stores. * * @param cnt Grid count. */ private void clearStores(int cnt) { for (int i = 0; i < cnt; i++) { String cacheName = grid(i).configuration().getCacheConfiguration()[0].getName(); GridCacheContext ctx = ((IgniteKernal)grid()).context().cache().internalCache(cacheName).context(); CacheStore store = ctx.store().configuredStore(); ((GridCacheTestStore)store).reset(); } }
/** * */ private void assertCachesAfterStop(IgniteEx igniteEx) { assertNull(igniteEx .context() .cache() .cacheGroup(CU.cacheId(STATIC_CACHE_CACHE_GROUP_NAME))); assertTrue(igniteEx.context().cache().cacheGroups().isEmpty()); for (int i = 0; i < CACHES_COUNT; i++) { assertNull(igniteEx.context().cache().cache(STATIC_CACHE_PREFIX + i)); assertNull(igniteEx.context().cache().internalCache(STATIC_CACHE_PREFIX + i)); } }
/** * @param cacheName Cache name. * @param node Node. * @param exp {@code True} if expect that cache is started on node. */ void checkCache(Ignite node, String cacheName, boolean exp) throws IgniteCheckedException { ((IgniteEx)node).context().cache().context().exchange().lastTopologyFuture().get(); ((IgniteEx)node).context().state().publicApiActiveState(true); GridCacheAdapter cache = ((IgniteEx)node).context().cache().internalCache(cacheName); if (exp) assertNotNull("Cache not found [cache=" + cacheName + ", node=" + node.name() + ']', cache); else assertNull("Unexpected cache found [cache=" + cacheName + ", node=" + node.name() + ']', cache); }
/** * @param cacheName Cache name. * @param expDone Expected rebalance finish flag. */ private void checkRebalance(String cacheName, boolean expDone) { for (Ignite node : G.allGrids()) { IgniteKernal node0 = (IgniteKernal)node; GridCacheAdapter cache = node0.context().cache().internalCache(cacheName); AffinityTopologyVersion topVer = node0.context().cache().context().exchange().readyAffinityVersion(); if (cache != null) assertEquals(expDone, cache.context().topology().rebalanceFinished(topVer)); else node0.context().discovery().cacheAffinityNode(node0.localNode(), cacheName); } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { grid(0).cache(DEFAULT_CACHE_NAME).removeAll(); for (int i = 0; i < GRID_CNT; i++) { Ignite g = grid(i); IgniteCache<String, int[]> c = g.cache(DEFAULT_CACHE_NAME); GridCacheAdapter<Object, Object> cache = ((IgniteEx)g).context().cache().internalCache(DEFAULT_CACHE_NAME); info("Node: " + g.cluster().localNode().id()); info("Entries: " + cache.entries()); if (cache.context().isNear()) info("DHT entries: " + cache.context().near().dht().entries()); assertEquals("Cache is not empty, node [entries=" + c.localEntries() + ", igniteInstanceName=" + g.name() + ']', 0, c.localSize()); } }