Search in sources :

Example 41 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 42 with NearCacheConfiguration

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

the class IgniteDynamicClientCacheStartSelfTest method testReplicatedWithNearCacheClient.

/**
 * @throws Exception If failed.
 */
public void testReplicatedWithNearCacheClient() throws Exception {
    ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setNearConfiguration(new NearCacheConfiguration());
    ccfg.setCacheMode(REPLICATED);
    final String cacheName = DEFAULT_CACHE_NAME;
    Ignite ignite0 = startGrid(0);
    checkCache(ignite0, cacheName, true, false);
    client = true;
    final Ignite ignite1 = startGrid(1);
    checkCache(ignite1, cacheName, false, true);
    ccfg.setNearConfiguration(null);
    Ignite ignite2 = startGrid(2);
    checkCache(ignite2, cacheName, false, false);
    ccfg = null;
    Ignite ignite3 = startGrid(3);
    checkNoCache(ignite3, cacheName);
}
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 43 with NearCacheConfiguration

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

the class IgniteNearClientCacheCloseTest method cacheConfiguration.

/**
 * @param atomicityMode Cache atomicity mode.
 * @param nearCache {@code True} to enable near cache.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode, boolean nearCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    if (nearCache)
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setBackups(1);
    return ccfg;
}
Also used : NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 44 with NearCacheConfiguration

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

the class IgniteTxReentryAbstractSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    discoSpi.setIpFinder(IP_FINDER);
    cfg.setCommunicationSpi(new CountingCommunicationSpi());
    cfg.setDiscoverySpi(discoSpi);
    CacheConfiguration cacheCfg = defaultCacheConfiguration();
    cacheCfg.setCacheMode(cacheMode());
    cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    if (nearEnabled())
        cacheCfg.setNearConfiguration(new NearCacheConfiguration());
    cfg.setCacheConfiguration(cacheCfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) 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)

Example 45 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)

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