/** * @param node Node. * @param discoveryDataClusterState Discovery data cluster state. * @return {@code True} if node is included in BaselineTopology. */ public static boolean baselineNode(ClusterNode node, DiscoveryDataClusterState discoveryDataClusterState) { return discoveryDataClusterState.baselineTopology().consistentIds().contains(node.consistentId()); }
/** * @param blt Baseline Topology. */ public static BaselineTopologyHistoryItem fromBaseline(BaselineTopology blt) { if (blt == null) return null; List<Long> fullActivationHistory = new ArrayList<>(blt.branchingHistory().size()); fullActivationHistory.addAll(blt.branchingHistory()); return new BaselineTopologyHistoryItem(blt.id(), U.arrayList(blt.consistentIds()), fullActivationHistory); }
/** * @param nodes Nodes. * @param id ID of BaselineTopology to build. * @return Baseline topology consisting of given nodes. */ @Nullable public static BaselineTopology build(Collection<? extends BaselineNode> nodes, int id) { if (nodes == null) return null; Map<Object, Map<String, Object>> nodeMap = new HashMap<>(); for (BaselineNode node : nodes) nodeMap.put(node.consistentId(), node.attributes()); return new BaselineTopology(nodeMap, id); }
/** */ boolean isCompatibleWith(BaselineTopology blt) { BaselineTopologyHistoryItem histBlt = hist.get(blt.id()); return histBlt.branchingHistory().contains(blt.branchingPointHash()); }
/** * Checks whether all conditions to meet BaselineTopology are satisfied. */ private boolean isBaselineSatisfied(BaselineTopology blt, List<ClusterNode> serverNodes) { if (blt == null) return false; if (blt.consistentIds() == null) return false; if (//only node participating in BaselineTopology is allowed to send activation command... blt.consistentIds().contains(ctx.discovery().localNode().consistentId()) //...and with this node BaselineTopology is reached && blt.isSatisfied(serverNodes)) return true; return false; }
if (joiningNodeBlt.id() > clusterBlt.id()) { String msg = "BaselineTopology of joining node (" + node.consistentId() + ") is not compatible with BaselineTopology in the cluster." + " Joining node BlT id (" + joiningNodeBlt.id() + ") is greater than cluster BlT id (" + clusterBlt.id() + ")." + " New BaselineTopology was set on joining node with set-baseline command." + recommendation; if (joiningNodeBlt.id() == clusterBlt.id()) { if (!clusterBlt.isCompatibleWith(joiningNodeBlt)) { String msg = "BaselineTopology of joining node (" + node.consistentId() + ") is not compatible with BaselineTopology in the cluster." + " Branching history of cluster BlT (" + clusterBlt.branchingHistory() + ") doesn't contain branching point hash of joining node BlT (" + joiningNodeBlt.branchingPointHash() + ")." + recommendation; else if (joiningNodeBlt.id() < clusterBlt.id()) { if (!bltHist.isCompatibleWith(joiningNodeBlt)) { String msg = "BaselineTopology of joining node (" + node.consistentId() + ") is not compatible with BaselineTopology in the cluster." + " BlT id of joining node (" + joiningNodeBlt.id() + ") less than BlT id of cluster (" + clusterBlt.id() + ") but cluster's BaselineHistory doesn't contain branching point hash of joining node BlT (" + joiningNodeBlt.branchingPointHash() + ")." + recommendation;
consIdxToNodeId = U.newHashMap(srvNodes.size()); Map<Object, Short> m = blt.consistentIdMapping(); List<BaselineNode >baselineNodes0 = new ArrayList<>(blt.size()); for (Object consId : blt.consistentIds()) { ClusterNode srvNode = aliveNodesByConsId.get(consId); baselineNodes0.add(srvNode); else baselineNodes0.add(blt.baselineNode(consId));
/** {@inheritDoc} */ @Override public void onReadyForRead(ReadOnlyMetastorage metastorage) throws IgniteCheckedException { BaselineTopology blt = (BaselineTopology) metastorage.read(METASTORE_CURR_BLT_KEY); if (blt != null) { if (log.isInfoEnabled()) U.log(log, "Restoring history for BaselineTopology[id=" + blt.id() + "]"); bltHist.restoreHistory(metastorage, blt.id()); } onStateRestored(blt); }
newBltId = activate ? currentBlt.id() + 1 : currentBlt.id(); newBlt = BaselineTopology.build(baselineNodes, newBltId); else if (activate) { if (baselineNodes == null) newBlt = BaselineTopology.build(baselineNodes, newBltId); else { newBlt = currentBlt; newBlt.updateHistory(baselineNodes);
/** * Log exchange event. * * @param evt Discovery event. */ private void logExchange(DiscoveryEvent evt) { if (cctx.kernalContext().state().publicApiActiveState(false) && cctx.wal() != null) { if (cctx.wal().serializerVersion() > 1) try { ExchangeRecord.Type type = null; if (evt.type() == EVT_NODE_JOINED) type = ExchangeRecord.Type.JOIN; else if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) type = ExchangeRecord.Type.LEFT; BaselineTopology blt = cctx.kernalContext().state().clusterState().baselineTopology(); if (type != null && blt != null) { Short constId = blt.consistentIdMapping().get(evt.eventNode().consistentId()); if (constId != null) cctx.wal().log(new ExchangeRecord(constId, type)); } } catch (IgniteCheckedException e) { U.error(log, "Fail during log exchange record.", e); } } }
/** * @param nodes Nodes. */ boolean updateHistory(Collection<? extends BaselineNode> nodes) { long newTopHash = calculateTopologyHash(nodes); lastBranchingPointType = BranchingPointType.CLUSTER_ACTIVATION; if (branchingPntHash != newTopHash) { branchingPntHash = newTopHash; branchingHist.add(newTopHash); return true; } return false; }
if (joiningNodeBlt.id() > clusterBlt.id()) { String msg = "BaselineTopology of joining node (" + node.consistentId() + ") is not compatible with BaselineTopology in the cluster." + " Joining node BlT id (" + joiningNodeBlt.id() + ") is greater than cluster BlT id (" + clusterBlt.id() + ")." + " New BaselineTopology was set on joining node with set-baseline command." + recommendation; if (joiningNodeBlt.id() == clusterBlt.id()) { if (!clusterBlt.isCompatibleWith(joiningNodeBlt)) { String msg = "BaselineTopology of joining node (" + node.consistentId() + ") is not compatible with BaselineTopology in the cluster." + " Branching history of cluster BlT (" + clusterBlt.branchingHistory() + ") doesn't contain branching point hash of joining node BlT (" + joiningNodeBlt.branchingPointHash() + ")." + recommendation; else if (joiningNodeBlt.id() < clusterBlt.id()) { if (!bltHist.isCompatibleWith(joiningNodeBlt)) { String msg = "BaselineTopology of joining node (" + node.consistentId() + ") is not compatible with BaselineTopology in the cluster." + " BlT id of joining node (" + joiningNodeBlt.id() + ") less than BlT id of cluster (" + clusterBlt.id() + ") but cluster's BaselineHistory doesn't contain branching point hash of joining node BlT (" + joiningNodeBlt.branchingPointHash() + ")." + recommendation;
consIdxToNodeId = U.newHashMap(srvNodes.size()); Map<Object, Short> m = blt.consistentIdMapping(); List<BaselineNode >baselineNodes0 = new ArrayList<>(blt.size()); for (Object consId : blt.consistentIds()) { ClusterNode srvNode = aliveNodesByConsId.get(consId); baselineNodes0.add(srvNode); else baselineNodes0.add(blt.baselineNode(consId));
/** Returns current baseline topology id of {@code -1} if there's no baseline topology found. */ private int getBaselineTopologyId() { BaselineTopology baselineTop = ctx.state().clusterState().baselineTopology(); return baselineTop != null ? baselineTop.id() : -1; }
/** * Checks whether all conditions to meet BaselineTopology are satisfied. */ private boolean isBaselineSatisfied(BaselineTopology blt, List<ClusterNode> serverNodes) { if (blt == null) return false; if (blt.consistentIds() == null) return false; if (//only node participating in BaselineTopology is allowed to send activation command... blt.consistentIds().contains(ctx.discovery().localNode().consistentId()) //...and with this node BaselineTopology is reached && blt.isSatisfied(serverNodes)) return true; return false; }
newBltId = activate ? currentBlt.id() + 1 : currentBlt.id(); newBlt = BaselineTopology.build(baselineNodes, newBltId); else if (activate) { if (baselineNodes == null) newBlt = BaselineTopology.build(baselineNodes, newBltId); else { newBlt = currentBlt; newBlt.updateHistory(baselineNodes);
/** */ boolean isCompatibleWith(BaselineTopology blt) { BaselineTopologyHistoryItem histBlt = hist.get(blt.id()); return histBlt.branchingHistory().contains(blt.branchingPointHash()); }
return null; Map<Object, Short> constIdMap = baselineTop.consistentIdMapping();
/** * @param nodes Nodes. */ boolean updateHistory(Collection<? extends BaselineNode> nodes) { long newTopHash = calculateTopologyHash(nodes); lastBranchingPointType = BranchingPointType.CLUSTER_ACTIVATION; if (branchingPntHash != newTopHash) { branchingPntHash = newTopHash; branchingHist.add(newTopHash); return true; } return false; }
@Override public void verify(BaselineTopology blt) { assertNotNull(blt); assertEquals(3, blt.consistentIds().size()); } };