Search in sources :

Example 66 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteCacheReadThroughStoreCallTest method cacheConfiguration.

/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @param backups Number of backups.
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
protected CacheConfiguration<Object, Object> cacheConfiguration(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setCacheStoreFactory(new TestStoreFactory());
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);
    return ccfg;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 67 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteClientAffinityAssignmentSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    if (cache) {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        ccfg.setBackups(1);
        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        ccfg.setNearConfiguration(null);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, PARTS));
        cfg.setCacheConfiguration(ccfg);
    } else
        cfg.setClientMode(true);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 68 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteCacheInvokeReadThroughAbstractTest method cacheConfiguration.

/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @param backups Number of backups.
 * @param nearCache Near cache flag.
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups, boolean nearCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setCacheStoreFactory(cacheStoreFactory());
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
    if (nearCache)
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);
    return ccfg;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 69 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteCacheGroupsTest method testCacheIdSort.

/**
 * @throws Exception If failed.
 */
public void testCacheIdSort() throws Exception {
    Ignite node = startGrid(0);
    final List<IgniteCache> caches = new ArrayList<>(3);
    caches.add(node.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
    caches.add(node.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
    caches.add(node.createCache(cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
    Affinity aff = node.affinity("c1");
    final List<Integer> keys = new ArrayList<>();
    for (int i = 0; i < 1_000_000; i++) {
        if (aff.partition(i) == 0) {
            keys.add(i);
            if (keys.size() >= 10_000)
                break;
        }
    }
    assertEquals(10_000, keys.size());
    final long stopTime = System.currentTimeMillis() + 10_000;
    GridTestUtils.runMultiThreaded(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            while (System.currentTimeMillis() < stopTime) {
                for (int i = 0; i < 100; i++) {
                    IgniteCache cache = caches.get(rnd.nextInt(3));
                    Integer key = keys.get(rnd.nextInt(10_000));
                    if (rnd.nextFloat() > 0.8f)
                        cache.remove(key);
                    else
                        cache.put(key, key);
                }
            }
            return null;
        }
    }, 5, "update-thread");
    CacheGroupContext grp = cacheGroup(node, GROUP1);
    Integer cacheId = null;
    GridIterator<CacheDataRow> it = grp.offheap().partitionIterator(0);
    int c = 0;
    while (it.hasNext()) {
        CacheDataRow row = it.next();
        if (cacheId == null || cacheId != row.cacheId()) {
            cacheId = row.cacheId();
            c++;
        }
    }
    assertEquals(3, c);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteCache(org.apache.ignite.IgniteCache) ArrayList(java.util.ArrayList) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheExistsException(org.apache.ignite.cache.CacheExistsException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheException(javax.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Affinity(org.apache.ignite.cache.affinity.Affinity) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)

Example 70 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class GridCacheDhtPreloadDelayedSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    assert preloadMode != null;
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setRebalanceMode(preloadMode);
    cc.setRebalanceDelay(delay);
    cc.setAffinity(new RendezvousAffinityFunction(false, 128));
    cc.setBackups(1);
    cc.setAtomicityMode(TRANSACTIONAL);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setFailureDetectionTimeout(Integer.MAX_VALUE);
    c.setDiscoverySpi(disco);
    c.setCacheConfiguration(cc);
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)142 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)126 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)71 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)48 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)33 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Ignite (org.apache.ignite.Ignite)11 IgniteEx (org.apache.ignite.internal.IgniteEx)11 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)10 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)10 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)8 ArrayList (java.util.ArrayList)7 Random (java.util.Random)7 IgniteCache (org.apache.ignite.IgniteCache)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 QueryEntity (org.apache.ignite.cache.QueryEntity)4 Transaction (org.apache.ignite.transactions.Transaction)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)3