Search in sources :

Example 86 with NearCacheConfiguration

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

the class GridCacheProcessor method prepareCacheStart.

/**
     * @param startCfg Start configuration.
     * @param reqNearCfg Near configuration if specified for client cache start request.
     * @param desc Cache descriptor.
     * @param exchTopVer Current exchange version.
     * @param schema Query schema.
     * @throws IgniteCheckedException If failed.
     */
private void prepareCacheStart(CacheConfiguration startCfg, @Nullable NearCacheConfiguration reqNearCfg, DynamicCacheDescriptor desc, AffinityTopologyVersion exchTopVer, @Nullable QuerySchema schema) throws IgniteCheckedException {
    assert !caches.containsKey(startCfg.getName()) : startCfg.getName();
    CacheConfiguration ccfg = new CacheConfiguration(startCfg);
    CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(ccfg);
    boolean affNode;
    if (ccfg.getCacheMode() == LOCAL) {
        affNode = true;
        ccfg.setNearConfiguration(null);
    } else if (CU.affinityNode(ctx.discovery().localNode(), ccfg.getNodeFilter()))
        affNode = true;
    else {
        affNode = false;
        ccfg.setNearConfiguration(reqNearCfg);
    }
    GridCacheContext cacheCtx = createCache(ccfg, null, desc, exchTopVer, cacheObjCtx, affNode, true);
    cacheCtx.dynamicDeploymentId(desc.deploymentId());
    GridCacheAdapter cache = cacheCtx.cache();
    sharedCtx.addCacheContext(cacheCtx);
    caches.put(cacheCtx.name(), cache);
    startCache(cache, schema != null ? schema : new QuerySchema());
    onKernalStart(cache);
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 87 with NearCacheConfiguration

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

the class AffinityClientNodeSelfTest method testClientNodeNotInAffinity.

/**
 * @throws Exception If failed.
 */
public void testClientNodeNotInAffinity() throws Exception {
    checkCache(CACHE1, 2);
    checkCache(CACHE2, 2);
    checkCache(CACHE4, 3);
    checkCache(CACHE5, 2);
    Ignite client = ignite(NODE_CNT - 1);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setBackups(0);
    ccfg.setNodeFilter(new TestNodesFilter());
    IgniteCache<Integer, Integer> cache = client.createCache(ccfg);
    try {
        checkCache(DEFAULT_CACHE_NAME, 1);
    } finally {
        cache.destroy();
    }
    cache = client.createCache(ccfg, new NearCacheConfiguration());
    try {
        checkCache(DEFAULT_CACHE_NAME, 1);
    } finally {
        cache.destroy();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 88 with NearCacheConfiguration

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

the class IgniteClientReconnectCacheTest method testReconnect.

/**
 * @throws Exception If failed.
 */
public void testReconnect() throws Exception {
    clientMode = true;
    IgniteEx client = startGrid(SRV_CNT);
    final TestTcpDiscoverySpi clientSpi = spi(client);
    Ignite srv = clientRouter(client);
    TestTcpDiscoverySpi srvSpi = spi(srv);
    final IgniteCache<Object, Object> cache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
    final IgniteCache<Object, Object> staticCache = client.cache(STATIC_CACHE);
    staticCache.put(1, 1);
    assertEquals(1, staticCache.get(1));
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setName("nearCache");
    final IgniteCache<Object, Object> nearCache = client.getOrCreateCache(ccfg, new NearCacheConfiguration<>());
    nearCache.put(1, 1);
    assertEquals(1, nearCache.localPeek(1));
    cache.put(1, 1);
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    final CountDownLatch reconnectLatch = new CountDownLatch(1);
    log.info("Block reconnect.");
    clientSpi.writeLatch = new CountDownLatch(1);
    final AtomicReference<IgniteInternalFuture> blockPutRef = new AtomicReference<>();
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                info("Disconnected: " + evt);
                assertEquals(1, reconnectLatch.getCount());
                blockPutRef.set(GridTestUtils.runAsync(new Callable() {

                    @Override
                    public Object call() throws Exception {
                        log.info("Start put.");
                        try {
                            cache.put(2, 2);
                            fail();
                        } catch (CacheException e) {
                            log.info("Expected exception: " + e);
                            IgniteClientDisconnectedException e0 = (IgniteClientDisconnectedException) e.getCause();
                            e0.reconnectFuture().get();
                        }
                        cache.put(2, 2);
                        log.info("Finish put.");
                        return null;
                    }
                }));
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                info("Reconnected: " + evt);
                assertEquals(0, disconnectLatch.getCount());
                reconnectLatch.countDown();
            }
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    log.info("Fail client.");
    srvSpi.failNode(client.cluster().localNode().id(), null);
    waitReconnectEvent(disconnectLatch);
    IgniteInternalFuture putFut = blockPutRef.get();
    assertNotDone(putFut);
    U.sleep(5000);
    assertNotDone(putFut);
    log.info("Allow reconnect.");
    clientSpi.writeLatch.countDown();
    assertTrue(reconnectLatch.await(5000, MILLISECONDS));
    checkCacheDiscoveryData(srv, client, DEFAULT_CACHE_NAME, true, true, false);
    checkCacheDiscoveryData(srv, client, "nearCache", true, true, true);
    checkCacheDiscoveryData(srv, client, STATIC_CACHE, true, true, false);
    assertEquals(1, cache.get(1));
    putFut.get();
    assertEquals(2, cache.get(2));
    cache.put(3, 3);
    assertEquals(3, cache.get(3));
    assertNull(nearCache.localPeek(1));
    staticCache.put(10, 10);
    assertEquals(10, staticCache.get(10));
    nearCache.put(20, 20);
    srv.cache(nearCache.getName()).put(20, 21);
    assertEquals(21, nearCache.localPeek(20));
    this.clientMode = false;
    IgniteEx srv2 = startGrid(SRV_CNT + 1);
    Integer key = primaryKey(srv2.cache(DEFAULT_CACHE_NAME));
    cache.put(key, 4);
    assertEquals(4, cache.get(key));
    checkCacheDiscoveryData(srv2, client, DEFAULT_CACHE_NAME, true, true, false);
    checkCacheDiscoveryData(srv2, client, "nearCache", true, true, true);
    checkCacheDiscoveryData(srv2, client, STATIC_CACHE, true, true, false);
    staticCache.put(20, 20);
    assertEquals(20, staticCache.get(20));
    srv.cache(nearCache.getName()).put(20, 22);
    assertEquals(22, nearCache.localPeek(20));
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 89 with NearCacheConfiguration

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

the class CacheClientStoreSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    boolean client = igniteInstanceName != null && igniteInstanceName.startsWith("client");
    cfg.setClientMode(client);
    if (client)
        cfg.setDataStorageConfiguration(new DataStorageConfiguration());
    CacheConfiguration cc = new CacheConfiguration(DEFAULT_CACHE_NAME);
    cc.setName(CACHE_NAME);
    cc.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    cc.setCacheMode(cacheMode);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setBackups(1);
    cc.setCacheStoreFactory(factory);
    if (factory instanceof Factory3)
        cc.setReadThrough(true);
    if (client && nearEnabled)
        cc.setNearConfiguration(new NearCacheConfiguration());
    cfg.setCacheConfiguration(cc);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(disco);
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 90 with NearCacheConfiguration

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

the class CacheDeferredDeleteSanitySelfTest method testDeferredDelete.

/**
 * @param mode Mode.
 * @param atomicityMode Atomicity mode.
 * @param near Near cache enabled.
 * @param expVal Expected deferred delete value.
 */
@SuppressWarnings("unchecked")
private void testDeferredDelete(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near, boolean expVal) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME).setCacheMode(mode).setAtomicityMode(atomicityMode);
    if (near)
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    IgniteCache cache = null;
    try {
        cache = grid(0).getOrCreateCache(ccfg);
        assertEquals(expVal, ((IgniteCacheProxy) grid(0).cache(DEFAULT_CACHE_NAME)).context().deferredDelete());
    } finally {
        if (cache != null)
            cache.destroy();
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) 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