@Nullable @Override public GridBiPredicate<K, V> forSpace(final String spaceName) { final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(spaceName); if (cache.context().isReplicated() || cache.configuration().getBackups() == 0) return null; return new GridBiPredicate<K, V>() { @Override public boolean apply(K k, V v) { return cache.context().affinity().primary(ctx.discovery().localNode(), k, -1); } }; } };
/** {@inheritDoc} */ @Override protected boolean updateNearCache(K key, long topVer) { if (!cctx.isDht() || !isNearEnabled(cctx) || cctx.localNodeId().equals(nearNodeId)) return false; if (cctx.config().getBackups() == 0) return true; // Check if we are on the backup node. return !cctx.affinity().backups(key, topVer).contains(cctx.localNode()); }
/** * @return {@code True} if need to filter out non-primary keys during processing of set data query. */ private boolean filterKeys() { return !collocated && !(ctx.isLocal() || ctx.isReplicated()) && (ctx.config().getBackups() > 0 || CU.isNearEnabled(ctx)); }
/** {@inheritDoc} */ @Override public void start0() throws GridException { aff = new GridAffinityAssignmentCache(cctx, cctx.namex(), cctx.config().getAffinity(), cctx.config().getAffinityMapper(), cctx.config().getBackups()); // Generate internal keys for partitions. int partCnt = partitions(); partAffKeys = new GridPartitionLockKey[partCnt]; Collection<Integer> found = new HashSet<>(); long affKey = 0; while (true) { GridPartitionLockKey key = new GridPartitionLockKey(affKey); int part = aff.partition(key); if (found.add(part)) { // This is a key for not yet calculated partition. key.partitionId(part); partAffKeys[part] = key; if (found.size() == partCnt) break; } affKey++; if (affKey > partCnt * MAX_PARTITION_KEY_ATTEMPT_RATIO) throw new IllegalStateException("Failed to calculate partition affinity keys for given affinity " + "function [attemptCnt=" + affKey + ", found=" + found + ", cacheName=" + cctx.name() + ']'); } }
/** * Checks if cache configurations are alike for warmup. * * @param ccfg0 First configuration. * @param ccfg1 Second configuration. * @return {@code True} if configurations match. */ private boolean matches(GridCacheConfiguration ccfg0, GridCacheConfiguration ccfg1) { return F.eq(ccfg0.getCacheMode(), ccfg1.getCacheMode()) && F.eq(ccfg0.getBackups(), ccfg1.getBackups()) && F.eq(ccfg0.getAtomicityMode(), ccfg1.getAtomicityMode()) && F.eq(ccfg0.getAtomicWriteOrderMode(), ccfg1.getAtomicWriteOrderMode()) && F.eq(ccfg0.getMemoryMode(), ccfg1.getMemoryMode()) && F.eq(ccfg0.getDistributionMode(), ccfg1.getDistributionMode()); }
/** * @param ccfg Cache configuration. * @return Data transfer object for affinity configuration properties. */ public static VisorAffinityConfig from(GridCacheConfiguration ccfg) { GridCacheAffinityFunction aff = ccfg.getAffinity(); Integer dfltReplicas = null; Boolean excludeNeighbors = null; if (aff instanceof GridCacheConsistentHashAffinityFunction) { GridCacheConsistentHashAffinityFunction hashAffFunc = (GridCacheConsistentHashAffinityFunction)aff; dfltReplicas = hashAffFunc.getDefaultReplicas(); excludeNeighbors = hashAffFunc.isExcludeNeighbors(); } VisorAffinityConfig cfg = new VisorAffinityConfig(); cfg.function(compactClass(aff)); cfg.mapper(compactClass(ccfg.getAffinityMapper())); cfg.partitionedBackups(ccfg.getBackups()); cfg.defaultReplicas(dfltReplicas); cfg.excludeNeighbors(excludeNeighbors); return cfg; }
GridDhtPartitionTopology top = dca.topology(); if (cfg.getCacheMode() != GridCacheMode.LOCAL && cfg.getBackups() > 0) partsMap = top.localPartitionMap();
int backups = dataCache.configuration().getBackups();
int backups = dataCache.configuration().getBackups();
perf.add("Decrease number of backups (set 'keyBackups' to 0)", cfg.getBackups() == 0);
affKeyBackups = cfg.getBackups();
atomicityMode = cc.getAtomicityMode(); atomicWriteOrderMode = cc.getAtomicWriteOrderMode(); backups = cc.getBackups(); cacheMode = cc.getCacheMode(); cloner = cc.getCloner();