Search in sources :

Example 76 with RendezvousAffinityFunction

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

the class IgniteCacheGroupsTest method scanQueryMultiplePartitions.

/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Cache atomicity mode.
 * @throws Exception If failed.
 */
private void scanQueryMultiplePartitions(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
    int keys = 10000;
    Integer[] data1 = generateData(keys);
    Integer[] data2 = generateData(keys);
    startGridsMultiThreaded(4);
    Ignite srv0 = ignite(0);
    srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false).setAffinity(new RendezvousAffinityFunction().setPartitions(32)));
    srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false).setAffinity(new RendezvousAffinityFunction().setPartitions(32)));
    awaitPartitionMapExchange();
    IgniteCache<Integer, Integer> cache1;
    IgniteCache<Integer, Integer> cache2;
    if (atomicityMode == TRANSACTIONAL) {
        Ignite ignite = ignite(1);
        cache1 = ignite.cache(CACHE1);
        cache2 = ignite.cache(CACHE2);
        try (Transaction tx = ignite.transactions().txStart()) {
            for (int i = 0; i < keys; i++) {
                cache1.put(i, data1[i]);
                cache2.put(i, data2[i]);
            }
            tx.commit();
        }
    } else {
        // Async put ops.
        int ldrs = 4;
        List<Callable<?>> cls = new ArrayList<>(ldrs * 2);
        for (int i = 0; i < ldrs; i++) {
            cls.add(putOperation(1, ldrs, i, CACHE1, data1));
            cls.add(putOperation(2, ldrs, i, CACHE2, data2));
        }
        GridTestUtils.runMultiThreaded(cls, "loaders");
    }
    int p = ThreadLocalRandom.current().nextInt(32);
    ScanQuery<Integer, Integer> qry = new ScanQuery().setPartition(p);
    Set<Integer> keysSet = new TreeSet<>();
    cache1 = ignite(3).cache(CACHE1);
    Affinity<Integer> aff = affinity(cache1);
    for (int i = 0; i < keys; i++) {
        if (aff.partition(i) == p)
            keysSet.add(i);
    }
    for (Cache.Entry<Integer, Integer> entry : cache1.query(qry)) {
        assertTrue(keysSet.remove(entry.getKey()));
        assertEquals(data1[entry.getKey()], entry.getValue());
    }
    assertTrue(keysSet.isEmpty());
    srv0.destroyCache(CACHE1);
    keysSet = new TreeSet<>();
    cache2 = ignite(3).cache(CACHE2);
    aff = affinity(cache2);
    for (int i = 0; i < keys; i++) {
        if (aff.partition(i) == p)
            keysSet.add(i);
    }
    for (Cache.Entry<Integer, Integer> entry : cache2.query(qry)) {
        assertTrue(keysSet.remove(entry.getKey()));
        assertEquals(data2[entry.getKey()], entry.getValue());
    }
    assertTrue(keysSet.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) ScanQuery(org.apache.ignite.cache.query.ScanQuery) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) Callable(java.util.concurrent.Callable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) TreeSet(java.util.TreeSet) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 77 with RendezvousAffinityFunction

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

the class IgniteCacheGroupsTest method checkAffinityMappers.

/**
 * @param node Node.
 */
private void checkAffinityMappers(Ignite node) {
    Affinity aff1 = node.affinity("c1");
    Affinity aff2 = node.affinity("c2");
    Affinity aff3 = node.affinity("c3");
    Affinity aff4 = node.affinity("c4");
    Affinity aff5 = node.affinity("c5");
    Affinity aff6 = node.affinity("c6");
    RendezvousAffinityFunction func = new RendezvousAffinityFunction();
    for (int i = 0; i < 100; i++) {
        MapperTestKey1 k = new MapperTestKey1(i, i + 10);
        assertEquals(i, aff1.partition(k));
        assertEquals(i, aff3.partition(k));
        assertEquals(i + 10, aff2.partition(k));
        assertEquals(i + 10, aff4.partition(k));
        int part;
        if (node.configuration().getMarshaller() instanceof BinaryMarshaller)
            part = func.partition(node.binary().toBinary(k));
        else
            part = func.partition(k);
        assertEquals(part, aff5.partition(k));
        assertEquals(part, aff6.partition(k));
    }
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Affinity(org.apache.ignite.cache.affinity.Affinity) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)

Example 78 with RendezvousAffinityFunction

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

the class GridCacheAbstractLocalStoreSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cacheCfg = cache(igniteInstanceName, DEFAULT_CACHE_NAME, 0);
    cacheCfg.setAffinity(new RendezvousAffinityFunction());
    CacheConfiguration cacheBackup1Cfg = cache(igniteInstanceName, BACKUP_CACHE_1, 1);
    cacheBackup1Cfg.setAffinity(new RendezvousAffinityFunction());
    CacheConfiguration cacheBackup2Cfg = cache(igniteInstanceName, BACKUP_CACHE_2, 2);
    cacheBackup2Cfg.setAffinity(new RendezvousAffinityFunction());
    cfg.setCacheConfiguration(cacheCfg, cacheBackup1Cfg, cacheBackup2Cfg);
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(spi);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 79 with RendezvousAffinityFunction

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

the class GridCachePartitionNotLoadedEventSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(disco);
    if (igniteInstanceName.matches(".*\\d")) {
        String idStr = UUID.randomUUID().toString();
        char[] chars = idStr.toCharArray();
        chars[chars.length - 3] = '0';
        chars[chars.length - 2] = '0';
        chars[chars.length - 1] = igniteInstanceName.charAt(igniteInstanceName.length() - 1);
        cfg.setNodeId(UUID.fromString(new String(chars)));
    }
    cfg.setCommunicationSpi(new TestTcpCommunicationSpi());
    CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setBackups(backupCnt);
    cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    cacheCfg.setAffinity(new RendezvousAffinityFunction(false, 32));
    cfg.setCacheConfiguration(cacheCfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestTcpCommunicationSpi(org.apache.ignite.util.TestTcpCommunicationSpi) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 80 with RendezvousAffinityFunction

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

the class GridCachePreloadRestartAbstractSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    // Discovery.
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setDiscoverySpi(disco);
    c.setDeploymentMode(CONTINUOUS);
    // Cache.
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setName(CACHE_NAME);
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(preloadMode);
    cc.setRebalanceBatchSize(preloadBatchSize);
    cc.setAffinity(new RendezvousAffinityFunction(false, partitions));
    cc.setBackups(backups);
    cc.setAtomicityMode(TRANSACTIONAL);
    if (!nearEnabled())
        cc.setNearConfiguration(null);
    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