use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.
the class GridDiscoveryManager method createDiscoCache.
/**
* Called from discovery thread.
*
* @param topVer Topology version.
* @param state Current state.
* @param loc Local node.
* @param topSnapshot Topology snapshot.
* @return Newly created discovery cache.
*/
@NotNull
private DiscoCache createDiscoCache(AffinityTopologyVersion topVer, DiscoveryDataClusterState state, ClusterNode loc, Collection<ClusterNode> topSnapshot) {
assert topSnapshot.contains(loc);
HashSet<UUID> alives = U.newHashSet(topSnapshot.size());
HashMap<UUID, ClusterNode> nodeMap = U.newHashMap(topSnapshot.size());
ArrayList<ClusterNode> daemonNodes = new ArrayList<>(topSnapshot.size());
ArrayList<ClusterNode> srvNodes = new ArrayList<>(topSnapshot.size());
ArrayList<ClusterNode> rmtNodes = new ArrayList<>(topSnapshot.size());
ArrayList<ClusterNode> allNodes = new ArrayList<>(topSnapshot.size());
Map<UUID, Short> nodeIdToConsIdx;
Map<Short, UUID> consIdxToNodeId;
List<? extends BaselineNode> baselineNodes;
IgniteProductVersion minVer = null;
IgniteProductVersion minSrvVer = null;
for (ClusterNode node : topSnapshot) {
if (alive(node))
alives.add(node.id());
if (node.isDaemon())
daemonNodes.add(node);
else {
allNodes.add(node);
if (!node.isLocal())
rmtNodes.add(node);
if (!node.isClient()) {
srvNodes.add(node);
if (minSrvVer == null)
minSrvVer = node.version();
else if (node.version().compareTo(minSrvVer) < 0)
minSrvVer = node.version();
}
}
nodeMap.put(node.id(), node);
if (minVer == null)
minVer = node.version();
else if (node.version().compareTo(minVer) < 0)
minVer = node.version();
}
assert !rmtNodes.contains(loc) : "Remote nodes collection shouldn't contain local node" + " [rmtNodes=" + rmtNodes + ", loc=" + loc + ']';
BaselineTopology blt = state.baselineTopology();
if (blt != null) {
nodeIdToConsIdx = U.newHashMap(srvNodes.size());
consIdxToNodeId = U.newHashMap(srvNodes.size());
Map<Object, Short> m = blt.consistentIdMapping();
Map<Object, ClusterNode> aliveNodesByConsId = U.newHashMap(srvNodes.size());
for (ClusterNode node : srvNodes) {
Short compactedId = m.get(node.consistentId());
if (compactedId != null) {
nodeIdToConsIdx.put(node.id(), compactedId);
consIdxToNodeId.put(compactedId, node.id());
}
aliveNodesByConsId.put(node.consistentId(), node);
}
List<BaselineNode> baselineNodes0 = new ArrayList<>(blt.size());
for (Object consId : blt.consistentIds()) {
ClusterNode srvNode = aliveNodesByConsId.get(consId);
if (srvNode != null)
baselineNodes0.add(srvNode);
else
baselineNodes0.add(blt.baselineNode(consId));
}
baselineNodes = baselineNodes0;
} else {
nodeIdToConsIdx = null;
consIdxToNodeId = null;
baselineNodes = null;
}
Map<Integer, List<ClusterNode>> allCacheNodes = U.newHashMap(allNodes.size());
Map<Integer, List<ClusterNode>> cacheGrpAffNodes = U.newHashMap(allNodes.size());
Set<ClusterNode> rmtNodesWithCaches = new TreeSet<>(NodeOrderComparator.getInstance());
fillAffinityNodeCaches(allNodes, allCacheNodes, cacheGrpAffNodes, rmtNodesWithCaches, nodeIdToConsIdx == null ? null : nodeIdToConsIdx.keySet());
return new DiscoCache(topVer, state, loc, Collections.unmodifiableList(rmtNodes), Collections.unmodifiableList(allNodes), Collections.unmodifiableList(srvNodes), Collections.unmodifiableList(daemonNodes), U.sealList(rmtNodesWithCaches), baselineNodes == null ? null : Collections.unmodifiableList(baselineNodes), Collections.unmodifiableMap(allCacheNodes), Collections.unmodifiableMap(cacheGrpAffNodes), Collections.unmodifiableMap(nodeMap), alives, nodeIdToConsIdx == null ? null : Collections.unmodifiableMap(nodeIdToConsIdx), consIdxToNodeId == null ? null : Collections.unmodifiableMap(consIdxToNodeId), minVer, minSrvVer);
}
use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.
the class GridDiscoveryManager method topologySnapshotMessage.
/**
* @param clo Wrapper of logger.
* @param topVer Topology version.
* @param discoCache Discovery cache.
* @param evtType Event type.
* @param evtNode Event node.
* @param srvNodesNum Server nodes number.
* @param clientNodesNum Client nodes number.
* @param totalCpus Total cpu number.
* @param heap Heap size.
* @param offheap Offheap size.
* @param needNodesDetails Flag for additional alive nodes logging.
*/
private void topologySnapshotMessage(IgniteClosure<String, Void> clo, long topVer, DiscoCache discoCache, int evtType, ClusterNode evtNode, int srvNodesNum, int clientNodesNum, int totalCpus, double heap, double offheap, boolean needNodesDetails) {
DiscoveryDataClusterState state = discoCache.state();
SB summary = new SB(PREFIX);
summary.a(" [");
summary.a(discoOrdered ? "ver=" + topVer + ", " : "");
summary.a("locNode=").a(U.id8(discoCache.localNode().id()));
summary.a(", servers=").a(srvNodesNum);
summary.a(", clients=").a(clientNodesNum);
summary.a(", state=").a(state.active() ? "ACTIVE" : "INACTIVE");
summary.a(", CPUs=").a(totalCpus);
summary.a(", offheap=").a(offheap).a("GB");
summary.a(", heap=").a(heap).a("GB");
if ((evtType == EVT_NODE_JOINED || evtType == EVT_NODE_LEFT || evtType == EVT_NODE_FAILED) && needNodesDetails) {
summary.a(", aliveNodes=[");
for (ClusterNode clusterNode : discoCache.allNodes()) {
if (discoCache.alive(clusterNode.id()))
summary.a(nodeDescription(clusterNode)).a(", ");
}
summary.setLength(summary.length() - 2);
summary.a(']');
}
summary.a(']');
clo.apply(summary.toString());
ClusterNode currCrd = discoCache.oldestServerNode();
if ((evtType == EventType.EVT_NODE_FAILED || evtType == EventType.EVT_NODE_LEFT) && currCrd != null && currCrd.order() > evtNode.order() && !evtNode.isClient() && !evtNode.isDaemon())
clo.apply("Coordinator changed [prev=" + evtNode + ", cur=" + currCrd + "]");
BaselineTopology blt = state.baselineTopology();
if (blt != null && discoCache.baselineNodes() != null) {
int bltSize = discoCache.baselineNodes().size();
int bltOnline = discoCache.aliveBaselineNodes().size();
int bltOffline = bltSize - bltOnline;
clo.apply(" ^-- Baseline [id=" + blt.id() + ", size=" + bltSize + ", online=" + bltOnline + ", offline=" + bltOffline + ']');
ClusterState targetState = ctx.config().getClusterStateOnStart();
if (targetState == null)
targetState = ctx.config().isAutoActivationEnabled() ? ACTIVE : INACTIVE;
if (!state.state().active() && targetState.active()) {
String offlineConsistentIds = "";
if (bltOffline > 0 && bltOffline <= 5) {
Collection<BaselineNode> offlineNodes = new HashSet<>(discoCache.baselineNodes());
offlineNodes.removeAll(discoCache.aliveBaselineNodes());
offlineConsistentIds = ' ' + F.nodeConsistentIds(offlineNodes).toString();
}
if (bltOffline == 0) {
if (evtType == EVT_NODE_JOINED && discoCache.baselineNode(evtNode))
clo.apply(" ^-- All baseline nodes are online, will start auto-activation");
} else
clo.apply(" ^-- " + bltOffline + " nodes left for auto-activation" + offlineConsistentIds);
}
}
}
use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.
the class IgniteClusterImpl method onlineBaselineNodesRequestedForRemoval.
/**
*/
@Nullable
private Collection<Object> onlineBaselineNodesRequestedForRemoval(Collection<? extends BaselineNode> newBlt) {
BaselineTopology blt = ctx.state().clusterState().baselineTopology();
Set<Object> bltConsIds;
if (blt == null)
return null;
else
bltConsIds = blt.consistentIds();
ArrayList<Object> onlineNodesRequestedForRemoval = new ArrayList<>();
Collection<Object> aliveNodesConsIds = getConsistentIds(ctx.discovery().aliveServerNodes());
Collection<Object> newBltConsIds = getConsistentIds(newBlt);
for (Object oldBltConsId : bltConsIds) {
if (aliveNodesConsIds.contains(oldBltConsId)) {
if (!newBltConsIds.contains(oldBltConsId))
onlineNodesRequestedForRemoval.add(oldBltConsId);
}
}
return onlineNodesRequestedForRemoval;
}
use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.
the class IgniteTxManager method logTxRecord.
/**
* Logs Tx state to WAL if needed.
*
* @param tx Transaction.
* @return WALPointer or {@code null} if nothing was logged.
*/
@Nullable
WALPointer logTxRecord(IgniteTxAdapter tx) {
BaselineTopology baselineTop;
// Log tx state change to WAL.
if (cctx.wal() == null || (baselineTop = cctx.kernalContext().state().clusterState().baselineTopology()) == null || !baselineTop.consistentIds().contains(cctx.localNode().consistentId()))
return null;
Map<Short, Collection<Short>> nodes = tx.consistentIdMapper.mapToCompactIds(tx.topVer, tx.txNodes, baselineTop);
TxRecord record;
if (tx.txState().mvccEnabled())
record = new MvccTxRecord(tx.state(), tx.nearXidVersion(), tx.writeVersion(), nodes, tx.mvccSnapshot());
else
record = new TxRecord(tx.state(), tx.nearXidVersion(), tx.writeVersion(), nodes);
try {
return cctx.wal().log(record);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to log TxRecord: " + record, e);
throw new IgniteException("Failed to log TxRecord: " + record, e);
}
}
use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.
the class IgniteBaselineAffinityTopologyActivationTest method testNewNodeJoinsToActiveCluster.
/**
* Verifies that when new node outside of baseline topology joins active cluster with BLT already set
* it receives BLT from the cluster and stores it locally.
*/
@Test
public void testNewNodeJoinsToActiveCluster() throws Exception {
Ignite nodeA = startGridWithConsistentId("A");
Ignite nodeB = startGridWithConsistentId("B");
Ignite nodeC = startGridWithConsistentId("C");
nodeC.cluster().active(true);
BaselineTopologyVerifier verifier1 = new BaselineTopologyVerifier() {
@Override
public void verify(BaselineTopology blt) {
assertNotNull(blt);
assertEquals(3, blt.consistentIds().size());
}
};
verifyBaselineTopologyOnNodes(verifier1, new Ignite[] { nodeA, nodeB, nodeC });
Ignite nodeD = startGridWithConsistentId("D");
verifyBaselineTopologyOnNodes(verifier1, new Ignite[] { nodeD });
stopAllGrids(false);
nodeD = startGridWithConsistentId("D");
assertFalse(nodeD.cluster().active());
verifyBaselineTopologyOnNodes(verifier1, new Ignite[] { nodeD });
}
Aggregations