use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class IgniteCacheReadThroughStoreCallTest method cacheConfiguration.
/**
* @param cacheMode Cache mode.
* @param atomicityMode Atomicity mode.
* @param backups Number of backups.
* @return Cache configuration.
*/
@SuppressWarnings("unchecked")
protected CacheConfiguration<Object, Object> cacheConfiguration(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
ccfg.setCacheStoreFactory(new TestStoreFactory());
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setCacheMode(cacheMode);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
if (cacheMode == PARTITIONED)
ccfg.setBackups(backups);
return ccfg;
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class IgniteClientAffinityAssignmentSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
if (cache) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(CacheMode.PARTITIONED);
ccfg.setBackups(1);
ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
ccfg.setNearConfiguration(null);
ccfg.setAffinity(new RendezvousAffinityFunction(false, PARTS));
cfg.setCacheConfiguration(ccfg);
} else
cfg.setClientMode(true);
return cfg;
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class IgniteCacheInvokeReadThroughAbstractTest method cacheConfiguration.
/**
* @param cacheMode Cache mode.
* @param atomicityMode Atomicity mode.
* @param backups Number of backups.
* @param nearCache Near cache flag.
* @return Cache configuration.
*/
@SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups, boolean nearCache) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
ccfg.setCacheStoreFactory(cacheStoreFactory());
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setCacheMode(cacheMode);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
if (nearCache)
ccfg.setNearConfiguration(new NearCacheConfiguration());
if (cacheMode == PARTITIONED)
ccfg.setBackups(backups);
return ccfg;
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class IgniteCacheGroupsTest method testCacheIdSort.
/**
* @throws Exception If failed.
*/
public void testCacheIdSort() throws Exception {
Ignite node = startGrid(0);
final List<IgniteCache> caches = new ArrayList<>(3);
caches.add(node.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
caches.add(node.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
caches.add(node.createCache(cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
Affinity aff = node.affinity("c1");
final List<Integer> keys = new ArrayList<>();
for (int i = 0; i < 1_000_000; i++) {
if (aff.partition(i) == 0) {
keys.add(i);
if (keys.size() >= 10_000)
break;
}
}
assertEquals(10_000, keys.size());
final long stopTime = System.currentTimeMillis() + 10_000;
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (System.currentTimeMillis() < stopTime) {
for (int i = 0; i < 100; i++) {
IgniteCache cache = caches.get(rnd.nextInt(3));
Integer key = keys.get(rnd.nextInt(10_000));
if (rnd.nextFloat() > 0.8f)
cache.remove(key);
else
cache.put(key, key);
}
}
return null;
}
}, 5, "update-thread");
CacheGroupContext grp = cacheGroup(node, GROUP1);
Integer cacheId = null;
GridIterator<CacheDataRow> it = grp.offheap().partitionIterator(0);
int c = 0;
while (it.hasNext()) {
CacheDataRow row = it.next();
if (cacheId == null || cacheId != row.cacheId()) {
cacheId = row.cacheId();
c++;
}
}
assertEquals(3, c);
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class GridCacheDhtPreloadDelayedSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
assert preloadMode != null;
CacheConfiguration cc = defaultCacheConfiguration();
cc.setCacheMode(PARTITIONED);
cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cc.setRebalanceMode(preloadMode);
cc.setRebalanceDelay(delay);
cc.setAffinity(new RendezvousAffinityFunction(false, 128));
cc.setBackups(1);
cc.setAtomicityMode(TRANSACTIONAL);
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(ipFinder);
c.setFailureDetectionTimeout(Integer.MAX_VALUE);
c.setDiscoverySpi(disco);
c.setCacheConfiguration(cc);
return c;
}
Aggregations