use of org.apache.ignite.cluster.BaselineNode in project ignite by apache.
the class IgniteClusterImpl method setBaselineTopology.
/**
* {@inheritDoc}
*/
@Override
public void setBaselineTopology(long topVer) {
guard();
try {
if (isInMemoryMode())
return;
Collection<ClusterNode> top = topology(topVer);
if (top == null)
throw new IgniteException("Topology version does not exist: " + topVer);
Collection<BaselineNode> target = new ArrayList<>(top.size());
for (ClusterNode node : top) {
if (!node.isClient())
target.add(node);
}
validateBeforeBaselineChange(target);
ctx.state().changeGlobalState(true, target, true).get();
} catch (IgniteCheckedException e) {
throw U.convertException(e);
} finally {
unguard();
}
}
use of org.apache.ignite.cluster.BaselineNode in project ignite by apache.
the class GridClusterStateProcessor method calculateNewBaselineTopology.
/**
*/
private BaselineTopology calculateNewBaselineTopology(final boolean activate, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology) {
BaselineTopology newBlt;
BaselineTopology currentBlt = globalState.baselineTopology();
int newBltId = 0;
if (currentBlt != null)
newBltId = activate ? currentBlt.id() + 1 : currentBlt.id();
if (baselineNodes != null && !baselineNodes.isEmpty()) {
List<BaselineNode> baselineNodes0 = new ArrayList<>();
for (BaselineNode node : baselineNodes) {
if (node instanceof ClusterNode) {
ClusterNode clusterNode = (ClusterNode) node;
if (!clusterNode.isClient() && !clusterNode.isDaemon())
baselineNodes0.add(node);
} else
baselineNodes0.add(node);
}
baselineNodes = baselineNodes0;
}
if (forceChangeBaselineTopology)
newBlt = BaselineTopology.build(baselineNodes, newBltId);
else if (activate) {
if (baselineNodes == null)
baselineNodes = baselineNodes();
if (currentBlt == null)
newBlt = BaselineTopology.build(baselineNodes, newBltId);
else {
newBlt = currentBlt;
newBlt.updateHistory(baselineNodes);
}
} else
newBlt = null;
return newBlt;
}
use of org.apache.ignite.cluster.BaselineNode in project ignite by apache.
the class VisorBaselineTaskResult method toMap.
/**
* @param nodes Nodes to process.
* @return Map of DTO objects.
*/
private static Map<String, VisorBaselineNode> toMap(Collection<? extends BaselineNode> nodes) {
if (F.isEmpty(nodes))
return null;
Map<String, VisorBaselineNode> map = new TreeMap<>();
for (BaselineNode node : nodes) {
VisorBaselineNode dto = new VisorBaselineNode(node);
map.put(dto.getConsistentId(), dto);
}
return map;
}
use of org.apache.ignite.cluster.BaselineNode in project ignite by apache.
the class GridClusterStateProcessor method baselineNodes.
/**
*/
private Collection<BaselineNode> baselineNodes() {
List<ClusterNode> clNodes = ctx.discovery().serverNodes(AffinityTopologyVersion.NONE);
ArrayList<BaselineNode> bltNodes = new ArrayList<>(clNodes.size());
for (ClusterNode clNode : clNodes) bltNodes.add(clNode);
return bltNodes;
}
use of org.apache.ignite.cluster.BaselineNode 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 (!CU.clientNode(node)) {
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 + ']';
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);
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;
}
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);
}
Aggregations