use of org.apache.ignite.cache.affinity.AffinityFunctionContext in project ignite by apache.
the class PlatformAffinityFunctionTarget method processOutStream.
/** {@inheritDoc} */
@Override
public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
if (type == OP_ASSIGN_PARTITIONS) {
AffinityFunctionContext affCtx = currentAffCtx.get();
if (affCtx == null)
throw new IgniteException("Thread-local AffinityFunctionContext is null. " + "This may indicate an unsupported call to the base AffinityFunction.");
final List<List<ClusterNode>> partitions = baseFunc.assignPartitions(affCtx);
PlatformAffinityUtils.writePartitionAssignment(partitions, writer, platformContext());
return;
}
super.processOutStream(type, writer);
}
use of org.apache.ignite.cache.affinity.AffinityFunctionContext in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayedAffinityCalculation.
/**
* Checks that new joined primary is not assigned immediately.
*
* @throws Exception If failed.
*/
public void testDelayedAffinityCalculation() throws Exception {
Ignite ignite0 = startServer(0, 1);
checkAffinity(1, topVer(1, 0), true);
GridCacheContext cctx = ((IgniteKernal) ignite0).context().cache().internalCache(CACHE_NAME1).context();
AffinityFunction func = cctx.config().getAffinity();
AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(ignite0.cluster().nodes()), null, null, topVer(1, 0), cctx.config().getBackups());
List<List<ClusterNode>> calcAff1_0 = func.assignPartitions(ctx);
startServer(1, 2);
ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(ignite0.cluster().nodes()), calcAff1_0, null, topVer(1, 0), cctx.config().getBackups());
List<List<ClusterNode>> calcAff2_0 = func.assignPartitions(ctx);
checkAffinity(2, topVer(2, 0), false);
List<List<ClusterNode>> aff2_0 = affinity(ignite0, topVer(2, 0), CACHE_NAME1);
for (int p = 0; p < calcAff1_0.size(); p++) {
List<ClusterNode> a1 = calcAff1_0.get(p);
List<ClusterNode> a2 = calcAff2_0.get(p);
List<ClusterNode> a = aff2_0.get(p);
// Primary did not change.
assertEquals(a1.get(0), a.get(0));
// New primary is backup.
if (!a1.get(0).equals(a2.get(0)))
assertTrue(a.contains(a2.get(0)));
}
checkAffinity(2, topVer(2, 1), true);
List<List<ClusterNode>> aff2_1 = affinity(ignite0, topVer(2, 1), CACHE_NAME1);
assertEquals(calcAff2_0, aff2_1);
}
use of org.apache.ignite.cache.affinity.AffinityFunctionContext in project ignite by apache.
the class GridCacheAffinityApiSelfTest method testPrimaryPartitionsOneNode.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testPrimaryPartitionsOneNode() throws Exception {
AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1);
List<List<ClusterNode>> assignment = affinity().assignPartitions(ctx);
for (ClusterNode node : grid(0).cluster().nodes()) {
int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).primaryPartitions(node);
assert !F.isEmpty(parts);
for (int p : parts) {
Collection<ClusterNode> owners = nodes(assignment, p);
assert !F.isEmpty(owners);
ClusterNode primary = F.first(owners);
assert F.eqNodes(node, primary);
}
}
}
use of org.apache.ignite.cache.affinity.AffinityFunctionContext 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());
}
use of org.apache.ignite.cache.affinity.AffinityFunctionContext in project ignite by apache.
the class GridCacheAffinityApiSelfTest method testMapPartitionsToNodeArray.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testMapPartitionsToNodeArray() 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