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;
}
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);
}
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));
}
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;
}
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();
}
}
Aggregations