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