Search in sources :

Example 6 with LruEvictionPolicy

use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.

the class CacheSerializableTransactionsTest method testNoOptimisticExceptionOnChangingTopology.

/**
 * @throws Exception If failed.
 */
public void testNoOptimisticExceptionOnChangingTopology() throws Exception {
    if (FAST)
        return;
    final AtomicBoolean finished = new AtomicBoolean();
    final List<String> cacheNames = new ArrayList<>();
    Ignite srv = ignite(1);
    try {
        {
            CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
            ccfg.setName("cache1");
            ccfg.setRebalanceMode(SYNC);
            srv.createCache(ccfg);
            cacheNames.add(ccfg.getName());
        }
        {
            // Store enabled.
            CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, false);
            ccfg.setName("cache2");
            ccfg.setRebalanceMode(SYNC);
            srv.createCache(ccfg);
            cacheNames.add(ccfg.getName());
        }
        {
            // Eviction.
            CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
            ccfg.setName("cache3");
            ccfg.setRebalanceMode(SYNC);
            LruEvictionPolicy plc = new LruEvictionPolicy();
            plc.setMaxSize(100);
            ccfg.setEvictionPolicy(plc);
            ccfg.setOnheapCacheEnabled(true);
            srv.createCache(ccfg);
            cacheNames.add(ccfg.getName());
        }
        IgniteInternalFuture<?> restartFut = restartFuture(finished, null);
        List<IgniteInternalFuture<?>> futs = new ArrayList<>();
        final int KEYS_PER_THREAD = 100;
        for (int i = 1; i < SRVS + CLIENTS; i++) {
            final Ignite node = ignite(i);
            final int minKey = i * KEYS_PER_THREAD;
            final int maxKey = minKey + KEYS_PER_THREAD;
            // Threads update non-intersecting keys, optimistic exception should not be thrown.
            futs.add(GridTestUtils.runAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    try {
                        log.info("Started update thread [node=" + node.name() + ", minKey=" + minKey + ", maxKey=" + maxKey + ']');
                        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
                        List<IgniteCache<Integer, Integer>> caches = new ArrayList<>();
                        for (String cacheName : cacheNames) caches.add(node.<Integer, Integer>cache(cacheName));
                        assertEquals(3, caches.size());
                        int iter = 0;
                        while (!finished.get()) {
                            int keyCnt = rnd.nextInt(1, 10);
                            final Set<Integer> keys = new LinkedHashSet<>();
                            while (keys.size() < keyCnt) keys.add(rnd.nextInt(minKey, maxKey));
                            for (final IgniteCache<Integer, Integer> cache : caches) {
                                doInTransaction(node, OPTIMISTIC, SERIALIZABLE, new Callable<Void>() {

                                    @Override
                                    public Void call() throws Exception {
                                        for (Integer key : keys) randomOperation(rnd, cache, key);
                                        return null;
                                    }
                                });
                            }
                            if (iter % 100 == 0)
                                log.info("Iteration: " + iter);
                            iter++;
                        }
                        return null;
                    } catch (Throwable e) {
                        log.error("Unexpected error: " + e, e);
                        throw e;
                    }
                }
            }, "update-thread-" + i));
        }
        U.sleep(60_000);
        finished.set(true);
        restartFut.get();
        for (IgniteInternalFuture<?> fut : futs) fut.get();
    } finally {
        finished.set(true);
        for (String cacheName : cacheNames) destroyCache(cacheName);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteException(org.apache.ignite.IgniteException) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)

Example 7 with LruEvictionPolicy

use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.

the class LruNearEvictionPolicySelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cc = new CacheConfiguration(DEFAULT_CACHE_NAME);
    cc.setCacheMode(PARTITIONED);
    cc.setAtomicityMode(atomicityMode);
    cc.setWriteSynchronizationMode(PRIMARY_SYNC);
    cc.setRebalanceMode(SYNC);
    cc.setBackups(0);
    NearCacheConfiguration nearCfg = new NearCacheConfiguration();
    LruEvictionPolicy plc = new LruEvictionPolicy();
    plc.setMaxSize(EVICTION_MAX_SIZE);
    nearCfg.setNearEvictionPolicy(plc);
    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) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 8 with LruEvictionPolicy

