use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.
the class ServerImpl method nodeAlive.
/**
* Checks whether a node is alive or not.
*
* @param nodeId Node ID.
* @return {@code True} if node is in the ring and is not being removed from.
*/
private boolean nodeAlive(UUID nodeId) {
// Is node alive or about to be removed from the ring?
TcpDiscoveryNode node = ring.node(nodeId);
boolean nodeAlive = node != null && node.visible();
if (nodeAlive) {
synchronized (mux) {
nodeAlive = !F.transform(failedNodes.keySet(), F.node2id()).contains(nodeId) && !F.transform(leavingNodes, F.node2id()).contains(nodeId);
}
}
return nodeAlive;
}
use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.
the class ServerImpl method processMessageFailedNodes.
/**
* Adds failed nodes specified in the received message to the local failed nodes list.
*
* @param msg Message.
*/
private void processMessageFailedNodes(TcpDiscoveryAbstractMessage msg) {
Collection<UUID> msgFailedNodes = msg.failedNodes();
if (msgFailedNodes != null) {
UUID sndId = msg.senderNodeId();
if (sndId != null) {
if (ring.node(sndId) == null) {
if (log.isDebugEnabled()) {
log.debug("Ignore message failed nodes, sender node is not alive [nodeId=" + sndId + ", failedNodes=" + msgFailedNodes + ']');
}
return;
}
synchronized (mux) {
for (TcpDiscoveryNode failedNode : failedNodes.keySet()) {
if (failedNode.id().equals(sndId)) {
if (log.isDebugEnabled()) {
log.debug("Ignore message failed nodes, sender node is in fail list [nodeId=" + sndId + ", failedNodes=" + msgFailedNodes + ']');
}
return;
}
}
}
}
for (UUID nodeId : msgFailedNodes) {
TcpDiscoveryNode failedNode = ring.node(nodeId);
if (failedNode != null) {
if (!failedNode.isLocal()) {
boolean added = false;
synchronized (mux) {
if (!failedNodes.containsKey(failedNode)) {
failedNodes.put(failedNode, msg.senderNodeId() != null ? msg.senderNodeId() : getLocalNodeId());
added = true;
}
}
if (added && log.isDebugEnabled())
log.debug("Added node to failed nodes list [node=" + failedNode + ", msg=" + msg + ']');
}
}
}
}
}
use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method 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);
}
use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.
the class IgniteClientReconnectAbstractTest method clientRouter.
/**
* @param client Client.
* @return Server node client connected to.
*/
protected Ignite clientRouter(Ignite client) {
TcpDiscoveryNode node = (TcpDiscoveryNode) client.cluster().localNode();
assertTrue(node.isClient());
assertNotNull(node.clientRouterNodeId());
Ignite srv = G.ignite(node.clientRouterNodeId());
assertNotNull(srv);
return srv;
}
use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.
the class AffinityFunctionExcludeNeighborsAbstractSelfTest method testAffinityMultiNode.
/**
* @throws Exception If failed.
*/
public void testAffinityMultiNode() throws Exception {
int grids = 9;
startGrids(grids);
try {
Object key = 12345;
int copies = backups + 1;
for (int i = 0; i < grids; i++) {
final Ignite g = grid(i);
Affinity<Object> aff = g.affinity(DEFAULT_CACHE_NAME);
List<TcpDiscoveryNode> top = new ArrayList<>();
for (ClusterNode node : g.cluster().nodes()) top.add((TcpDiscoveryNode) node);
Collections.sort(top);
assertEquals(grids, top.size());
int idx = 1;
for (ClusterNode n : top) {
assertEquals(idx, n.order());
idx++;
}
Collection<? extends ClusterNode> affNodes = nodes(aff, key);
info("Affinity picture for grid [i=" + i + ", aff=" + U.toShortString(affNodes));
assertEquals(copies, affNodes.size());
Set<String> macs = new HashSet<>();
for (ClusterNode node : affNodes) macs.add((String) node.attribute(IgniteNodeAttributes.ATTR_MACS));
assertEquals(copies, macs.size());
}
} finally {
stopAllGrids();
}
}
Aggregations