本文整理汇总了Java中org.apache.ignite.events.EventType.EVT_NODE_JOINED属性的典型用法代码示例。如果您正苦于以下问题:Java EventType.EVT_NODE_JOINED属性的具体用法?Java EventType.EVT_NODE_JOINED怎么用?Java EventType.EVT_NODE_JOINED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.ignite.events.EventType
的用法示例。
在下文中一共展示了EventType.EVT_NODE_JOINED属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNode
/**
* @param nodes Topology.
* @param iter Iteration count.
* @return Discovery event.
*/
@NotNull private DiscoveryEvent addNode(List<ClusterNode> nodes, int iter) {
GridTestNode node = new GridTestNode(UUID.randomUUID());
// two neighbours nodes
node.setAttribute(IgniteNodeAttributes.ATTR_MACS, MAC_PREF + "_add_" + iter / 4);
nodes.add(node);
return new DiscoveryEvent(nodes.get(0), "", EventType.EVT_NODE_JOINED, node);
}
示例2: 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);
}
示例3: beforeExchange
/** {@inheritDoc} */
@Override public void beforeExchange(GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException {
DiscoveryEvent discoEvt = fut.firstEvent();
boolean joinEvt = discoEvt.type() == EventType.EVT_NODE_JOINED;
boolean locNode = discoEvt.eventNode().isLocal();
boolean isSrvNode = !cctx.kernalContext().clientNode();
boolean clusterInTransitionStateToActive = fut.activateCluster();
// Before local node join event.
if (clusterInTransitionStateToActive || (joinEvt && locNode && isSrvNode))
restoreState();
if (cctx.kernalContext().query().moduleEnabled()) {
for (final GridCacheContext cacheCtx : (Collection<GridCacheContext>)cctx.cacheContexts()) {
if (cacheCtx.startTopologyVersion().equals(fut.initialVersion()) &&
!cctx.pageStore().hasIndexStore(cacheCtx.groupId()) && cacheCtx.affinityNode()) {
final int cacheId = cacheCtx.cacheId();
final IgniteInternalFuture<?> rebuildFut = cctx.kernalContext().query()
.rebuildIndexesFromHash(Collections.singletonList(cacheCtx.cacheId()));
idxRebuildFuts.put(cacheId, rebuildFut);
rebuildFut.listen(new CI1<IgniteInternalFuture>() {
@Override public void apply(IgniteInternalFuture igniteInternalFut) {
idxRebuildFuts.remove(cacheId, rebuildFut);
CacheConfiguration ccfg = cacheCtx.config();
if (ccfg != null) {
log().info("Finished indexes rebuilding for cache: [name=" + ccfg.getName()
+ ", grpName=" + ccfg.getGroupName());
}
}
});
}
}
}
}
示例4: findKeys
/**
* Tries to find keys for two partitions: for one partition assignment should not change after node join,
* for another primary node should change.
*
* @param ignite Ignite.
* @param nodes Current nodes.
* @return Found keys.
*/
private IgniteBiTuple<Integer, Integer> findKeys(Ignite ignite, ClusterNode...nodes) {
ClusterNode newNode = new TcpDiscoveryNode();
GridTestUtils.setFieldValue(newNode, "consistentId", getTestIgniteInstanceName(4));
GridTestUtils.setFieldValue(newNode, "id", UUID.randomUUID());
List<ClusterNode> topNodes = new ArrayList<>();
Collections.addAll(topNodes, nodes);
topNodes.add(newNode);
DiscoveryEvent discoEvt = new DiscoveryEvent(newNode, "", EventType.EVT_NODE_JOINED, newNode);
final long topVer = ignite.cluster().topologyVersion();
GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(topNodes,
null,
discoEvt,
new AffinityTopologyVersion(topVer + 1),
1);
AffinityFunction affFunc = ignite.cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getAffinity();
List<List<ClusterNode>> newAff = affFunc.assignPartitions(ctx);
List<List<ClusterNode>> curAff = ((IgniteKernal)ignite).context().cache().internalCache(DEFAULT_CACHE_NAME).context().
affinity().assignments(new AffinityTopologyVersion(topVer));
Integer key1 = null;
Integer key2 = null;
Affinity<Integer> aff = ignite.affinity(DEFAULT_CACHE_NAME);
for (int i = 0; i < curAff.size(); i++) {
if (key1 == null) {
List<ClusterNode> oldNodes = curAff.get(i);
List<ClusterNode> newNodes = newAff.get(i);
if (oldNodes.equals(newNodes))
key1 = findKey(aff, i);
}
if (key2 == null) {
ClusterNode oldPrimary = F.first(curAff.get(i));
ClusterNode newPrimary = F.first(newAff.get(i));
if (!oldPrimary.equals(newPrimary))
key2 = findKey(aff, i);
}
if (key1 != null && key2 != null)
break;
}
if (key1 == null || key2 == null)
fail("Failed to find nodes required for test.");
return new IgniteBiTuple<>(key1, key2);
}
示例5: checkRandomReassignment
/**
* @param backups Backups.
*/
protected void checkRandomReassignment(int backups) {
AffinityFunction aff = affinityFunction();
Random rnd = new Random();
int maxNodes = 50;
List<ClusterNode> nodes = new ArrayList<>(maxNodes);
List<List<ClusterNode>> prev = null;
int state = 0;
int i = 0;
while (true) {
boolean add;
if (nodes.size() < 2) {
// Returned back to one node?
if (state == 1)
return;
add = true;
}
else if (nodes.size() == maxNodes) {
if (state == 0)
state = 1;
add = false;
}
else {
// Nodes size in [2, maxNodes - 1].
if (state == 0)
add = rnd.nextInt(3) != 0; // 66% to add, 33% to remove.
else
add = rnd.nextInt(3) == 0; // 33% to add, 66% to remove.
}
DiscoveryEvent discoEvt;
if (add) {
ClusterNode addedNode = new GridTestNode(UUID.randomUUID());
nodes.add(addedNode);
discoEvt = new DiscoveryEvent(addedNode, "", EventType.EVT_NODE_JOINED, addedNode);
}
else {
ClusterNode rmvNode = nodes.remove(rnd.nextInt(nodes.size()));
discoEvt = new DiscoveryEvent(rmvNode, "", EventType.EVT_NODE_LEFT, rmvNode);
}
info("======================================");
info("Assigning partitions [iter=" + i + ", discoEvt=" + discoEvt + ", nodesSize=" + nodes.size() + ']');
info("======================================");
List<List<ClusterNode>> assignment = aff.assignPartitions(
new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i),
backups));
verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
prev = assignment;
i++;
}
}