Search in sources :

Example 1 with LocalAffinityFunction

use of org.apache.ignite.internal.processors.affinity.LocalAffinityFunction in project ignite by apache.

the class GridCacheUtils method initializeConfigDefaults.

/**
 * @param cfg Initializes cache configuration with proper defaults.
 * @param cacheObjCtx Cache object context.
 * @throws IgniteCheckedException If configuration is not valid.
 */
public static void initializeConfigDefaults(IgniteLogger log, CacheConfiguration cfg, CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
    if (cfg.getCacheMode() == null)
        cfg.setCacheMode(DFLT_CACHE_MODE);
    if (cfg.getNodeFilter() == null)
        cfg.setNodeFilter(CacheConfiguration.ALL_NODES);
    if (cfg.getAffinity() == null) {
        if (cfg.getCacheMode() == PARTITIONED) {
            RendezvousAffinityFunction aff = new RendezvousAffinityFunction();
            cfg.setAffinity(aff);
        } else if (cfg.getCacheMode() == REPLICATED) {
            RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 512);
            cfg.setAffinity(aff);
            cfg.setBackups(Integer.MAX_VALUE);
        } else
            cfg.setAffinity(new LocalAffinityFunction());
    } else {
        if (cfg.getCacheMode() == LOCAL && !(cfg.getAffinity() instanceof LocalAffinityFunction)) {
            cfg.setAffinity(new LocalAffinityFunction());
            U.warn(log, "AffinityFunction configuration parameter will be ignored for local cache" + " [cacheName=" + U.maskName(cfg.getName()) + ']');
        }
    }
    validateKeyConfigiration(cfg.getGroupName(), cfg.getName(), cfg.getKeyConfiguration(), log, true);
    if (cfg.getCacheMode() == REPLICATED)
        cfg.setBackups(Integer.MAX_VALUE);
    if (cfg.getQueryParallelism() > 1 && cfg.getCacheMode() != PARTITIONED)
        throw new IgniteCheckedException("Segmented indices are supported for PARTITIONED mode only.");
    if (cfg.getAffinityMapper() == null)
        cfg.setAffinityMapper(cacheObjCtx.defaultAffMapper());
    if (cfg.getRebalanceMode() == null)
        cfg.setRebalanceMode(ASYNC);
    if (cfg.getAtomicityMode() == null)
        cfg.setAtomicityMode(CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE);
    if (cfg.getWriteSynchronizationMode() == null)
        cfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    assert cfg.getWriteSynchronizationMode() != null;
    if (cfg.getCacheStoreFactory() == null) {
        Factory<CacheLoader> ldrFactory = cfg.getCacheLoaderFactory();
        Factory<CacheWriter> writerFactory = cfg.isWriteThrough() ? cfg.getCacheWriterFactory() : null;
        if (ldrFactory != null || writerFactory != null)
            cfg.setCacheStoreFactory(new GridCacheLoaderWriterStoreFactory(ldrFactory, writerFactory));
    } else {
        if (cfg.getCacheLoaderFactory() != null)
            throw new IgniteCheckedException("Cannot set both cache loaded factory and cache store factory " + "for cache: " + U.maskName(cfg.getName()));
        if (cfg.getCacheWriterFactory() != null)
            throw new IgniteCheckedException("Cannot set both cache writer factory and cache store factory " + "for cache: " + U.maskName(cfg.getName()));
    }
    Collection<QueryEntity> entities = cfg.getQueryEntities();
    if (!F.isEmpty(entities)) {
        cfg.clearQueryEntities().setQueryEntities(QueryUtils.normalizeQueryEntities(cacheObjCtx.kernalContext(), entities, cfg));
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheWriter(javax.cache.integration.CacheWriter) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheLoader(javax.cache.integration.CacheLoader) QueryEntity(org.apache.ignite.cache.QueryEntity) LocalAffinityFunction(org.apache.ignite.internal.processors.affinity.LocalAffinityFunction)

Aggregations

CacheLoader (javax.cache.integration.CacheLoader)1 CacheWriter (javax.cache.integration.CacheWriter)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 LocalAffinityFunction (org.apache.ignite.internal.processors.affinity.LocalAffinityFunction)1