Search in sources :

Example 11 with NearCacheConfiguration

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

the class GridCacheNearEvictionSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setBackups(1);
    cc.setRebalanceMode(SYNC);
    cc.setAtomicityMode(atomicityMode());
    NearCacheConfiguration nearCfg = new NearCacheConfiguration();
    cc.setNearConfiguration(nearCfg);
    c.setCacheConfiguration(cc);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setDiscoverySpi(disco);
    return c;
}
Also used : 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 12 with NearCacheConfiguration

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

the class GridCacheMultithreadedFailoverAbstractTest method configuration.

/**
     * Node configuration.
     *
     * @param idx Node index.
     * @return Node configuration.
     * @throws Exception If failed.
     */
private IgniteConfiguration configuration(int idx) throws Exception {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(CACHE_NAME);
    ccfg.setCacheMode(cacheMode());
    ccfg.setAtomicityMode(atomicityMode());
    ccfg.setRebalanceMode(SYNC);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setEvictionPolicy(null);
    if (cacheMode() == PARTITIONED)
        ccfg.setBackups(backups());
    if (atomicityMode() != ATOMIC && cacheMode() == PARTITIONED) {
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    }
    IgniteConfiguration cfg = getConfiguration(nodeName(idx));
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    discoSpi.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(discoSpi);
    cfg.setLocalHost("127.0.0.1");
    cfg.setCacheConfiguration(ccfg);
    cfg.setConnectorConfiguration(null);
    return cfg;
}
Also used : 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 13 with NearCacheConfiguration

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

the class IgniteCacheClientNodeChangingTopologyTest method lock.

/**
     * @param nearCfg Near cache configuration.
     * @throws Exception If failed.
     */
private void lock(NearCacheConfiguration nearCfg) throws Exception {
    ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setRebalanceMode(SYNC);
    ccfg.setNearConfiguration(nearCfg);
    final IgniteEx ignite0 = startGrid(0);
    final IgniteEx ignite1 = startGrid(1);
    awaitPartitionMapExchange();
    client = true;
    final Ignite ignite2 = startGrid(2);
    assertTrue(ignite2.configuration().isClientMode());
    final List<Integer> keys = new ArrayList<>();
    for (int i = 0; i < 100; i++) keys.add(i);
    TestCommunicationSpi spi = (TestCommunicationSpi) ignite2.configuration().getCommunicationSpi();
    spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id());
    spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id());
    final IgniteCache<Integer, Integer> cache = ignite2.cache(DEFAULT_CACHE_NAME);
    final CountDownLatch lockedLatch = new CountDownLatch(1);
    final CountDownLatch unlockLatch = new CountDownLatch(1);
    IgniteInternalFuture<Lock> lockFut = GridTestUtils.runAsync(new Callable<Lock>() {

        @Override
        public Lock call() throws Exception {
            Thread.currentThread().setName("put-thread");
            Lock lock = cache.lockAll(keys);
            lock.lock();
            log.info("Locked");
            lockedLatch.countDown();
            unlockLatch.await();
            lock.unlock();
            return lock;
        }
    });
    client = false;
    startGrid(3);
    log.info("Stop block.");
    assertEquals(1, lockedLatch.getCount());
    spi.stopBlock();
    assertTrue(lockedLatch.await(3000, TimeUnit.MILLISECONDS));
    IgniteCache<Integer, Integer> cache0 = ignite0.cache(DEFAULT_CACHE_NAME);
    for (Integer key : keys) {
        Lock lock = cache0.lock(key);
        assertFalse(lock.tryLock());
    }
    unlockLatch.countDown();
    lockFut.get();
    awaitPartitionMapExchange();
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (int i = 0; i < 4; i++) {
                if (!unlocked(ignite(i)))
                    return false;
            }
            return true;
        }

        private boolean unlocked(Ignite ignite) {
            IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
            for (Integer key : keys) {
                if (cache.isLocalLocked(key, false)) {
                    log.info("Key is locked [key=" + key + ", node=" + ignite.name() + ']');
                    return false;
                }
            }
            return true;
        }
    }, 10_000);
    assertTrue(wait);
    for (Integer key : keys) {
        Lock lock = cache0.lock(key);
        assertTrue("Failed to lock: " + key, lock.tryLock());
        lock.unlock();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) Lock(java.util.concurrent.locks.Lock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 14 with NearCacheConfiguration

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

the class GridDiscoveryManagerAliveCacheSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cCfg = defaultCacheConfiguration();
    cCfg.setCacheMode(PARTITIONED);
    cCfg.setBackups(1);
    cCfg.setNearConfiguration(new NearCacheConfiguration());
    cCfg.setRebalanceMode(SYNC);
    cCfg.setWriteSynchronizationMode(FULL_SYNC);
    TcpDiscoverySpi disc = new TcpDiscoverySpi();
    if (clientMode && ((igniteInstanceName.charAt(igniteInstanceName.length() - 1) - '0') & 1) != 0)
        cfg.setClientMode(true);
    else
        cfg.setClientFailureDetectionTimeout(50000);
    disc.setIpFinder(IP_FINDER);
    disc.setAckTimeout(1000);
    disc.setSocketTimeout(1000);
    cfg.setCacheConfiguration(cCfg);
    cfg.setDiscoverySpi(disc);
    cfg.setMetricsUpdateFrequency(500);
    return cfg;
}
Also used : 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 15 with NearCacheConfiguration

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

the class GridCachePutAllFailoverSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
    cfg.setPeerClassLoadingEnabled(false);
    cfg.setDeploymentMode(DeploymentMode.CONTINUOUS);
    TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
    discoverySpi.setAckTimeout(60000);
    discoverySpi.setIpFinder(ipFinder);
    discoverySpi.setForceServerMode(true);
    cfg.setDiscoverySpi(discoverySpi);
    if (igniteInstanceName.startsWith("master")) {
        cfg.setClientMode(true);
        cfg.setUserAttributes(ImmutableMap.of("segment", "master"));
        // For sure.
        failoverSpi.setMaximumFailoverAttempts(100);
        cfg.setFailoverSpi(failoverSpi);
    } else if (igniteInstanceName.startsWith("worker")) {
        cfg.setUserAttributes(ImmutableMap.of("segment", "worker"));
        CacheConfiguration cacheCfg = defaultCacheConfiguration();
        cacheCfg.setName("partitioned");
        cacheCfg.setAtomicityMode(atomicityMode());
        cacheCfg.setCacheMode(PARTITIONED);
        cacheCfg.setBackups(backups);
        cacheCfg.setNearConfiguration(nearEnabled ? new NearCacheConfiguration() : null);
        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
        cfg.setCacheConfiguration(cacheCfg);
    } else
        throw new IllegalStateException("Unexpected Ignite instance name: " + igniteInstanceName);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) 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