use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class RendezvousAffinityFunctionSelfTest method affinityFunction.
/** {@inheritDoc} */
@Override
protected AffinityFunction affinityFunction() {
AffinityFunction aff = new RendezvousAffinityFunction();
GridTestUtils.setFieldValue(aff, "ignite", ignite);
return aff;
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class RendezvousAffinityFunctionSimpleBenchmark method testAffinityBenchmarkAdd.
/**
*
*/
public void testAffinityBenchmarkAdd() {
mode = TopologyModificationMode.ADD;
AffinityFunction aff0 = new RendezvousAffinityFunctionOld(true, 1024);
GridTestUtils.setFieldValue(aff0, "ignite", ignite);
affinityBenchmark(aff0, new RendezvousAffinityFunction(true, 1024));
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class AtomicCacheAffinityConfigurationTest method testRendezvousAffinity.
/**
* @throws Exception If failed.
*
*/
public void testRendezvousAffinity() throws Exception {
try {
affinityFunction = new RendezvousAffinityFunction(false, 10);
startGrids(3);
for (int i = 0; i < 3; i++) {
IgniteEx igniteEx = grid(i);
CacheConfiguration cConf = igniteEx.context().cache().cache("ignite-atomics-sys-cache").configuration();
AffinityFunction aff = cConf.getAffinity();
assertNotNull(aff);
assertEquals(aff.partitions(), affinityFunction.partitions());
assertEquals(aff.getClass(), affinityFunction.getClass());
}
checkAtomics();
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class IgniteTxAbstractTest method checkCommit.
/**
* @param concurrency Concurrency.
* @param isolation Isolation.
* @throws Exception If check failed.
*/
protected void checkCommit(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);
try (Transaction tx = ignite(gridIdx).transactions().txStart(concurrency, isolation, 0, 0)) {
int prevKey = -1;
for (Integer key : getKeys()) {
// Make sure we have the same locking order for all concurrent transactions.
assert key >= prevKey : "key: " + key + ", prevKey: " + prevKey;
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:
{
if (isTestDebug())
debug("Reading key [key=" + key + ", i=" + i + ']');
val = cache.get(key);
if (isTestDebug())
debug("Read value for key [key=" + key + ", val=" + val + ']');
break;
}
case WRITE:
{
if (isTestDebug())
debug("Writing key and value [key=" + key + ", val=" + val + ", i=" + i + ']');
cache.put(key, val);
break;
}
case REMOVE:
{
if (isTestDebug())
debug("Removing key [key=" + key + ", i=" + i + ']');
cache.remove(key);
break;
}
default:
{
assert false;
}
}
}
tx.commit();
if (isTestDebug())
debug("Committed transaction [i=" + i + ", tx=" + tx + ']');
} catch (TransactionOptimisticException e) {
if (!(concurrency == OPTIMISTIC && isolation == SERIALIZABLE)) {
log.error("Unexpected error: " + e, e);
throw e;
}
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
Transaction tx = ignite(gridIdx).transactions().tx();
assertNull("Thread should not have transaction upon completion", tx);
if (printMemoryStats()) {
if (cntr.getAndIncrement() % 100 == 0)
// Print transaction memory stats.
((IgniteKernal) grid(gridIdx)).internalCache(DEFAULT_CACHE_NAME).context().tm().printMemoryStats();
}
}
use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.
the class GridCacheAffinityApiSelfTest method testMapPartitionsToNode.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testMapPartitionsToNode() throws Exception {
Map<Integer, ClusterNode> map = grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionsToNodes(F.asList(0, 1, 5, 19, 12));
AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1);
AffinityFunction aff = affinity();
List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
for (Map.Entry<Integer, ClusterNode> e : map.entrySet()) assert F.eqNodes(F.first(nodes(assignment, aff, e.getKey())), e.getValue());
}
Aggregations