Search in sources :

Example 81 with CacheConfiguration

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

the class GridCacheNearOneNodeSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration() throws Exception {
    IgniteConfiguration cfg = super.getConfiguration();
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));
    cfg.setDiscoverySpi(disco);
    CacheConfiguration cacheCfg = defaultCacheConfiguration();
    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setBackups(1);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setCacheStoreFactory(singletonFactory(store));
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    cfg.setCacheConfiguration(cacheCfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 82 with CacheConfiguration

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

the class GridCacheNearMetricsSelfTest method cacheConfiguration.

/** {@inheritDoc} */
@Override
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cc = super.cacheConfiguration(igniteInstanceName);
    cc.setCacheMode(CacheMode.PARTITIONED);
    cc.setBackups(1);
    return cc;
}
Also used : CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 83 with CacheConfiguration

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

the class GridCacheNearMultiGetSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings({ "ConstantConditions" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    c.getTransactionConfiguration().setTxSerializableEnabled(true);
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(PARTITIONED);
    cc.setBackups(1);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setRebalanceMode(NONE);
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setIpFinder(ipFinder);
    c.setFailureDetectionTimeout(Integer.MAX_VALUE);
    c.setDiscoverySpi(spi);
    c.setCacheConfiguration(cc);
    if (CACHE_DEBUG)
        resetLog4j(Level.DEBUG, false, GridCacheProcessor.class.getPackage().getName());
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 84 with CacheConfiguration

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

the class CacheContinuousQueryConcurrentPartitionUpdateTest method concurrentUpdatesAndQueryStart.

/**
     * @param atomicityMode Cache atomicity mode.
     * @throws Exception If failed.
     */
private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) throws Exception {
    Ignite srv = startGrid(0);
    client = true;
    Ignite client = startGrid(1);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    IgniteCache clientCache = client.createCache(ccfg);
    Affinity<Integer> aff = srv.affinity(DEFAULT_CACHE_NAME);
    final List<Integer> keys = new ArrayList<>();
    final int KEYS = 10;
    for (int i = 0; i < 100_000; i++) {
        if (aff.partition(i) == 0) {
            keys.add(i);
            if (keys.size() == KEYS)
                break;
        }
    }
    assertEquals(KEYS, keys.size());
    final int THREADS = 10;
    final int UPDATES = 1000;
    for (int i = 0; i < 5; i++) {
        log.info("Iteration: " + i);
        ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
        final AtomicInteger evtCnt = new AtomicInteger();
        qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

            @Override
            public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
                for (CacheEntryEvent evt : evts) {
                    assertNotNull(evt.getKey());
                    assertNotNull(evt.getValue());
                    if ((Integer) evt.getValue() >= 0)
                        evtCnt.incrementAndGet();
                }
            }
        });
        QueryCursor cur;
        final IgniteCache<Object, Object> srvCache = srv.cache(DEFAULT_CACHE_NAME);
        final AtomicBoolean stop = new AtomicBoolean();
        try {
            IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
                    while (!stop.get()) srvCache.put(keys.get(rnd.nextInt(KEYS)), rnd.nextInt(100) - 200);
                    return null;
                }
            }, THREADS, "update");
            U.sleep(1000);
            cur = clientCache.query(qry);
            U.sleep(1000);
            stop.set(true);
            fut.get();
        } finally {
            stop.set(true);
        }
        GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                for (int i = 0; i < UPDATES; i++) srvCache.put(keys.get(rnd.nextInt(KEYS)), i);
                return null;
            }
        }, THREADS, "update");
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                log.info("Events: " + evtCnt.get());
                return evtCnt.get() >= THREADS * UPDATES;
            }
        }, 5000);
        assertEquals(THREADS * UPDATES, evtCnt.get());
        cur.close();
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 85 with CacheConfiguration

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

the class GridServiceProcessorStopSelfTest method testStopDuringHangedDeployment.

/**
     * @throws Exception If failed.
     */
public void testStopDuringHangedDeployment() throws Exception {
    final CountDownLatch depLatch = new CountDownLatch(1);
    final CountDownLatch finishLatch = new CountDownLatch(1);
    final IgniteEx node0 = startGrid(0);
    final IgniteEx node1 = startGrid(1);
    final IgniteEx node2 = startGrid(2);
    final IgniteCache<Object, Object> cache = node2.getOrCreateCache(new CacheConfiguration<Object, Object>("def").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
    node0.services().deployNodeSingleton("myService", new TestServiceImpl());
    // Guarantee lock owner will never left topology unexpectedly.
    final Integer lockKey = keyForNode(node2.affinity("def"), new AtomicInteger(1), node2.cluster().localNode());
    // Lock to hold topology version undone.
    final Lock lock = cache.lock(lockKey);
    // Try to change topology once service has deployed.
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            depLatch.await();
            node1.close();
            return null;
        }
    }, "top-change-thread");
    // Stop node on unstable topology.
    GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            depLatch.await();
            Thread.sleep(1000);
            node0.close();
            finishLatch.countDown();
            return null;
        }
    }, "stopping-node-thread");
    assertNotNull(node0.services().service("myService"));
    // Freeze topology changing
    lock.lock();
    depLatch.countDown();
    boolean wait = finishLatch.await(15, TimeUnit.SECONDS);
    if (!wait)
        U.dumpThreads(log);
    assertTrue("Deploy future isn't completed", wait);
    fut.get();
    Ignition.stopAll(true);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) Lock(java.util.concurrent.locks.Lock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)980 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)392 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)287 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)250 Ignite (org.apache.ignite.Ignite)148 ArrayList (java.util.ArrayList)69 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)64 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)59 QueryEntity (org.apache.ignite.cache.QueryEntity)44 IgniteException (org.apache.ignite.IgniteException)43 CacheException (javax.cache.CacheException)42 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)40 IgniteEx (org.apache.ignite.internal.IgniteEx)40 IgniteCache (org.apache.ignite.IgniteCache)39 LinkedHashMap (java.util.LinkedHashMap)35 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)32 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)30 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)30 Transaction (org.apache.ignite.transactions.Transaction)28