use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class GridOffHeapPartitionedMapPerformanceAbstractTest method beforeTest.
/** {@inheritDoc} */
@Override
protected void beforeTest() throws Exception {
map = newMap();
if (keys == null) {
keys = new T3[LOAD_CNT];
wrappers = new GridByteArrayWrapper[LOAD_CNT];
AffinityFunction aff = new RendezvousAffinityFunction();
Random rnd = new Random();
for (int i = 0; i < LOAD_CNT; i++) {
byte[] key = new byte[rnd.nextInt(511) + 1];
rnd.nextBytes(key);
GridByteArrayWrapper wrap = new GridByteArrayWrapper(key);
keys[i] = new T3<>(aff.partition(wrap), wrap.hashCode(), key);
wrappers[i] = wrap;
}
}
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class GridOffHeapPartitionedMapPerformanceAbstractTest method beforeTest.
/** {@inheritDoc} */
@Override
protected void beforeTest() throws Exception {
map = newMap();
if (keys == null) {
keys = new T3[LOAD_CNT];
wrappers = new GridByteArrayWrapper[LOAD_CNT];
AffinityFunction aff = new RendezvousAffinityFunction();
Random rnd = new Random();
for (int i = 0; i < LOAD_CNT; i++) {
byte[] key = new byte[rnd.nextInt(511) + 1];
rnd.nextBytes(key);
GridByteArrayWrapper wrap = new GridByteArrayWrapper(key);
keys[i] = new T3<>(aff.partition(wrap), wrap.hashCode(), key);
wrappers[i] = wrap;
}
}
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class GridCachePartitionedAffinityExcludeNeighborsPerformanceTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setIpFinder(ipFinder);
c.setDiscoverySpi(spi);
CacheConfiguration cc = defaultCacheConfiguration();
cc.setCacheMode(PARTITIONED);
cc.setBackups(2);
AffinityFunction aff = new RendezvousAffinityFunction(excNeighbores);
cc.setAffinity(aff);
cc.setRebalanceMode(NONE);
c.setCacheConfiguration(cc);
return c;
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class GridCachePartitionedPreloadEventsSelfTest method cacheConfiguration.
/** {@inheritDoc} */
@Override
protected CacheConfiguration cacheConfiguration() {
CacheConfiguration cacheCfg = super.cacheConfiguration();
if (replicatedAffinity)
// replicate entries to all nodes
cacheCfg.setAffinity(notSerializableProxy(new AffinityFunction() {
/** {@inheritDoc} */
@Override
public void reset() {
}
/** {@inheritDoc} */
@Override
public int partitions() {
return 1;
}
/** {@inheritDoc} */
@Override
public int partition(Object key) {
return 0;
}
/** {@inheritDoc} */
@Override
public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) {
List<ClusterNode> nodes = new ArrayList<>(affCtx.currentTopologySnapshot());
return Collections.singletonList(nodes);
}
/** {@inheritDoc} */
@Override
public void removeNode(UUID nodeId) {
}
}, AffinityFunction.class));
cacheCfg.setRebalanceDelay(rebalanceDelay);
return cacheCfg;
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class IgniteTxAbstractTest method checkRollback.
/**
* @param map Map to check.
* @param concurrency Concurrency.
* @param isolation Isolation.
* @throws IgniteCheckedException If check failed.
*/
protected void checkRollback(ConcurrentMap<Integer, String> map, TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
int gridIdx = RAND.nextInt(gridCount());
Ignite ignite = grid(gridIdx);
if (isTestDebug())
debug("Checking commit on grid: " + ignite.cluster().localNode().id());
for (int i = 0; i < iterations(); i++) {
IgniteCache<Integer, String> cache = jcache(gridIdx);
Transaction tx = ignite(gridIdx).transactions().txStart(concurrency, isolation, 0, 0);
try {
for (Integer key : getKeys()) {
if (isTestDebug()) {
AffinityFunction aff = cache.getConfiguration(CacheConfiguration.class).getAffinity();
int part = aff.partition(key);
debug("Key affinity [key=" + key + ", partition=" + part + ", affinity=" + U.toShortString(ignite(gridIdx).affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(part)) + ']');
}
String val = Integer.toString(key);
switch(getOp()) {
case READ:
{
debug("Reading key: " + key);
checkMap(map, key, cache.get(key));
break;
}
case WRITE:
{
debug("Writing key and value [key=" + key + ", val=" + val + ']');
checkMap(map, key, cache.getAndPut(key, val));
break;
}
case REMOVE:
{
debug("Removing key: " + key);
checkMap(map, key, cache.getAndRemove(key));
break;
}
default:
{
assert false;
}
}
}
tx.rollback();
debug("Rolled back transaction: " + tx);
} catch (TransactionOptimisticException e) {
tx.rollback();
log.warning("Rolled back transaction due to optimistic exception [tx=" + tx + ", e=" + e + ']');
throw e;
} catch (Exception e) {
tx.rollback();
error("Rolled back transaction due to exception [tx=" + tx + ", e=" + e + ']');
throw e;
} finally {
Transaction t1 = ignite(gridIdx).transactions().tx();
debug("t1=" + t1);
assert t1 == null : "Thread should not have transaction upon completion ['t==tx'=" + (t1 == tx) + ", t=" + t1 + ']';
}
}
}
Aggregations