use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.

the class GridCacheReloadSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setLocalHost("127.0.0.1");
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
    ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500"));
    discoSpi.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(discoSpi);
    CacheConfiguration cacheCfg = defaultCacheConfiguration();
    cacheCfg.setName(CACHE_NAME);
    cacheCfg.setCacheMode(cacheMode);
    LruEvictionPolicy plc = new LruEvictionPolicy();
    plc.setMaxSize(MAX_CACHE_ENTRIES);
    cacheCfg.setEvictionPolicy(plc);
    cacheCfg.setOnheapCacheEnabled(true);
    cacheCfg.setNearConfiguration(nearEnabled ? new NearCacheConfiguration() : null);
    final CacheStore store = new CacheStoreAdapter<Integer, Integer>() {

        @Override
        public Integer load(Integer key) {
            return key;
        }

        @Override
        public void write(javax.cache.Cache.Entry<? extends Integer, ? extends Integer> e) {
        // No-op.
        }

        @Override
        public void delete(Object key) {
        // No-op.
        }
    };
    cacheCfg.setCacheStoreFactory(singletonFactory(store));
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    if (cacheMode == PARTITIONED)
        cacheCfg.setBackups(1);
    cfg.setCacheConfiguration(cacheCfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) CacheStoreAdapter(org.apache.ignite.cache.store.CacheStoreAdapter) CacheStore(org.apache.ignite.cache.store.CacheStore) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 9 with LruEvictionPolicy

use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.

the class IgniteCacheMultiTxLockSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setDiscoverySpi(disco);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(CACHE_NAME);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    ccfg.setBackups(2);
    ccfg.setCacheMode(PARTITIONED);
    LruEvictionPolicy plc = new LruEvictionPolicy();
    plc.setMaxSize(100000);
    ccfg.setEvictionPolicy(plc);
    ccfg.setOnheapCacheEnabled(true);
    c.setCacheConfiguration(ccfg);
    c.setClientMode(client);
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)

Example 10 with LruEvictionPolicy

use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.

the class PlatformConfigurationUtils method writeEvictionPolicy.

/**
 * Writes the eviction policy.
 * @param out Stream.
 * @param p Policy.
 */
@SuppressWarnings("TypeMayBeWeakened")
private static void writeEvictionPolicy(BinaryRawWriter out, EvictionPolicy p) {
    if (p instanceof FifoEvictionPolicy) {
        out.writeByte((byte) 1);
        FifoEvictionPolicy p0 = (FifoEvictionPolicy) p;
        out.writeInt(p0.getBatchSize());
        out.writeInt(p0.getMaxSize());
        out.writeLong(p0.getMaxMemorySize());
    } else if (p instanceof LruEvictionPolicy) {
        out.writeByte((byte) 2);
        LruEvictionPolicy p0 = (LruEvictionPolicy) p;
        out.writeInt(p0.getBatchSize());
        out.writeInt(p0.getMaxSize());
        out.writeLong(p0.getMaxMemorySize());
    } else
        out.writeByte((byte) 0);
}
Also used : FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)

Aggregations

LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)24 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)9 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)7 Duration (javax.cache.expiry.Duration)2 Ignite (org.apache.ignite.Ignite)2 IgniteCache (org.apache.ignite.IgniteCache)2 FifoEvictionPolicy (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)2 CacheStoreAdapter (org.apache.ignite.cache.store.CacheStoreAdapter)2 AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)2 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Callable (java.util.concurrent.Callable)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CacheException (javax.cache.CacheException)1 FactoryBuilder (javax.cache.configuration.FactoryBuilder)1