/** {@inheritDoc} */ @Override public Collection<CacheStoreManager> stores(GridCacheSharedContext cctx) { if (cacheCtx == null) return null; CacheStoreManager store = cacheCtx.store(); if (store.configured()) return Collections.singleton(store); return null; }
/** * @param tx Transaction. * @param key Key. * @param reload flag. * @param subjId Subject ID. * @param taskName Task name. * @return Read value. * @throws IgniteCheckedException If failed. */ @Nullable protected Object readThrough(@Nullable IgniteInternalTx tx, KeyCacheObject key, boolean reload, UUID subjId, String taskName) throws IgniteCheckedException { return cctx.store().load(tx, key); }
/** {@inheritDoc} */ @Override public boolean storeWriteThrough(GridCacheSharedContext cctx) { if (cacheCtx == null) return false; CacheStoreManager store = cacheCtx.store(); return store.configured() && store.isWriteThrough(); }
/** * @return {@code True} If store writes should be performed from dht transactions. This happens if both * {@code writeBehindEnabled} and {@code writeBehindPreferPrimary} cache configuration properties * are set to {@code true} or the store is local. */ public boolean writeToStoreFromDht() { return store().isLocal() || cacheCfg.isWriteBehindEnabled(); }
/** * @return {@code True} if store and read-through mode are enabled in configuration. */ public boolean readThroughConfigured() { return store().configured() && cacheCfg.isReadThrough(); }
/** * Checks that cache store is present. * * @param ctx Registry. * @throws IgniteCheckedException If cache store is not present. */ public static void checkStore(GridCacheContext<?, ?> ctx) throws IgniteCheckedException { if (!ctx.store().configured()) throw new IgniteCheckedException("Failed to find cache store for method 'reload(..)' " + "(is GridCacheStore configured?)"); }
/** * @return {@code True} if store write-through enabled. */ private boolean writeThrough() { return ctx.writeThrough() && ctx.store().configured(); }
/** {@inheritDoc} */ @Override public Collection<CacheStoreManager> stores(GridCacheSharedContext cctx) { if (entry == null) return null; CacheStoreManager store = entry.context().store(); if (store.configured() && store.isLocal()) { // Only local stores take part at tx on backup node. return Collections.singleton(store); } return null; }
/** * @param cacheCtx Cache context to remove. */ void removeCacheContext(GridCacheContext cacheCtx) { int cacheId = cacheCtx.cacheId(); ctxMap.remove(cacheId, cacheCtx); CacheStoreManager mgr = cacheCtx.store(); if (mgr.configured() && mgr.isLocal()) locStoreCnt.decrementAndGet(); // Safely clean up the message listeners. ioMgr.removeCacheHandlers(cacheId); }
/** * Creates cache metrics; * * @param cctx Cache context. */ public CacheMetricsImpl(GridCacheContext<?, ?> cctx) { assert cctx != null; this.cctx = cctx; if (cctx.isNear()) dhtCtx = cctx.near().dht().context(); if (cctx.store().store() instanceof GridCacheWriteBehindStore) store = (GridCacheWriteBehindStore)cctx.store().store(); delegate = null; }
/** {@inheritDoc} */ @Override public Collection<CacheStoreManager> stores(GridCacheSharedContext cctx) { GridIntList cacheIds = activeCacheIds; if (!cacheIds.isEmpty()) { Collection<CacheStoreManager> stores = new ArrayList<>(cacheIds.size()); for (int i = 0; i < cacheIds.size(); i++) { int cacheId = cacheIds.get(i); CacheStoreManager store = cctx.cacheContext(cacheId).store(); if (store.configured()) stores.add(store); } return stores; } return null; }
/** * @param ctx Context. * @return Managers present in both, DHT and Near caches. */ @SuppressWarnings("IfMayBeConditional") private Collection<GridCacheManager> dhtExcludes(GridCacheContext ctx) { if (ctx.config().getCacheMode() == LOCAL || !isNearEnabled(ctx)) return Collections.emptyList(); else return F.asList(ctx.queries(), ctx.continuousQueries(), ctx.store()); }
/** * Adds cache context to shared cache context. * * @param cacheCtx Cache context to add. * @throws IgniteCheckedException If cache ID conflict detected. */ @SuppressWarnings("unchecked") public void addCacheContext(GridCacheContext cacheCtx) throws IgniteCheckedException { if (ctxMap.containsKey(cacheCtx.cacheId())) { GridCacheContext<K, V> existing = ctxMap.get(cacheCtx.cacheId()); throw new IgniteCheckedException("Failed to start cache due to conflicting cache ID " + "(change cache name and restart grid) [cacheName=" + cacheCtx.name() + ", conflictingCacheName=" + existing.name() + ']'); } CacheStoreManager mgr = cacheCtx.store(); if (mgr.configured() && mgr.isLocal()) locStoreCnt.incrementAndGet(); ctxMap.put(cacheCtx.cacheId(), cacheCtx); }
/** * @param ctx Context. * @return DHT managers. */ private List<GridCacheManager> dhtManagers(GridCacheContext ctx) { return F.asList(ctx.store(), ctx.events(), ctx.evicts(), ctx.queries(), ctx.continuousQueries(), ctx.dr()); }
/** {@inheritDoc} */ @Override public boolean storeWriteThrough(GridCacheSharedContext cctx) { if (!activeCacheIds.isEmpty()) { for (int i = 0; i < activeCacheIds.size(); i++) { int cacheId = activeCacheIds.get(i); CacheStoreManager store = cctx.cacheContext(cacheId).store(); if (store.configured() && store.isWriteThrough()) return true; } } return false; }
/** {@inheritDoc} */ @Override public void localLoad(Collection<? extends K> keys, final ExpiryPolicy plc, final boolean keepBinary) throws IgniteCheckedException { if (ctx.store().isLocal()) { super.localLoad(keys, plc, keepBinary); return; } // Version for all loaded entries. final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); final GridCacheVersion ver0 = ctx.shared().versions().nextForLoad(topVer); final boolean replicate = ctx.isDrEnabled(); final ExpiryPolicy plc0 = plc != null ? plc : ctx.expiry(); Collection<KeyCacheObject> keys0 = ctx.cacheKeysView(keys); ctx.store().loadAll(null, keys0, new CI2<KeyCacheObject, Object>() { @Override public void apply(KeyCacheObject key, Object val) { loadEntry(key, val, ver0, null, topVer, replicate, plc0); } }); }
/** * */ private void checkOpenedClosedCount() { assertEquals(GRID_CNT, Ignition.allGrids().size()); for (Ignite ignite : Ignition.allGrids()) { GridCacheContext cctx = ((IgniteKernal)ignite).internalCache(DEFAULT_CACHE_NAME).context(); CacheStore store = cctx.store().configuredStore(); long opened = ((LongAdder)U.field(store, "opened")).sum(); long closed = ((LongAdder)U.field(store, "closed")).sum(); assert opened > 0; assert closed > 0; assertEquals(opened, closed); } } }
/** * @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(); } }
/** * @param cctx Cache context. */ private void cleanup(GridCacheContext cctx) { CacheConfiguration cfg = cctx.config(); cleanup(cfg, cfg.getAffinity(), false); cleanup(cfg, cfg.getAffinityMapper(), false); cleanup(cfg, cfg.getEvictionFilter(), false); cleanup(cfg, cfg.getInterceptor(), false); cleanup(cfg, cctx.store().configuredStore(), false); if (!CU.isUtilityCache(cfg.getName()) && !CU.isSystemCache(cfg.getName())) { unregisterMbean(cctx.cache().localMxBean(), cfg.getName(), false); unregisterMbean(cctx.cache().clusterMxBean(), cfg.getName(), false); } cctx.cleanup(); }