@Override public String apply(GridCache<?, ?> c) { return c.name(); } },
/** * Gets utility cache. * * @param keyCls Key class. * @param valCls Value class. * @return Projection over utility cache. */ public <K extends GridCacheUtilityKey, V> GridCacheProjectionEx<K, V> utilityCache(Class<K> keyCls, Class<V> valCls) { return (GridCacheProjectionEx<K, V>)cache(CU.UTILITY_CACHE_NAME).projection(keyCls, valCls); }
/** * Maps affinity key to node. * * @param affinityKey Affinity key to map. * @return Primary node for this key. */ public GridNode affinityNode(Object affinityKey) { return dataCache.affinity().mapKeyToNode(affinityKey); }
@Override public boolean apply(GridCache<?, ?> c) { return !CU.UTILITY_CACHE_NAME.equals(c.name()) && F.eq(spiName, c.configuration().getIndexingSpiName()); } }
/** {@inheritDoc} */ @Override public void update(GridCache<K, V> cache, Collection<Map.Entry<K, V>> entries) throws GridException { assert cache != null; assert !F.isEmpty(entries); for (Map.Entry<K, V> entry : entries) { K key = entry.getKey(); assert key != null; V val = entry.getValue(); if (val == null) cache.removex(key); else cache.putx(key, val); } } }
/** {@inheritDoc} */ @Override protected Void run(Set<String> cacheNames) throws GridException { Collection<GridFuture<?>> futs = new ArrayList<>(); for(GridCache c : g.cachesx()) { if (cacheNames.contains(c.name())) futs.add(c.forceRepartition()); } for (GridFuture f: futs) f.get(); return null; }
/** * Set sampling flag. * * @param val Sampling flag state or {@code null} to clear sampling state and mark it as "not set". * @return {@code True} if sampling mode was actually changed by this call. * @throws GridException If failed. */ public boolean sampling(Boolean val) throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ); try { Object prev = val != null ? metaCache.put(sampling, val) : metaCache.remove(sampling); tx.commit(); return !F.eq(prev, val); } finally { tx.close(); } } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to set sampling flag because Grid is stopping."); }
log.debug("Update file info [fileId=" + fileId + ", c=" + c + ']'); GridCacheTx tx = metaCache.isLockedByThread(fileId) ? null : metaCache.txStart(PESSIMISTIC, REPEATABLE_READ); " [oldInfo=" + oldInfo + ", newInfo=" + newInfo + ", c=" + c + ']'); boolean b = metaCache.replace(fileId, oldInfo, newInfo);
@Override public Boolean call() throws Exception { return cache.get(key) != null; } });
/** {@inheritDoc} */ @Override protected Map<String, GridBiTuple<Integer, Integer>> run(Set<String> arg) throws GridException { Map<String, GridBiTuple<Integer, Integer>> res = new HashMap<>(); for(GridCache cache : g.cachesx()) { String cacheName = cache.name(); if (arg.contains(cacheName)) { Set keys = cache.keySet(); int before = keys.size(), after = before; for (Object key : keys) { if (cache.clear(key)) after--; } res.put(cacheName, new GridBiTuple<>(before, after)); } } return res; }
/** {@inheritDoc} */ @Override protected Map<String, GridBiTuple<Integer, Integer>> run(Set<String> names) throws GridException { final Map<String, GridBiTuple<Integer, Integer>> res = new HashMap<>(); for(GridCache cache : g.cachesx()) { String cacheName = cache.name(); if (names.contains(cacheName)) { final Set keys = cache.keySet(); int before = keys.size(), after = before; for (Object key : keys) { if (cache.compact(key)) after--; } res.put(cacheName, new GridBiTuple<>(before, after)); } } return res; }
/** {@inheritDoc} */ @Override protected Map<String, Integer> run(GridTuple3<Set<String>, Long, Object[]> arg) throws GridException { Set<String> cacheNames = arg.get1(); Long ttl = arg.get2(); Object[] loaderArgs = arg.get3(); Map<String, Integer> res = new HashMap<>(); for (GridCache c: g.cachesx()) { String cacheName = c.name(); if (cacheNames.contains(cacheName)) { c.loadCache(new P2<Object, Object>() { @Override public boolean apply(Object o, Object o2) { return true; } }, ttl, loaderArgs); res.put(cacheName, c.size()); // Put new key size for successfully loaded cache. } } return res; }
/** {@inheritDoc} */ @Override protected void start0() throws GridException { cfg = ggfsCtx.configuration(); metaCache = ggfsCtx.kernalContext().cache().cache(cfg.getMetaCacheName()); if (metaCache.configuration().getAtomicityMode() != TRANSACTIONAL) throw new GridException("Meta cache should be transactional: " + cfg.getMetaCacheName()); evts = ggfsCtx.kernalContext().event(); sampling = new GridGgfsSamplingKey(cfg.getName()); assert metaCache != null; id2InfoPrj = (GridCacheProjectionEx<GridUuid, GridGgfsFileInfo>)metaCache.<GridUuid, GridGgfsFileInfo>cache(); log = ggfsCtx.kernalContext().log(GridGgfsMetaManager.class); }
/** * Generates next affinity key for local node based on current topology. If previous affinity key maps * on local node, return previous affinity key to prevent unnecessary file map growth. * * @param prevAffKey Affinity key of previous block. * @return Affinity key. */ public GridUuid nextAffinityKey(@Nullable GridUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!isAffinityNode(dataCache.configuration())) return null; UUID nodeId = ggfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { GridUuid key = new GridUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
assert !F.isEmpty(entries); assert cache.configuration().getAtomicityMode() != ATOMIC; int part = cache.affinity().partition(key); int cnt = e.getValue(); GridCacheTx tx = cache.txStartPartition(part, PESSIMISTIC, REPEATABLE_READ, 0, cnt);
/** {@inheritDoc} */ @Override protected Map<String, GridBiTuple<Integer, Integer>> run(Set<String> names) throws GridException { Map<String, GridBiTuple<Integer, Integer>> total = new HashMap<>(); for (GridCache c: g.cachesx()) { String cacheName = c.name(); if (names.contains(cacheName)) { Set<GridCacheEntry> entries = c.entrySet(); int before = entries.size(), after = before; for (GridCacheEntry entry: entries) { if (entry.backup() && entry.evict()) after--; } total.put(cacheName, new GridBiTuple<>(before, after)); } } return total; }
/** * @param cacheName Cache name. * @param keys Keys. * @param topVer Topology version. * @return Affinity map. * @throws GridException If failed. */ private <K> Map<GridNode, Collection<K>> keysToNodes(@Nullable final String cacheName, Collection<? extends K> keys, long topVer) throws GridException { if (F.isEmpty(keys)) return Collections.emptyMap(); GridNode loc = ctx.discovery().localNode(); if (U.hasCache(loc, cacheName) && ctx.cache().cache(cacheName).configuration().getCacheMode() == LOCAL) return F.asMap(loc, (Collection<K>)keys); AffinityInfo affInfo = affinityCache(cacheName, topVer); return affInfo != null ? affinityMap(affInfo, keys) : Collections.<GridNode, Collection<K>>emptyMap(); }