Search in sources :

Example 1 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class JdbcThinDynamicIndexAbstractSelfTest method cacheConfig.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
CacheConfiguration cacheConfig() {
    CacheConfiguration ccfg = super.cacheConfig();
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setCacheMode(cacheMode());
    ccfg.setAtomicityMode(atomicityMode());
    if (nearCache())
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    return ccfg;
}
Also used : NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 2 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheProcessor method prepareCacheChangeRequest.

/**
     * Prepares DynamicCacheChangeRequest for cache creation.
     *
     * @param ccfg Cache configuration
     * @param cacheName Cache name
     * @param nearCfg Near cache configuration
     * @param cacheType Cache type
     * @param sql Whether the cache needs to be created as the result of SQL {@code CREATE TABLE} command.
     * @param failIfExists Fail if exists flag.
     * @param failIfNotStarted If {@code true} fails if cache is not started.
     * @return Request or {@code null} if cache already exists.
     * @throws IgniteCheckedException if some of pre-checks failed
     * @throws CacheExistsException if cache exists and failIfExists flag is {@code true}
     */
private DynamicCacheChangeRequest prepareCacheChangeRequest(@Nullable CacheConfiguration ccfg, String cacheName, @Nullable NearCacheConfiguration nearCfg, CacheType cacheType, boolean sql, boolean failIfExists, boolean failIfNotStarted) throws IgniteCheckedException {
    DynamicCacheDescriptor desc = cacheDescriptor(cacheName);
    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
    req.sql(sql);
    req.failIfExists(failIfExists);
    if (ccfg != null) {
        cloneCheckSerializable(ccfg);
        if (desc != null) {
            if (failIfExists) {
                throw new CacheExistsException("Failed to start cache " + "(a cache with the same name is already started): " + cacheName);
            } else {
                CacheConfiguration descCfg = desc.cacheConfiguration();
                // Check if we were asked to start a near cache.
                if (nearCfg != null) {
                    if (CU.affinityNode(ctx.discovery().localNode(), descCfg.getNodeFilter())) {
                        // If we are on a data node and near cache was enabled, return success, else - fail.
                        if (descCfg.getNearConfiguration() != null)
                            return null;
                        else
                            throw new IgniteCheckedException("Failed to start near " + "cache (local node is an affinity node for cache): " + cacheName);
                    } else
                        // If local node has near cache, return success.
                        req.clientStartOnly(true);
                } else
                    req.clientStartOnly(true);
                req.deploymentId(desc.deploymentId());
                req.startCacheConfiguration(descCfg);
                req.schema(desc.schema());
            }
        } else {
            req.deploymentId(IgniteUuid.randomUuid());
            CacheConfiguration cfg = new CacheConfiguration(ccfg);
            CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
            initialize(cfg, cacheObjCtx);
            req.startCacheConfiguration(cfg);
            req.schema(new QuerySchema(cfg.getQueryEntities()));
        }
    } else {
        req.clientStartOnly(true);
        if (desc != null)
            ccfg = desc.cacheConfiguration();
        if (ccfg == null) {
            if (failIfNotStarted) {
                throw new CacheExistsException("Failed to start client cache " + "(a cache with the given name is not started): " + cacheName);
            } else
                return null;
        }
        req.deploymentId(desc.deploymentId());
        req.startCacheConfiguration(ccfg);
        req.schema(desc.schema());
    }
    if (nearCfg != null)
        req.nearCacheConfiguration(nearCfg);
    req.cacheType(cacheType);
    return req;
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheExistsException(org.apache.ignite.cache.CacheExistsException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 3 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheProcessor method lifecycleAwares.

/**
     * @param ccfg Cache configuration.
     * @param objs Extra components.
     * @return Components provided in cache configuration which can implement {@link LifecycleAware} interface.
     */
private Iterable<Object> lifecycleAwares(CacheConfiguration ccfg, Object... objs) {
    Collection<Object> ret = new ArrayList<>(7 + objs.length);
    ret.add(ccfg.getAffinity());
    ret.add(ccfg.getAffinityMapper());
    ret.add(ccfg.getEvictionFilter());
    ret.add(ccfg.getEvictionPolicy());
    ret.add(ccfg.getInterceptor());
    ret.add(ccfg.getTopologyValidator());
    NearCacheConfiguration nearCfg = ccfg.getNearConfiguration();
    if (nearCfg != null)
        ret.add(nearCfg.getNearEvictionPolicy());
    Collections.addAll(ret, objs);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 4 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class PlatformProcessorImpl method getOrCreateNearCache.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy getOrCreateNearCache(@Nullable String cacheName, long memPtr) {
    NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
    IgniteCacheProxy cache = (IgniteCacheProxy) ctx.grid().getOrCreateNearCache(cacheName, cfg);
    return createPlatformCache(cache);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 5 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class PlatformProcessorImpl method createNearCache.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy createNearCache(@Nullable String cacheName, long memPtr) {
    NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
    IgniteCacheProxy cache = (IgniteCacheProxy) ctx.grid().createNearCache(cacheName, cfg);
    return createPlatformCache(cache);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Aggregations

NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)140 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)110 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)45 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)38 Ignite (org.apache.ignite.Ignite)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 CacheException (javax.cache.CacheException)11 IgniteCache (org.apache.ignite.IgniteCache)11 IgniteEx (org.apache.ignite.internal.IgniteEx)9 IgniteException (org.apache.ignite.IgniteException)8 Transaction (org.apache.ignite.transactions.Transaction)8 FifoEvictionPolicy (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)7 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Callable (java.util.concurrent.Callable)5 TimeoutException (java.util.concurrent.TimeoutException)5 LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)5 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4