Search in sources :

Example 76 with NearCacheConfiguration

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

the class ClusterCachesInfo method onStateChangeRequest.

/**
 * @param msg Message.
 * @param topVer Current topology version.
 * @param curState Current cluster state.
 * @return Exchange action.
 * @throws IgniteCheckedException If configuration validation failed.
 */
public ExchangeActions onStateChangeRequest(ChangeGlobalStateMessage msg, AffinityTopologyVersion topVer, DiscoveryDataClusterState curState) throws IgniteCheckedException {
    ExchangeActions exchangeActions = new ExchangeActions();
    if (msg.activate() == curState.active())
        return exchangeActions;
    if (msg.activate()) {
        for (DynamicCacheDescriptor desc : orderedCaches(CacheComparators.DIRECT)) {
            desc.startTopologyVersion(topVer);
            DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(msg.requestId(), desc.cacheName(), msg.initiatorNodeId());
            req.startCacheConfiguration(desc.cacheConfiguration());
            req.cacheType(desc.cacheType());
            T2<CacheConfiguration, NearCacheConfiguration> locCfg = locCfgsForActivation.get(desc.cacheName());
            if (locCfg != null) {
                if (locCfg.get1() != null)
                    req.startCacheConfiguration(locCfg.get1());
                req.nearCacheConfiguration(locCfg.get2());
                req.locallyConfigured(true);
            }
            exchangeActions.addCacheToStart(req, desc);
        }
        for (CacheGroupDescriptor grpDesc : registeredCacheGroups().values()) exchangeActions.addCacheGroupToStart(grpDesc);
        List<StoredCacheData> storedCfgs = msg.storedCacheConfigurations();
        if (storedCfgs != null) {
            List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
            IgniteUuid deploymentId = msg.id();
            for (StoredCacheData storedCfg : storedCfgs) {
                CacheConfiguration ccfg = storedCfg.config();
                if (!registeredCaches.containsKey(ccfg.getName())) {
                    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(msg.requestId(), ccfg.getName(), msg.initiatorNodeId());
                    req.deploymentId(deploymentId);
                    req.startCacheConfiguration(ccfg);
                    req.cacheType(ctx.cache().cacheType(ccfg.getName()));
                    req.schema(new QuerySchema(storedCfg.queryEntities()));
                    req.sql(storedCfg.sql());
                    reqs.add(req);
                }
            }
            CacheChangeProcessResult res = processCacheChangeRequests(exchangeActions, reqs, topVer, true);
            if (!res.errs.isEmpty()) {
                IgniteCheckedException err = new IgniteCheckedException("Failed to activate cluster.");
                for (IgniteCheckedException err0 : res.errs) err.addSuppressed(err0);
                throw err;
            }
        }
    } else {
        locCfgsForActivation = new HashMap<>();
        for (DynamicCacheDescriptor desc : orderedCaches(CacheComparators.REVERSE)) {
            DynamicCacheChangeRequest req = DynamicCacheChangeRequest.stopRequest(ctx, desc.cacheName(), desc.sql(), false);
            exchangeActions.addCacheToStop(req, desc);
            if (ctx.discovery().cacheClientNode(ctx.discovery().localNode(), desc.cacheName()))
                locCfgsForActivation.put(desc.cacheName(), new T2<>((CacheConfiguration) null, (NearCacheConfiguration) null));
        }
        for (CacheGroupDescriptor grpDesc : registeredCacheGroups().values()) exchangeActions.addCacheGroupToStop(grpDesc, false);
    }
    return exchangeActions;
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) ArrayList(java.util.ArrayList) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) T2(org.apache.ignite.internal.util.typedef.T2)

Example 77 with NearCacheConfiguration

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

the class GridDhtPartitionsExchangeFuture method initCachesOnLocalJoin.

/**
 * @throws IgniteCheckedException If failed.
 */
