/** * @param state Current state. * @param discoCache Discovery data cache. */ TransitionOnJoinWaitFuture(DiscoveryDataClusterState state, DiscoCache discoCache) { assert state.transition() : state; transitionNodes = U.newHashSet(state.transitionNodes().size()); for (UUID nodeId : state.transitionNodes()) { if (discoCache.node(nodeId) != null) transitionNodes.add(nodeId); } }
/** * @return {@code True} if cluster was in active state. */ boolean clusterActive() { return state.active() && !state.transition(); } }
/** {@inheritDoc} */ @Override @Nullable public ChangeGlobalStateFinishMessage onNodeLeft(ClusterNode node) { if (globalState.transition()) { Set<UUID> nodes = globalState.transitionNodes(); if (nodes.remove(node.id()) && nodes.isEmpty()) { U.warn(log, "Failed to change cluster state, all participating nodes failed. " + "Switching to inactive state."); ChangeGlobalStateFinishMessage msg = new ChangeGlobalStateFinishMessage(globalState.transitionRequestId(), false, false); onStateFinishMessage(msg); return msg; } } return null; }
if (globalState.transition() && globalState.active()) { Boolean transitionRes = globalState.transitionResult();
/** {@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); } } }
/** */ private void onStateRestored(BaselineTopology blt) { DiscoveryDataClusterState state = globalState; if (!state.active() && !state.transition() && state.baselineTopology() == null) { DiscoveryDataClusterState newState = DiscoveryDataClusterState.createState(false, blt); globalState = newState; } }
compatibilityMode = false; if (state.transition()) { if (isApplicable(msg, state)) { GridChangeGlobalStateFuture fut = changeStateFuture(msg);
/** * Checks cluster state and handles given event. * <pre> * - if cluster is active, then adds event in deployment queue; * - if cluster state in transition, them adds to pending events; * - if cluster is inactive, then ignore event; * </pre> * <b>Should be called from discovery thread.</b> * * @param evt Discovery event. * @param discoCache Discovery cache. * @param depActions Services deployment actions. */ private void checkClusterStateAndAddTask(@NotNull DiscoveryEvent evt, @NotNull DiscoCache discoCache, @Nullable ServiceDeploymentActions depActions) { if (discoCache.state().transition()) pendingEvts.add(new PendingEventHolder(evt, discoCache.version(), depActions)); else if (discoCache.state().active()) addTask(evt, discoCache.version(), depActions); else if (log.isDebugEnabled()) log.debug("Ignore event, cluster is inactive, evt=" + evt); }
/** * Callback invoked from discovery thread when discovery message is received. * * @param type Event type. * @param customMsg Custom message instance. * @param node Event node. * @param topVer Topology version. * @param state Cluster state. */ void onDiscoveryEvent(int type, @Nullable DiscoveryCustomMessage customMsg, ClusterNode node, AffinityTopologyVersion topVer, DiscoveryDataClusterState state) { if (type == EVT_NODE_JOINED && node.isLocal()) lastAffVer = null; if ((state.transition() || !state.active()) && !DiscoveryCustomEvent.requiresCentralizedAffinityAssignment(customMsg)) return; if ((!node.isClient() && (type == EVT_NODE_FAILED || type == EVT_NODE_JOINED || type == EVT_NODE_LEFT)) || DiscoveryCustomEvent.requiresCentralizedAffinityAssignment(customMsg)) { synchronized (mux) { assert lastAffVer == null || topVer.compareTo(lastAffVer) > 0 : "lastAffVer=" + lastAffVer + ", topVer=" + topVer + ", customMsg=" + customMsg; lastAffVer = topVer; } } }
/** {@inheritDoc} */ @Override public Map<Integer, CacheMetrics> cacheMetrics() { try { if (disableCacheMetricsUpdate) return Collections.emptyMap(); /** Caches should not be accessed while state transition is in progress. */ if (ctx.state().clusterState().transition()) return Collections.emptyMap(); Collection<GridCacheAdapter<?, ?>> caches = ctx.cache().internalCaches(); if (!F.isEmpty(caches)) { Map<Integer, CacheMetrics> metrics = U.newHashMap(caches.size()); for (GridCacheAdapter<?, ?> cache : caches) { if (cache.context().statisticsEnabled() && cache.context().started() && cache.context().affinity().affinityTopologyVersion().topologyVersion() > 0) metrics.put(cache.context().cacheId(), cache.localMetrics()); } return metrics; } } catch (Exception e) { U.warn(log, "Failed to compute cache metrics", e); } return Collections.emptyMap(); } };
boolean active = state.active() && !state.transition(); ClusterCachesReconnectResult reconnectRes = cachesInfo.onReconnected(active, state.transition());
/** * @param clientData Discovery data. * @param clientNodeId Client node ID. */ private void processClientReconnectData(CacheClientReconnectDiscoveryData clientData, UUID clientNodeId) { DiscoveryDataClusterState state = ctx.state().clusterState(); if (state.active() && !state.transition()) { for (CacheClientReconnectDiscoveryData.CacheInfo cacheInfo : clientData.clientCaches().values()) { String cacheName = cacheInfo.config().getName(); if (surviveReconnect(cacheName)) ctx.discovery().addClientNode(cacheName, clientNodeId, false); else { DynamicCacheDescriptor desc = registeredCaches.get(cacheName); if (desc != null && desc.deploymentId().equals(cacheInfo.deploymentId())) ctx.discovery().addClientNode(cacheName, clientNodeId, cacheInfo.nearCache()); } } } }
/** {@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; }
DiscoveryDataClusterState state = ctx.state().clusterState(); if (!state.active() || state.transition()) { for (ServiceChangeAbstractRequest req : msg.requests()) { GridFutureAdapter<?> fut = null;
assert locJoinCachesCtx == null : locJoinCachesCtx; if (ctx.state().clusterState().transition()) { joinOnTransition = true;
if (!curState.transition() && curState.active() == activate && (!activate || BaselineTopology.equals(curState.baselineTopology(), blt))) return new GridFinishedFuture<>();
DiscoveryDataClusterState state = ctx.state().clusterState(); if (state.active() && !state.transition()) { ExchangeActions exchangeActions = new ExchangeActions();
if (globalState.transition() && globalState.previousBaselineTopology() == null) { if (globalState.transition()) clusterBlt = globalState.previousBaselineTopology(); else
assertFalse(stateFut.get().isDone()); assertTrue(client.context().state().clusterState().transition());
DiscoveryDataClusterState clusterState = crd.context().state().clusterState(); return clusterState.transition() && !clusterState.active(); }, getTestTimeout());