aff = cc.getAffinity(); affMapper = cc.getAffinityMapper(); atomicityMode = cc.getAtomicityMode(); atomicWriteOrderMode = cc.getAtomicWriteOrderMode(); backups = cc.getBackups(); cacheMode = cc.getCacheMode(); cloner = cc.getCloner(); dfltConcurrency = cc.getDefaultTxConcurrency(); dfltIsolation = cc.getDefaultTxIsolation(); dfltLockTimeout = cc.getDefaultLockTimeout(); dfltQryTimeout = cc.getDefaultQueryTimeout(); dfltTxTimeout = cc.getDefaultTxTimeout(); dgcFreq = cc.getDgcFrequency(); dgcRmvLocks = cc.isDgcRemoveLocks(); dgcSuspectLockTimeout = cc.getDgcSuspectLockTimeout(); distro = cc.getDistributionMode(); drSndCacheCfg = cc.getDrSenderConfiguration() != null ? new GridDrSenderCacheConfiguration(cc.getDrSenderConfiguration()) : null; drRcvCacheCfg = cc.getDrReceiverConfiguration() != null ? new GridDrReceiverCacheConfiguration(cc.getDrReceiverConfiguration()) : null; eagerTtl = cc.isEagerTtl(); evictFilter = cc.getEvictionFilter(); evictKeyBufSize = cc.getEvictSynchronizedKeyBufferSize(); evictMaxOverflowRatio = cc.getEvictMaxOverflowRatio(); evictNearSync = cc.isEvictNearSynchronized(); evictPlc = cc.getEvictionPolicy(); evictSync = cc.isEvictSynchronized(); evictSyncConcurrencyLvl = cc.getEvictSynchronizedConcurrencyLevel(); evictSyncTimeout = cc.getEvictSynchronizedTimeout();
/** * @return {@code True} if values should be always unmarshalled. */ public boolean isUnmarshalValues() { return cacheCfg.isQueryIndexEnabled() || !cacheCfg.isStoreValueBytes(); }
/** * 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(GridCacheConfiguration cfg) { if (cfg.getCacheMode() == LOCAL) return false; return cfg.getDistributionMode() == NEAR_PARTITIONED || cfg.getDistributionMode() == GridCacheDistributionMode.NEAR_ONLY; }
/** {@inheritDoc} */ @Override public void preProcessCacheConfiguration(GridCacheConfiguration cfg) { GridCacheEvictionPolicy evictPlc = cfg.getEvictionPolicy(); if (evictPlc instanceof GridCacheGgfsPerBlockLruEvictionPolicy && cfg.getEvictionFilter() == null) cfg.setEvictionFilter(new GridCacheGgfsEvictionFilter()); }
atomicityMode = cfg.getAtomicityMode(); cacheMode = cfg.getCacheMode(); dfltConcurrency = cfg.getDefaultTxConcurrency(); dfltIsolation = cfg.getDefaultTxIsolation(); dfltLockTimeout = cfg.getDefaultLockTimeout(); dfltQryTimeout = cfg.getDefaultQueryTimeout(); dfltTxTimeout = cfg.getDefaultTxTimeout(); dgcFreq = cfg.getDgcFrequency(); dgcRmvLocks = cfg.isDgcRemoveLocks(); dgcSuspectLockTimeout = cfg.getDgcSuspectLockTimeout(); drRcvAttrs = cfg.getDrReceiverConfiguration() != null ? new GridCacheDrReceiveAttributes(cfg.getDrReceiverConfiguration()) : null; drSndAttrs = cfg.getDrSenderConfiguration() != null ? new GridCacheDrSendAttributes(cfg.getDrSenderConfiguration()) : null; evictMaxOverflowRatio = cfg.getEvictMaxOverflowRatio(); evictNearSync = cfg.isEvictNearSynchronized(); evictSync = cfg.isEvictSynchronized(); indexingSpiName = cfg.getIndexingSpiName(); name = cfg.getName(); partDistro = GridCacheUtils.distributionMode(cfg); preloadBatchSize = cfg.getPreloadBatchSize(); preloadMode = cfg.getPreloadMode(); qryIdxEnabled = cfg.isQueryIndexEnabled(); seqReserveSize = cfg.getAtomicSequenceReserveSize(); storeEnabled = cfg.getStore() != null; storeValBytes = cfg.isStoreValueBytes();
if (cc.getCacheMode() == REPLICATED) { if (cc.getAffinity() instanceof GridCachePartitionFairAffinity) throw new GridException("REPLICATED cache can not be started with GridCachePartitionFairAffinity" + " [cacheName=" + cc.getName() + ']'); if (cc.getAffinity() instanceof GridCacheConsistentHashAffinityFunction) { GridCacheConsistentHashAffinityFunction aff = (GridCacheConsistentHashAffinityFunction)cc.getAffinity(); "GridCacheConsistentHashAffinityFunction cannot be set [cacheName=" + cc.getName() + ']'); if (cc.getAffinity() instanceof GridCacheRendezvousAffinityFunction) { GridCacheRendezvousAffinityFunction aff = (GridCacheRendezvousAffinityFunction)cc.getAffinity(); "GridCacheRendezvousAffinityFunction cannot be set [cacheName=" + cc.getName() + ']'); if (cc.getDistributionMode() == NEAR_PARTITIONED) { U.warn(log, "NEAR_PARTITIONED distribution mode cannot be used with REPLICATED cache, " + "will be changed to PARTITIONED_ONLY [cacheName=" + cc.getName() + ']'); cc.setDistributionMode(PARTITIONED_ONLY); if (cc.getCacheMode() == LOCAL && !cc.getAffinity().getClass().equals(LocalAffinityFunction.class)) U.warn(log, "GridCacheAffinityFunction configuration parameter will be ignored for local cache [cacheName=" + cc.getName() + ']'); if (cc.getPreloadMode() != GridCachePreloadMode.NONE) { assertParameter(cc.getPreloadThreadPoolSize() > 0, "preloadThreadPoolSize > 0"); assertParameter(cc.getPreloadBatchSize() > 0, "preloadBatchSize > 0");
cfg.name(ccfg.getName()); cfg.mode(ccfg.getCacheMode()); cfg.distributionMode(ccfg.getDistributionMode()); cfg.atomicityMode(ccfg.getAtomicityMode()); cfg.atomicSequenceReserveSize(ccfg.getAtomicSequenceReserveSize()); cfg.atomicWriteOrderMode(ccfg.getAtomicWriteOrderMode()); cfg.atomicSequenceReserveSize(ccfg.getAtomicSequenceReserveSize()); cfg.eagerTtl(ccfg.isEagerTtl()); cfg.refreshAheadRatio(ccfg.getRefreshAheadRatio()); cfg.writeSynchronizationMode(ccfg.getWriteSynchronizationMode()); cfg.swapEnabled(ccfg.isSwapEnabled()); cfg.queryIndexEnabled(ccfg.isQueryIndexEnabled()); cfg.batchUpdateOnCommit(ccfg.isBatchUpdateOnCommit()); cfg.invalidate(ccfg.isInvalidate()); cfg.startSize(ccfg.getStartSize()); cfg.cloner(compactClass(ccfg.getCloner())); cfg.transactionManagerLookupClassName(ccfg.getTransactionManagerLookupClassName()); cfg.txSerializableEnabled(ccfg.isTxSerializableEnabled()); cfg.offsetHeapMaxMemory(ccfg.getOffHeapMaxMemory()); cfg.maxQueryIteratorCount(ccfg.getMaximumQueryIteratorCount()); cfg.maxConcurrentAsyncOperations(ccfg.getMaxConcurrentAsyncOperations()); cfg.pessimisticTxLoggerSize(ccfg.getPessimisticTxLogSize()); cfg.pessimisticTxLoggerLinger(ccfg.getPessimisticTxLogLinger()); cfg.memoryMode(ccfg.getMemoryMode()); cfg.indexingSpiName(ccfg.getIndexingSpiName()); cfg.interceptor(compactClass(ccfg.getInterceptor())); cfg.affinityConfig(VisorAffinityConfig.from(ccfg)); cfg.preloadConfig(VisorPreloadConfig.from(ccfg));
if (cfg.getCacheMode() == null) cfg.setCacheMode(DFLT_CACHE_MODE); if (cfg.getDefaultTxConcurrency() == null) cfg.setDefaultTxConcurrency(DFLT_TX_CONCURRENCY); if (cfg.getDefaultTxIsolation() == null) cfg.setDefaultTxIsolation(DFLT_TX_ISOLATION); if (cfg.getMemoryMode() == null) cfg.setMemoryMode(DFLT_MEMORY_MODE); if (cfg.getAffinity() == null) { if (cfg.getCacheMode() == PARTITIONED) { GridCacheConsistentHashAffinityFunction aff = new GridCacheConsistentHashAffinityFunction(); cfg.setAffinity(aff); else if (cfg.getCacheMode() == REPLICATED) { GridCacheConsistentHashAffinityFunction aff = new GridCacheConsistentHashAffinityFunction(false, 512); cfg.setAffinity(aff); cfg.setBackups(Integer.MAX_VALUE); cfg.setAffinity(new LocalAffinityFunction()); if (cfg.getCacheMode() == PARTITIONED) { if (cfg.getAffinity() instanceof GridCacheConsistentHashAffinityFunction) {
if (cfg.getEvictionPolicy() != null) { perf.add(msg, false); perf.add("Disable synchronized evictions (set 'evictSynchronized' to false)", !cfg.isEvictSynchronized()); if (cfg.getCacheMode() == PARTITIONED) { perf.add("Disable near cache (set 'partitionDistributionMode' to PARTITIONED_ONLY or CLIENT_ONLY)", cfg.getDistributionMode() != NEAR_PARTITIONED && cfg.getDistributionMode() != NEAR_ONLY); if (cfg.getAffinity() != null) perf.add("Decrease number of backups (set 'keyBackups' to 0)", cfg.getBackups() == 0); cfg.getAtomicityMode() == ATOMIC); cfg.getWriteSynchronizationMode() != FULL_SYNC); perf.add("Disable swap store (set 'swapEnabled' to false)", !cfg.isSwapEnabled()); if (cfg.getStore() != null) perf.add("Enable write-behind to persistent store (set 'writeBehindEnabled' to true)", cfg.isWriteBehindEnabled()); perf.add("Disable query index (set 'queryIndexEnabled' to false)", !cfg.isQueryIndexEnabled()); !cfg.isTxSerializableEnabled());
/** * @param ccfg Cache configuration. * @return Data transfer object for eviction configuration properties. */ public static VisorEvictionConfig from(GridCacheConfiguration ccfg) { VisorEvictionConfig cfg = new VisorEvictionConfig(); Integer policyMaxSize = null; final GridCacheEvictionPolicy policy = ccfg.getEvictionPolicy(); if (policy instanceof GridCacheLruEvictionPolicyMBean) policyMaxSize = ((GridCacheLruEvictionPolicyMBean)policy).getMaxSize(); else if (policy instanceof GridCacheRandomEvictionPolicyMBean) policyMaxSize = ((GridCacheRandomEvictionPolicyMBean)policy).getMaxSize(); else if (policy instanceof GridCacheFifoEvictionPolicyMBean) policyMaxSize = ((GridCacheFifoEvictionPolicyMBean)policy).getMaxSize(); cfg.policy(compactClass(ccfg.getEvictionPolicy())); cfg.policyMaxSize(policyMaxSize); cfg.filter(compactClass(ccfg.getEvictionFilter())); cfg.synchronizedConcurrencyLevel(ccfg.getEvictSynchronizedConcurrencyLevel()); cfg.synchronizedTimeout(ccfg.getEvictSynchronizedTimeout()); cfg.synchronizedKeyBufferSize(ccfg.getEvictSynchronizedKeyBufferSize()); cfg.evictSynchronized(ccfg.isEvictSynchronized()); cfg.nearSynchronized(ccfg.isEvictNearSynchronized()); cfg.maxOverflowRatio(ccfg.getEvictMaxOverflowRatio()); return cfg; }
throw new GridException("Data cache is not configured locally for GGFS: " + cfg); if (dataCache.configuration().isQueryIndexEnabled()) throw new GridException("GGFS data cache cannot start with enabled query indexing."); throw new GridException("Metadata cache is not configured locally for GGFS: " + cfg); if (metaCache.configuration().isQueryIndexEnabled()) throw new GridException("GGFS metadata cache cannot start with enabled query indexing."); 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); long offHeapSize = dataCache.configuration().getOffHeapMaxMemory(); if (dataCache.configuration().getCacheMode() == PARTITIONED) { int backups = dataCache.configuration().getBackups(); if (cfg.getMaxSpaceSize() == 0 && dataCache.configuration().getMemoryMode() == OFFHEAP_VALUES) U.warn(log, "GGFS max space size is not specified but data cache values are stored off-heap (max " + "space will be limited to 80% of max JVM heap size): " + cfg.getName());
/** * @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); }
/** * @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; }
/** * 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()); }
if (ccfg.getDrSenderConfiguration() != null) sysCaches.add(CU.cacheNameForDrSystemCache(ccfg.getName())); GridCacheConfiguration cfg = new GridCacheConfiguration(cfgs[i]); if (!sysCaches.contains(cfg.getName())) suggestOptimizations(cfg); if (cfg.getCacheMode() != LOCAL && (cfg.getDistributionMode() == CLIENT_ONLY || cfg.getDistributionMode() == NEAR_ONLY)) nearOrClientCaches.add(cfg.getName()); GridCacheJtaManagerAdapter jta = JTA.create(cfg.getTransactionManagerLookupClassName() == null); GridCacheVersionManager verMgr = new GridCacheVersionManager(); GridCacheEventManager evtMgr = new GridCacheEventManager(); GridCacheSwapManager swapMgr = new GridCacheSwapManager(cfg.getCacheMode() == LOCAL || !isNearEnabled(cfg)); GridCacheDgcManager dgcMgr = new GridCacheDgcManager(); GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager(); switch (cfg.getCacheMode()) { case LOCAL: { switch (cfg.getAtomicityMode()) { case TRANSACTIONAL: { cache = new GridLocalCache(cacheCtx); assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode(); case REPLICATED: {
/** * @return {@code True} if cache is replicated cache. */ public boolean isReplicated() { return cacheCfg.getCacheMode() == GridCacheMode.REPLICATED; }
/** * Creates a wrapped cache store if write-behind cache is configured. * * @param gridName Grid name. * @param cfg Cache configuration. * @param near Whether or not store retrieved for near cache. * @return Instance if {@link GridCacheWriteBehindStore} if write-behind store is configured, * or user-defined cache store. */ @SuppressWarnings({"unchecked"}) private GridCacheStore cacheStore(String gridName, GridCacheConfiguration cfg, boolean near) { if (cfg.getStore() == null || !cfg.isWriteBehindEnabled()) return cfg.getStore(); // Write-behind store is used in DHT cache only. if (!near) { GridCacheWriteBehindStore store = new GridCacheWriteBehindStore(gridName, cfg.getName(), log, cfg.getStore()); store.setFlushSize(cfg.getWriteBehindFlushSize()); store.setFlushThreadCount(cfg.getWriteBehindFlushThreadCount()); store.setFlushFrequency(cfg.getWriteBehindFlushFrequency()); store.setBatchSize(cfg.getWriteBehindBatchSize()); return store; } else return cfg.getStore(); }
/** * @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(); }
/** {@inheritDoc} */ @Override public void validateCacheConfiguration(GridCacheConfiguration cfg) throws GridException { GridCacheEvictionPolicy evictPlc = cfg.getEvictionPolicy(); if (evictPlc != null && evictPlc instanceof GridCacheGgfsPerBlockLruEvictionPolicy) { GridCacheEvictionFilter evictFilter = cfg.getEvictionFilter(); if (evictFilter != null && !(evictFilter instanceof GridCacheGgfsEvictionFilter)) throw new GridException("Eviction filter cannot be set explicitly when using " + "GridCacheGgfsPerBlockLruEvictionPolicy:" + cfg.getName()); } }
if (CU.isSystemCache(ccfg.getName())) continue; GridCacheConfiguration ccfgCp = new GridCacheConfiguration(ccfg); if (ccfgCp.getDistributionMode() == GridCacheDistributionMode.CLIENT_ONLY) ccfgCp.setDistributionMode(GridCacheDistributionMode.PARTITIONED_ONLY); else if (ccfgCp.getDistributionMode() == GridCacheDistributionMode.NEAR_ONLY) ccfgCp.setDistributionMode(GridCacheDistributionMode.NEAR_PARTITIONED); ccfgCp.setStore(null); ccfgCp.setWriteBehindEnabled(false);