/** * @return {@code True} if near cache is enabled. */ public boolean nearCacheEnabled() { return cacheMode() != LOCAL && ccfg.getNearConfiguration() != null; }
/** * Checks if near cache is enabled for cache configuration. * * @param cfg Cache configuration to check. * @return {@code True} if near cache is enabled, {@code false} otherwise. */ @SuppressWarnings("SimplifiableIfStatement") public static boolean isNearEnabled(CacheConfiguration cfg) { if (cfg.getCacheMode() == LOCAL) return false; return cfg.getNearConfiguration() != null; }
/** * @return Near eviction policy class name. * * @deprecated Use nearEvictionPolicyFactoryClassName() instead. */ public String nearEvictionPolicyClassName() { NearCacheConfiguration nearCfg = ccfg.getNearConfiguration(); if (nearCfg == null) return null; return className(nearCfg.getNearEvictionPolicy()); }
/** * Dynamically starts cache as a result of SQL {@code CREATE TABLE} command. * * @param ccfg Cache configuration. */ public IgniteInternalFuture<Boolean> dynamicStartSqlCache( CacheConfiguration ccfg ) { A.notNull(ccfg, "ccfg"); return dynamicStartCache(ccfg, ccfg.getName(), ccfg.getNearConfiguration(), CacheType.USER, true, false, true, true); }
/** {@inheritDoc} */ @Override public void start() throws IgniteCheckedException { if (map == null) { map = new GridCacheLocalConcurrentMap( ctx, entryFactory(), ctx.config().getNearConfiguration().getNearStartSize()); } }
/** {@inheritDoc} */ @Override public void onReconnected() { map = new GridCacheLocalConcurrentMap( ctx, entryFactory(), ctx.config().getNearConfiguration().getNearStartSize()); }
/** {@inheritDoc} */ @Override public List<GridCacheClearAllRunnable<K, V>> splitClearLocally(boolean srv, boolean near, boolean readers) { assert configuration().getNearConfiguration() != null; if (ctx.affinityNode()) { GridCacheVersion obsoleteVer = ctx.versions().next(); List<GridCacheClearAllRunnable<K, V>> dhtJobs = dht().splitClearLocally(srv, near, readers); List<GridCacheClearAllRunnable<K, V>> res = new ArrayList<>(dhtJobs.size()); for (GridCacheClearAllRunnable<K, V> dhtJob : dhtJobs) res.add(new GridNearCacheClearAllRunnable<>(this, obsoleteVer, dhtJob)); return res; } else return super.splitClearLocally(srv, near, readers); }
/** * Create data transfer object for near cache configuration properties. * * @param ccfg Cache configuration. */ public VisorCacheNearConfiguration(CacheConfiguration ccfg) { nearEnabled = GridCacheUtils.isNearEnabled(ccfg); if (nearEnabled) { NearCacheConfiguration nccfg = ccfg.getNearConfiguration(); final Factory nearEvictionPlc = nccfg.getNearEvictionPolicyFactory(); nearStartSize = nccfg.getNearStartSize(); nearEvictPlc = compactClass(nearEvictionPlc); nearEvictMaxSize = evictionPolicyMaxSize(nearEvictionPlc); } }
/** {@inheritDoc} */ @Override public void start0() throws IgniteCheckedException { CacheConfiguration cfg = cctx.config(); if (cctx.isNear()) { plc = (cfg.getNearConfiguration().getNearEvictionPolicyFactory() != null) ? (EvictionPolicy)cfg.getNearConfiguration().getNearEvictionPolicyFactory().create() : cfg.getNearConfiguration().getNearEvictionPolicy(); } else if (cfg.getEvictionPolicyFactory() != null) plc = (EvictionPolicy)cfg.getEvictionPolicyFactory().create(); else plc = cfg.getEvictionPolicy(); plcEnabled = plc != null; if (plcEnabled) prepare(cfg, plc, cctx.isNear()); filter = cfg.getEvictionFilter(); if (log.isDebugEnabled()) log.debug("Eviction manager started on node: " + cctx.nodeId()); }
/** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration() { CacheConfiguration ccfg = super.cacheConfiguration(); assertNotNull(ccfg.getNearConfiguration()); ccfg.setNearConfiguration(null); return ccfg; }
/** * @param i Grid index. * @return Policy. */ @SuppressWarnings({"unchecked"}) protected T nearPolicy(int i) { CacheConfiguration cfg = grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class); NearCacheConfiguration nearCfg = cfg.getNearConfiguration(); return (T)(nearCfg == null ? null : nearCfg.getNearEvictionPolicy()); }
/** * @param ccfg Cache configuration. */ private void logCacheInfo(CacheConfiguration<?, ?> ccfg) { log.info("Test cache [mode=" + ccfg.getCacheMode() + ", sync=" + ccfg.getWriteSynchronizationMode() + ", backups=" + ccfg.getBackups() + ", near=" + (ccfg.getNearConfiguration() != null) + ']'); }
/** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { dhtCtx = cctx.isNear() ? cctx.near().dht().context() : cctx; boolean cleanupDisabled = cctx.kernalContext().isDaemon() || !cctx.config().isEagerTtl() || CU.isUtilityCache(cctx.name()) || cctx.dataStructuresCache() || (cctx.kernalContext().clientNode() && cctx.config().getNearConfiguration() == null); if (cleanupDisabled) return; eagerTtlEnabled = true; cctx.shared().ttl().register(this); pendingEntries = (!cctx.isLocal() && cctx.config().getNearConfiguration() != null) ? new GridConcurrentSkipListSetEx() : null; }
/** * @param ccfg Cache configuration. */ private void logCacheInfo(CacheConfiguration<?, ?> ccfg) { log.info("Test cache [mode=" + ccfg.getCacheMode() + ", sync=" + ccfg.getWriteSynchronizationMode() + ", backups=" + ccfg.getBackups() + ", near=" + (ccfg.getNearConfiguration() != null) + ", store=" + ccfg.isWriteThrough() + ", evictPlc=" + (ccfg.getEvictionPolicy() != null) + ']'); }
/** * @param ccfg Cache configuration. */ private void logCacheInfo(CacheConfiguration<?, ?> ccfg) { log.info("Test cache [mode=" + ccfg.getCacheMode() + ", sync=" + ccfg.getWriteSynchronizationMode() + ", backups=" + ccfg.getBackups() + ", near=" + (ccfg.getNearConfiguration() != null) + ", store=" + ccfg.isWriteThrough() + ", evictPlc=" + (ccfg.getEvictionPolicy() != null) + ']'); }
/** */ private void executeForNodeAndCache(CacheConfiguration ccfg, Ignite ignite, TestClosure clo, TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { String cacheName = ccfg.getName(); IgniteCache cache; if (ignite.configuration().isClientMode() && ccfg.getCacheMode() == CacheMode.PARTITIONED && ccfg.getNearConfiguration() != null) cache = ignite.getOrCreateNearCache(ccfg.getName(), ccfg.getNearConfiguration()); else cache = ignite.cache(ccfg.getName()); cache.removeAll(); assertEquals(0, cache.size()); clo.configure(ignite, cache, concurrency, isolation); log.info("Running test with node " + ignite.name() + ", cache " + cacheName); clo.key1 = 1; clo.key2 = 4; clo.run(); }
/** */ private void cleanup() throws Exception { for (CacheConfiguration ccfg : cacheConfigurations()) { String cacheName = ccfg.getName(); if (ccfg.getCacheMode() == CacheMode.LOCAL) { grid(NODE_CLIENT).cache(cacheName).clear(); for (int node = 0; node < NODE_COUNT; node++) grid(node).cache(cacheName).clear(); } else { if (ccfg.getCacheMode() == CacheMode.PARTITIONED && ccfg.getNearConfiguration() != null) { IgniteCache cache = grid(NODE_CLIENT).getOrCreateNearCache(cacheName, ccfg.getNearConfiguration()); cache.clear(); } grid(NODE_CLIENT).cache(cacheName).clear(); } } executeSql("DROP TABLE test IF EXISTS"); }
/** * @throws Exception If failed. */ private void checkNoPrimaryReadPreloadFinished(List<CacheConfiguration<Object, Object>> cacheCfgs) throws Exception { for (CacheConfiguration<Object, Object> ccfg : cacheCfgs) { boolean near = (ccfg.getNearConfiguration() != null); log.info("Test cache [mode=" + ccfg.getCacheMode() + ", atomicity=" + ccfg.getAtomicityMode() + ", backups=" + ccfg.getBackups() + ", near=" + near + "]"); ignite(0).createCache(ccfg); awaitPartitionMapExchange(); try { checkLocalRead(NODES, ccfg); } finally { ignite(0).destroyCache(ccfg.getName()); } } }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration c = super.getConfiguration(igniteInstanceName); c.getTransactionConfiguration().setTxSerializableEnabled(true); CacheConfiguration cc = defaultCacheConfiguration(); cc.setCacheMode(PARTITIONED); cc.setWriteSynchronizationMode(FULL_SYNC); FifoEvictionPolicy plc = new FifoEvictionPolicy(); plc.setMaxSize(EVICT_CACHE_SIZE); cc.setEvictionPolicy(plc); cc.setOnheapCacheEnabled(true); FifoEvictionPolicy nearPlc = new FifoEvictionPolicy(); nearPlc.setMaxSize(EVICT_CACHE_SIZE); cc.getNearConfiguration().setNearEvictionPolicy(nearPlc); // We set 1 backup explicitly. cc.setBackups(1); c.setCacheConfiguration(cc); return c; }
/** * @throws Exception If failed. */ @Test public void testUpdate() throws Exception { if (gridCount() > 1) { IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME); Integer key = nearKey(cache); primaryCache(key, DEFAULT_CACHE_NAME).put(key, 1); assertEquals(1, cache.get(key)); primaryCache(key, DEFAULT_CACHE_NAME).put(key, 2); if (cache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null) assertEquals(2, cache.localPeek(key)); assertEquals(2, cache.get(key)); int cnt = 0; for (Cache.Entry e : cache) cnt++; assertEquals(1, cnt); } } }