private void initCachesOnLocalJoin() throws IgniteCheckedException {
    cctx.activate();
    LocalJoinCachesContext locJoinCtx = exchActions == null ? null : exchActions.localJoinContext();
    List<T2<DynamicCacheDescriptor, NearCacheConfiguration>> caches = locJoinCtx == null ? null : locJoinCtx.caches();
    if (!cctx.kernalContext().clientNode()) {
        List<DynamicCacheDescriptor> startDescs = new ArrayList<>();
        if (caches != null) {
            for (T2<DynamicCacheDescriptor, NearCacheConfiguration> c : caches) {
                DynamicCacheDescriptor startDesc = c.get1();
                if (CU.isPersistentCache(startDesc.cacheConfiguration(), cctx.gridConfig().getDataStorageConfiguration()))
                    startDescs.add(startDesc);
            }
        }
        cctx.database().readCheckpointAndRestoreMemory(startDescs);
    }
    cctx.cache().startCachesOnLocalJoin(locJoinCtx, initialVersion());
}
Also used : ArrayList(java.util.ArrayList) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) LocalJoinCachesContext(org.apache.ignite.internal.processors.cache.LocalJoinCachesContext) T2(org.apache.ignite.internal.util.typedef.T2) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 78 with NearCacheConfiguration

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

the class GridCacheVersionMultinodeTest method cacheConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
    assert atomicityMode != null;
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setNearConfiguration(near ? new NearCacheConfiguration() : null);
    return ccfg;
}
Also used : NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 79 with NearCacheConfiguration

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

the class CrossCacheTxRandomOperationsTest method cacheConfiguration.

/**
 * @param name Cache name.
 * @param cacheMode Cache mode.
 * @param writeSync Write synchronization mode.
 * @param nearCache Near cache flag.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfiguration(String name, CacheMode cacheMode, CacheWriteSynchronizationMode writeSync, boolean nearCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(name);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(writeSync);
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(1);
    ccfg.setAffinity(new RendezvousAffinityFunction());
    if (nearCache)
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    return ccfg;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 80 with NearCacheConfiguration

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

the class IgniteCacheGroupsTest method cacheApiTest.

/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @param backups Number of backups.
 * @param heapCache On heap cache flag.
 * @param nearSrv {@code True} if near cache should be used on a server side.
 * @param nearClient {@code True} if near cache should be used on a client side.
 * @throws Exception If failed.
 */
private void cacheApiTest(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups, boolean heapCache, boolean nearSrv, boolean nearClient) throws Exception {
    Ignite srv0 = ignite(0);
    NearCacheConfiguration nearCfg = nearSrv ? new NearCacheConfiguration() : null;
    srv0.createCache(cacheConfiguration(GROUP1, "cache-0", cacheMode, atomicityMode, backups, heapCache).setNearConfiguration(nearCfg));
    srv0.createCache(cacheConfiguration(GROUP1, "cache-1", cacheMode, atomicityMode, backups, heapCache));
    srv0.createCache(cacheConfiguration(GROUP2, "cache-2", cacheMode, atomicityMode, backups, heapCache).setNearConfiguration(nearCfg));
    srv0.createCache(cacheConfiguration(null, "cache-3", cacheMode, atomicityMode, backups, heapCache));
    if (nearClient) {
        Ignite clientNode = ignite(4);
        clientNode.createNearCache("cache-0", new NearCacheConfiguration());
        clientNode.createNearCache("cache-2", new NearCacheConfiguration());
    }
    try {
        for (final Ignite node : Ignition.allGrids()) {
            List<Callable<?>> ops = new ArrayList<>();
            for (int i = 0; i < 4; i++) ops.add(testSet(node.cache("cache-" + i), cacheMode, atomicityMode, backups, heapCache, node));
            // Async operations.
            GridTestUtils.runMultiThreaded(ops, "cacheApiTest");
        }
    } finally {
        for (int i = 0; i < 4; i++) srv0.destroyCache("cache-" + i);
    }
}
Also used : ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) Callable(java.util.concurrent.Callable) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Aggregations

NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)158 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)121 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)50 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)41 Ignite (org.apache.ignite.Ignite)37 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 IgniteCache (org.apache.ignite.IgniteCache)12 CacheException (javax.cache.CacheException)11 IgniteEx (org.apache.ignite.internal.IgniteEx)9 Transaction (org.apache.ignite.transactions.Transaction)9 ArrayList (java.util.ArrayList)8 IgniteException (org.apache.ignite.IgniteException)8 HashMap (java.util.HashMap)7 FifoEvictionPolicy (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)7 LinkedHashMap (java.util.LinkedHashMap)6 Callable (java.util.concurrent.Callable)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)6 QuerySchema (org.apache.ignite.internal.processors.query.QuerySchema)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6