/** * @return Previous Baseline topology. */ @Nullable public BaselineTopology previousBaselineTopology() { return prevState != null ? prevState.baselineTopology() : null; }
/** * @param ctx Context. * * @return instance of current baseline topology if it exists */ public static BaselineTopology getBaselineTopology(@NotNull GridKernalContext ctx) { return ctx.state().clusterState().baselineTopology(); }
/** * @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()); }
/** * Resets branching history on current BaselineTopology. * * @throws IgniteCheckedException If write to metastore has failed. */ public void resetBranchingHistory(long newBranchingHash) throws IgniteCheckedException { if (!compatibilityMode()) { globalState.baselineTopology().resetBranchingHistory(newBranchingHash); writeBaselineTopology(globalState.baselineTopology(), null); U.log(log, String.format("Branching history of current BaselineTopology is reset to the value %d", newBranchingHash)); } }
/** * * @return {@code True} If baseLine changed, {@code False} if not. */ public boolean baselineChanged() { BaselineTopology prevBLT = previousBaselineTopology(); BaselineTopology curBLT = baselineTopology(); if (prevBLT == null && curBLT != null) return true; if (prevBLT!= null && curBLT != null) return !prevBLT.equals(curBLT); return false; }
/** {@inheritDoc} */ @Override public long getRowCount() { BaselineTopology blt = ctx.state().clusterState().baselineTopology(); return blt == null ? 0 : blt.consistentIds().size(); } }
/** 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; }
/** */ private void onStateRestored(BaselineTopology blt) { DiscoveryDataClusterState state = globalState; if (!state.active() && !state.transition() && state.baselineTopology() == null) { DiscoveryDataClusterState newState = DiscoveryDataClusterState.createState(false, blt); globalState = newState; } }
/** {@inheritDoc} */ @Override public Iterator<Row> getRows(Session ses, SearchRow first, SearchRow last) { List<Row> rows = new ArrayList<>(); BaselineTopology blt = ctx.state().clusterState().baselineTopology(); if (blt == null) return rows.iterator(); Set<Object> consistentIds = blt.consistentIds(); Collection<ClusterNode> srvNodes = ctx.discovery().aliveServerNodes(); Set<Object> aliveNodeIds = new HashSet<>(F.nodeConsistentIds(srvNodes)); for (Object consistentId : consistentIds) { rows.add( createRow( ses, consistentId, aliveNodeIds.contains(consistentId) ) ); } return rows.iterator(); }
/** {@inheritDoc} */ @Nullable @Override public Collection<BaselineNode> currentBaselineTopology() { guard(); try { BaselineTopology blt = ctx.state().clusterState().baselineTopology(); return blt != null ? blt.currentBaseline() : null; } finally { unguard(); } }
/** */ @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; }
/** {@inheritDoc} */ @Override public void onReadyForReadWrite(ReadWriteMetastorage metastorage) throws IgniteCheckedException { this.metastorage = metastorage; if (compatibilityMode) { if (log.isInfoEnabled()) log.info("BaselineTopology won't be stored as this node is running in compatibility mode"); return; } writeBaselineTopology(globalState.baselineTopology(), null); bltHist.flushHistoryItems(metastorage); }
/** * @param msg State change message. * @param state Current cluster state. * @return {@code True} if states are equivalent. */ protected static boolean isEquivalent(ChangeGlobalStateMessage msg, DiscoveryDataClusterState state) { return (msg.activate() == state.active() && BaselineTopology.equals(msg.baselineTopology(), state.baselineTopology())); }
/** {@inheritDoc} */ @Override @Nullable public IgniteInternalFuture<Boolean> onLocalJoin(DiscoCache discoCache) { final DiscoveryDataClusterState state = globalState; if (state.active()) checkLocalNodeInBaseline(state.baselineTopology()); if (state.transition()) { joinFut = new TransitionOnJoinWaitFuture(state, discoCache); return joinFut; } else if (!ctx.clientNode() && !ctx.isDaemon() && ctx.config().isAutoActivationEnabled() && !state.active() && isBaselineSatisfied(state.baselineTopology(), discoCache.serverNodes())) changeGlobalState0(true, state.baselineTopology(), false); return null; }
/** * @return {@code true} if local node is in baseline and {@code false} otherwise. */ private boolean isLocalNodeInBaseline() { BaselineTopology topology = cctx.discovery().discoCache().state().baselineTopology(); return topology != null && topology.consistentIds().contains(cctx.localNode().consistentId()); }
/** * Retrieves baseline topology from ignite node instance. * * @param ig Ig. */ private BaselineTopology getBaselineTopology(Ignite ig) { return ((DiscoveryDataClusterState) U.field( (Object) U.field( (Object) U.field(ig, "ctx"), "stateProc"), "globalState")) .baselineTopology(); }
/** * @param req State change request. */ private void onFinalActivate(final StateChangeRequest req) { ctx.dataStructures().onBeforeActivate(); checkLocalNodeInBaseline(globalState.baselineTopology()); ctx.closure().runLocalSafe(new Runnable() { @Override public void run() { boolean client = ctx.clientNode(); try { if (ctx.service() instanceof GridServiceProcessor) { GridServiceProcessor srvcProc = (GridServiceProcessor)ctx.service(); srvcProc.onUtilityCacheStarted(); srvcProc.onActivate(ctx); } ctx.dataStructures().onActivate(ctx); ctx.igfs().onActivate(ctx); ctx.task().onActivate(ctx); ctx.encryption().onActivate(ctx); ((IgniteChangeGlobalStateSupport)ctx.distributedMetastorage()).onActivate(ctx); if (log.isInfoEnabled()) log.info("Successfully performed final activation steps [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + req.topologyVersion() + "]"); } catch (Exception ex) { throw new IgniteException(ex); } } }); }
/** {@inheritDoc} */ @Override public void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) { if (data.commonData() instanceof DiscoveryDataClusterState) { if (globalState != null && globalState.baselineTopology() != null) //node with BaselineTopology is not allowed to join mixed cluster // (where some nodes don't support BaselineTopology) throw new IgniteException("Node with BaselineTopology cannot join" + " mixed cluster running in compatibility mode"); globalState = (DiscoveryDataClusterState) data.commonData(); compatibilityMode = true; return; } BaselineStateAndHistoryData stateDiscoData = (BaselineStateAndHistoryData)data.commonData(); if (stateDiscoData != null) { DiscoveryDataClusterState state = stateDiscoData.globalState; if (state.transition()) transitionFuts.put(state.transitionRequestId(), new GridFutureAdapter<Void>()); globalState = state; if (stateDiscoData.recentHistory != null) { for (BaselineTopologyHistoryItem item : stateDiscoData.recentHistory.history()) bltHist.bufferHistoryItemForStore(item); } } }
/** * 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 || (!logTxRecords && !tx.txState().mvccEnabled()) || (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); } }
/** * 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); } } }