Search in sources :

Example 16 with RendezvousAffinityFunction

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

the class CacheExchangeMessageDuplicatedStateTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    cfg.setClientMode(client);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    commSpi.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg.getClass() == GridDhtPartitionsSingleMessage.class || msg.getClass() == GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
        }
    });
    cfg.setCommunicationSpi(commSpi);
    List<CacheConfiguration> ccfgs = new ArrayList<>();
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE1);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE2);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF3_CACHE1);
        ccfg.setBackups(3);
        RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 64);
        ccfg.setAffinity(aff);
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE1);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE2);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 17 with RendezvousAffinityFunction

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

the class AtomicCacheAffinityConfigurationTest method testRendezvousAffinity.

/**
     * @throws Exception If failed.
     *
     */
public void testRendezvousAffinity() throws Exception {
    try {
        affinityFunction = new RendezvousAffinityFunction(false, 10);
        startGrids(3);
        for (int i = 0; i < 3; i++) {
            IgniteEx igniteEx = grid(i);
            CacheConfiguration cConf = igniteEx.context().cache().cache("ignite-atomics-sys-cache").configuration();
            AffinityFunction aff = cConf.getAffinity();
            assertNotNull(aff);
            assertEquals(aff.partitions(), affinityFunction.partitions());
            assertEquals(aff.getClass(), affinityFunction.getClass());
        }
        checkAtomics();
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 18 with RendezvousAffinityFunction

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

the class GridCacheDhtPreloadUnloadSelfTest method getConfiguration.

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

Example 19 with RendezvousAffinityFunction

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

the class IgniteCacheAbstractQuerySelfTest method cacheConfiguration.

/**
     * @return cache configuration
     */
protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(cacheMode());
    cc.setAtomicityMode(atomicityMode());
    cc.setNearConfiguration(nearCacheConfiguration());
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setCacheStoreFactory(new StoreFactory());
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);
    cc.setRebalanceMode(SYNC);
    cc.setSqlFunctionClasses(SqlFunctions.class);
    List<QueryEntity> entityList = new ArrayList<>();
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType(Type1.class.getName());
    qryEntity.addQueryField("id", Integer.class.getName(), null);
    qryEntity.addQueryField("name", String.class.getName(), null);
    qryEntity.setTableName("Type2");
    qryEntity.setIndexes(Arrays.asList(new QueryIndex("id")));
    entityList.add(qryEntity);
    qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType(Type2.class.getName());
    qryEntity.addQueryField("id", Integer.class.getName(), null);
    qryEntity.addQueryField("name", String.class.getName(), null);
    qryEntity.setTableName("Type1");
    qryEntity.setIndexes(Arrays.asList(new QueryIndex("id")));
    entityList.add(qryEntity);
    qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType(ObjectValue2.class.getName());
    qryEntity.addQueryField("strVal", String.class.getName(), null);
    // Default index type
    final QueryIndex strIdx = new QueryIndex();
    strIdx.setFieldNames(Collections.singletonList("strVal"), true);
    qryEntity.setIndexes(Arrays.asList(strIdx));
    entityList.add(qryEntity);
    cc.setQueryEntities(entityList);
    if (cacheMode() != CacheMode.LOCAL)
        cc.setAffinity(new RendezvousAffinityFunction());
    // Explicitly set number of backups equal to number of grids.
    if (cacheMode() == CacheMode.PARTITIONED)
        cc.setBackups(gridCount());
    return cc;
}
Also used : ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) QueryEntity(org.apache.ignite.cache.QueryEntity) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 20 with RendezvousAffinityFunction

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

the class IgniteCacheQueryNodeRestartSelfTest2 method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    MemoryConfiguration memCfg = new MemoryConfiguration().setDefaultMemoryPolicySize(50 * 1024 * 1024);
    c.setMemoryConfiguration(memCfg);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setDiscoverySpi(disco);
    int i = 0;
    CacheConfiguration<?, ?>[] ccs = new CacheConfiguration[4];
    for (String name : F.asList("pe", "pu")) {
        CacheConfiguration<?, ?> cc = defaultCacheConfiguration();
        cc.setName(name);
        cc.setCacheMode(PARTITIONED);
        cc.setBackups(2);
        cc.setWriteSynchronizationMode(FULL_SYNC);
        cc.setAtomicityMode(TRANSACTIONAL);
        cc.setRebalanceMode(SYNC);
        cc.setAffinity(new RendezvousAffinityFunction(false, 60));
        if (name.equals("pe")) {
            cc.setIndexedTypes(Integer.class, Person.class);
        } else if (name.equals("pu")) {
            cc.setIndexedTypes(AffinityKey.class, Purchase.class);
        }
        ccs[i++] = cc;
    }
    for (String name : F.asList("co", "pr")) {
        CacheConfiguration<?, ?> cc = defaultCacheConfiguration();
        cc.setName(name);
        cc.setCacheMode(REPLICATED);
        cc.setWriteSynchronizationMode(FULL_SYNC);
        cc.setAtomicityMode(TRANSACTIONAL);
        cc.setRebalanceMode(SYNC);
        cc.setAffinity(new RendezvousAffinityFunction(false, 50));
        if (name.equals("co")) {
            cc.setIndexedTypes(Integer.class, Company.class);
        } else if (name.equals("pr")) {
            cc.setIndexedTypes(Integer.class, Product.class);
        }
        ccs[i++] = cc;
    }
    c.setCacheConfiguration(ccs);
    return c;
}
Also used : MemoryConfiguration(org.apache.ignite.configuration.MemoryConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)73 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)64 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)35 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)34 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)8 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)7 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 Ignite (org.apache.ignite.Ignite)2 IgniteCache (org.apache.ignite.IgniteCache)2 QueryEntity (org.apache.ignite.cache.QueryEntity)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 MemoryConfiguration (org.apache.ignite.configuration.MemoryConfiguration)2 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)2 PlatformAffinityFunction (org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction)2 PlatformDotNetAffinityFunction (org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction)2 TestTcpCommunicationSpi (org.apache.ignite.util.TestTcpCommunicationSpi)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CacheLoader (javax.cache.integration.CacheLoader)1