use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class RendezvousAffinityFunctionSimpleBenchmark method assignPartitions.
/**
*
* @param aff Affinity function.
* @param nodes Topology.
* @param iter Number of iteration.
* @param prevAssignment Previous affinity assignment.
* @param backups Backups count.
* @return Tuple with affinity and time spend of the affinity calculation.
*/
private IgniteBiTuple<Long, List<List<ClusterNode>>> assignPartitions(AffinityFunction aff, List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int backups, int iter) {
GridAffinityFunctionContextImpl ctx = null;
switch(mode) {
case CHANGE_LAST_NODE:
ctx = nodesModificationChangeLast(nodes, prevAssignment, iter, backups);
break;
case CHANGE_FIRST_NODE:
ctx = nodesModificationChangeFirst(nodes, prevAssignment, iter, backups);
break;
case ADD:
ctx = new GridAffinityFunctionContextImpl(nodes, prevAssignment, addNode(nodes, iter), new AffinityTopologyVersion(nodes.size()), backups);
break;
case REMOVE_RANDOM:
ctx = new GridAffinityFunctionContextImpl(nodes, prevAssignment, removeNode(nodes, nodes.size() - 1), new AffinityTopologyVersion(nodes.size()), backups);
break;
case NONE:
ctx = new GridAffinityFunctionContextImpl(nodes, prevAssignment, new DiscoveryEvent(nodes.get(0), "", EventType.EVT_NODE_JOINED, nodes.get(nodes.size() - 1)), new AffinityTopologyVersion(nodes.size()), backups);
break;
}
long start = System.currentTimeMillis();
List<List<ClusterNode>> assignments = aff.assignPartitions(ctx);
return F.t(System.currentTimeMillis() - start, assignments);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class AbstractAffinityFunctionSelfTest method checkNodeRemoved.
/**
* @throws Exception If failed.
*/
protected void checkNodeRemoved(int backups, int neighborsPerHost, int neighborsPeriod) throws Exception {
AffinityFunction aff = affinityFunction();
int nodesCnt = 50;
List<ClusterNode> nodes = new ArrayList<>(nodesCnt);
List<List<ClusterNode>> prev = null;
for (int i = 0; i < nodesCnt; i++) {
info("======================================");
info("Assigning partitions: " + i);
info("======================================");
ClusterNode node = new GridTestNode(UUID.randomUUID());
if (neighborsPerHost > 0)
node.attribute(MAC_PREF + ((i / neighborsPeriod) % (nodesCnt / neighborsPerHost)));
nodes.add(node);
DiscoveryEvent discoEvt = new DiscoveryEvent(node, "", EventType.EVT_NODE_JOINED, node);
GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups);
List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
info("Assigned.");
verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
prev = assignment;
}
info("======================================");
info("Will remove nodes.");
info("======================================");
for (int i = 0; i < nodesCnt - 1; i++) {
info("======================================");
info("Assigning partitions: " + i);
info("======================================");
ClusterNode rmv = nodes.remove(nodes.size() - 1);
DiscoveryEvent discoEvt = new DiscoveryEvent(rmv, "", EventType.EVT_NODE_LEFT, rmv);
List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
info("Assigned.");
verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
prev = assignment;
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class RendezvousAffinityFunctionSimpleBenchmark method nodesModificationChangeFirst.
/**
* Modify the topology by remove the first node / add new node
*
* @param nodes Topology.
* @param prevAssignment Previous affinity.
* @param iter Number of iteration.
* @param backups Backups count.
* @return Affinity context.
*/
private GridAffinityFunctionContextImpl nodesModificationChangeFirst(List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int iter, int backups) {
DiscoveryEvent discoEvt;
discoEvt = iter % 2 == 0 ? addNode(nodes, iter) : removeNode(nodes, 0);
return new GridAffinityFunctionContextImpl(nodes, prevAssignment, discoEvt, new AffinityTopologyVersion(nodes.size()), backups);
}
Aggregations