/** * @param ccfg Cache configuration. * @param objs Extra components. * @return Components provided in cache configuration which can implement {@link GridLifecycleAware} interface. */ private Iterable<Object> lifecycleAwares(GridCacheConfiguration ccfg, Object...objs) { Collection<Object> ret = new ArrayList<>(7 + objs.length); ret.add(ccfg.getAffinity()); ret.add(ccfg.getAffinityMapper()); ret.add(ccfg.getCloner()); ret.add(ccfg.getEvictionFilter()); ret.add(ccfg.getEvictionPolicy()); ret.add(ccfg.getNearEvictionPolicy()); ret.add(ccfg.getInterceptor()); Collections.addAll(ret, objs); return ret; }
/** {@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() + ']'); } }
/** {@inheritDoc} */ @Override public Object affinityKey(K key) { A.notNull(key, "key"); if (cctx.portableEnabled()) { try { key = (K)cctx.marshalToPortable(key); } catch (GridPortableException e) { U.error(log, "Failed to marshal key to portable: " + key, e); } } return cctx.config().getAffinityMapper().affinityKey(key); }
continue; // No cache for the given GGFS configuration. GridCacheAffinityKeyMapper affMapper = cacheCfg.getAffinityMapper();
continue; // No cache for the given GGFS configuration. GridCacheAffinityKeyMapper affMapper = cacheCfg.getAffinityMapper();
/** {@inheritDoc} */ @Override public GridTuple3<GridAffinityMessage, GridAffinityMessage, GridAffinityAssignment> call() throws Exception { assert grid != null; assert log != null; GridKernal kernal = ((GridKernal)grid); GridCacheContext<Object, Object> cctx = kernal.internalCache(cacheName).context(); assert cctx != null; GridKernalContext ctx = kernal.context(); return F.t( affinityMessage(ctx, cctx.config().getAffinity()), affinityMessage(ctx, cctx.config().getAffinityMapper()), new GridAffinityAssignment(topVer, cctx.affinity().assignments(topVer))); }
/** * Checks that affinity keys are enlisted in group transaction on start. * * @param keys Keys to check. * @throws GridException If sanity check failed. */ private void groupLockSanityCheck(Iterable<? extends K> keys) throws GridException { if (groupLock() && cctx.kernalContext().config().isCacheSanityCheckEnabled()) { // Note that affinity is called without mapper on purpose. int affinityPart = cctx.config().getAffinity().partition(grpLockKey); for (K key : keys) { if (partitionLock()) { int part = cctx.affinity().partition(key); if (affinityPart != part) throw new GridException("Failed to enlist key into group-lock transaction (given " + "key does not belong to locked partition) [key=" + key + ", affinityPart=" + affinityPart + ", part=" + part + ", groupLockKey=" + grpLockKey + ']'); } else { Object affinityKey = cctx.config().getAffinityMapper().affinityKey(key); if (!grpLockKey.equals(affinityKey)) throw new GridException("Failed to enlist key into group-lock transaction (affinity key was " + "not enlisted to transaction on start) [key=" + key + ", affinityKey=" + affinityKey + ", groupLockKey=" + grpLockKey + ']'); } } } }
cctx.config().getAffinityMapper(), new GridAffinityAssignment(topVer, cctx.affinity().assignments(topVer)), cctx.portableEnabled());
/** * @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; }
/** * @param cctx Cache context. */ private void cleanup(GridCacheContext cctx) { GridCacheConfiguration cfg = cctx.config(); cleanup(cfg, cfg.getEvictionPolicy(), false); cleanup(cfg, cfg.getNearEvictionPolicy(), true); cleanup(cfg, cfg.getAffinity(), false); cleanup(cfg, cfg.getAffinityMapper(), false); cleanup(cfg, cctx.jta().tmLookup(), false); cleanup(cfg, cfg.getCloner(), false); cleanup(cfg, cfg.getStore(), false); cctx.cleanup(); }
throw new GridException("Cannot use same cache as both data and meta cache: " + cfg.getName()); if (!(dataCache.configuration().getAffinityMapper() instanceof GridGgfsGroupDataBlocksKeyMapper)) throw new GridException("Invalid GGFS data cache configuration (key affinity mapper class should be " + GridGgfsGroupDataBlocksKeyMapper.class.getSimpleName() + "): " + cfg);
throw new GridException("Cannot use same cache as both data and meta cache: " + cfg.getName()); if (!(dataCache.configuration().getAffinityMapper() instanceof GridGgfsGroupDataBlocksKeyMapper)) throw new GridException("Invalid GGFS data cache configuration (key affinity mapper class should be " + GridGgfsGroupDataBlocksKeyMapper.class.getSimpleName() + "): " + cfg);
/** * @param cfg Configuration. * @param objs Extra components. * @throws GridException If failed to inject. */ private void prepare(GridCacheConfiguration cfg, Object... objs) throws GridException { prepare(cfg, cfg.getEvictionPolicy(), false); prepare(cfg, cfg.getNearEvictionPolicy(), true); prepare(cfg, cfg.getAffinity(), false); prepare(cfg, cfg.getAffinityMapper(), false); prepare(cfg, cfg.getCloner(), false); prepare(cfg, cfg.getStore(), false); prepare(cfg, cfg.getEvictionFilter(), false); prepare(cfg, cfg.getInterceptor(), false); GridDrSenderCacheConfiguration drSndCfg = cfg.getDrSenderConfiguration(); if (drSndCfg != null) prepare(cfg, drSndCfg.getEntryFilter(), false); GridDrReceiverCacheConfiguration drRcvCfg = cfg.getDrReceiverConfiguration(); if (drRcvCfg != null) prepare(cfg, drRcvCfg.getConflictResolver(), false); for (Object obj : objs) prepare(cfg, obj, false); }
.internalCache(ggfsCtx.configuration().getDataCacheName()).configuration().getAffinityMapper();
.internalCache(ggfsCtx.configuration().getDataCacheName()).configuration().getAffinityMapper();
writeSyncMode = cfg.getWriteSynchronizationMode(); affMapperClsName = className(cfg.getAffinityMapper());
cfg.setBackups(Integer.MAX_VALUE); if (cfg.getAffinityMapper() == null) cfg.setAffinityMapper(new GridCacheDefaultAffinityKeyMapper());
affMapper = cc.getAffinityMapper(); atomicityMode = cc.getAtomicityMode(); atomicWriteOrderMode = cc.getAtomicWriteOrderMode();