Search in sources :

Example 61 with RendezvousAffinityFunction

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

the class ClientAbstractMultiNodeSelfTest method cacheConfiguration.

/**
 * @param cacheName Cache name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
private CacheConfiguration cacheConfiguration(@NotNull String cacheName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();
    cfg.setAtomicityMode(TRANSACTIONAL);
    switch(cacheName) {
        case DEFAULT_CACHE_NAME:
            cfg.setCacheMode(LOCAL);
            break;
        case PARTITIONED_CACHE_NAME:
            cfg.setCacheMode(PARTITIONED);
            cfg.setBackups(0);
            break;
        default:
            cfg.setCacheMode(REPLICATED);
            break;
    }
    cfg.setName(cacheName);
    cfg.setWriteSynchronizationMode(REPLICATED_ASYNC_CACHE_NAME.equals(cacheName) ? FULL_ASYNC : FULL_SYNC);
    cfg.setAffinity(new RendezvousAffinityFunction());
    return cfg;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 62 with RendezvousAffinityFunction

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

the class PlatformConfigurationUtils method readAffinityFunction.

/**
 * Reads the eviction policy.
 *
 * @param in Stream.
 * @return Affinity function.
 */
public static PlatformAffinityFunction readAffinityFunction(BinaryRawReaderEx in) {
    byte plcTyp = in.readByte();
    if (plcTyp == 0)
        return null;
    int partitions = in.readInt();
    boolean exclNeighbours = in.readBoolean();
    byte overrideFlags = in.readByte();
    Object userFunc = in.readObjectDetached();
    AffinityFunction baseFunc = null;
    switch(plcTyp) {
        case 1:
            {
                throw new IllegalStateException("FairAffinityFunction");
            }
        case 2:
            {
                RendezvousAffinityFunction f = new RendezvousAffinityFunction();
                f.setPartitions(partitions);
                f.setExcludeNeighbors(exclNeighbours);
                baseFunc = f;
                break;
            }
        default:
            assert plcTyp == 3;
    }
    return new PlatformAffinityFunction(userFunc, partitions, overrideFlags, baseFunc);
}
Also used : PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction)

Example 63 with RendezvousAffinityFunction

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

the class CacheBaselineTopologyTest method testAffinityAssignmentChangedAfterRestart.

/**
 * @throws Exception if failed.
 */
public void testAffinityAssignmentChangedAfterRestart() throws Exception {
    delayRebalance = false;
    int parts = 32;
    final List<Integer> partMapping = new ArrayList<>();
    for (int p = 0; p < parts; p++) partMapping.add(p);
    final AffinityFunction affFunc = new TestAffinityFunction(new RendezvousAffinityFunction(false, parts));
    TestAffinityFunction.partsAffMapping = partMapping;
    String cacheName = CACHE_NAME + 2;
    startGrids(4);
    IgniteEx ig = grid(0);
    ig.cluster().active(true);
    IgniteCache<Integer, Integer> cache = ig.createCache(new CacheConfiguration<Integer, Integer>().setName(cacheName).setCacheMode(PARTITIONED).setBackups(1).setPartitionLossPolicy(READ_ONLY_SAFE).setReadFromBackup(true).setWriteSynchronizationMode(FULL_SYNC).setRebalanceDelay(-1).setAffinity(affFunc));
    Map<Integer, String> keyToConsId = new HashMap<>();
    for (int k = 0; k < 1000; k++) {
        cache.put(k, k);
        keyToConsId.put(k, ig.affinity(cacheName).mapKeyToNode(k).consistentId().toString());
    }
    stopAllGrids();
    Collections.shuffle(TestAffinityFunction.partsAffMapping, new Random(1));
    delayRebalance = true;
    startGrids(4);
    ig = grid(0);
    ig.active(true);
    cache = ig.cache(cacheName);
    GridDhtPartitionFullMap partMap = ig.cachex(cacheName).context().topology().partitionMap(false);
    for (int i = 1; i < 4; i++) {
        IgniteEx ig0 = grid(i);
        for (int p = 0; p < 32; p++) assertEqualsCollections(ig.affinity(cacheName).mapPartitionToPrimaryAndBackups(p), ig0.affinity(cacheName).mapPartitionToPrimaryAndBackups(p));
    }
    for (Map.Entry<Integer, String> e : keyToConsId.entrySet()) {
        int p = ig.affinity(cacheName).partition(e.getKey());
        assertEquals("p=" + p, GridDhtPartitionState.OWNING, partMap.get(ig.affinity(cacheName).mapKeyToNode(e.getKey()).id()).get(p));
    }
    for (int k = 0; k < 1000; k++) assertEquals("k=" + k, Integer.valueOf(k), cache.get(k));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) HashMap(java.util.HashMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)

Example 64 with RendezvousAffinityFunction

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

the class CrossCacheTxRandomOperationsTest method cacheConfiguration.

/**
 * @param name Cache name.
 * @param cacheMode Cache mode.
 * @param writeSync Write synchronization mode.
 * @param nearCache Near cache flag.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfiguration(String name, CacheMode cacheMode, CacheWriteSynchronizationMode writeSync, boolean nearCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(name);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(writeSync);
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(1);
    ccfg.setAffinity(new RendezvousAffinityFunction());
    if (nearCache)
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    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 65 with RendezvousAffinityFunction

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

the class IgniteCacheConfigurationTemplateTest method testTemplateCleanup.

/**
 * @throws Exception If failed.
 */
public void testTemplateCleanup() throws Exception {
    startGridsMultiThreaded(3);
    try {
        CacheConfiguration ccfg = new CacheConfiguration("affTemplate-*");
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ignite(0).addCacheConfiguration(ccfg);
        ignite(0).getOrCreateCache("affTemplate-1");
        IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache("affTemplate-2");
        ignite(0).destroyCache("affTemplate-1");
        startGrid(3);
        cache.put(1, 1);
        assertEquals(1, cache.get(1));
    } finally {
        stopAllGrids();
    }
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

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