/** * */ public void onDisconnected() { cachesOnDisconnect = new CachesOnDisconnect( ctx.state().clusterState(), new HashMap<>(registeredCacheGrps), new HashMap<>(registeredCaches)); registeredCacheGrps.clear(); registeredCaches.clear(); registeredTemplates.clear(); clientReconnectReqs = 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(); }
/** * Check cluster state. */ private void checkActivate() { if (!ctx.state().publicApiActiveState(true)) { throw new IgniteException("Can not perform the operation because the cluster is inactive. Note, that " + "the cluster is considered inactive by default if Ignite Persistent Store is used to let all the nodes " + "join the cluster. To activate the cluster call Ignite.active(true)."); } }
/** Whether cluster is active at this moment or not. Also returns {@code true} if cluster is being activated. */ private boolean isActive() { return ctx.state().clusterState().active(); }
/** {@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; }
/** {@inheritDoc} */ @Override public boolean active() { guard(); try { return ctx.state().publicApiActiveState(true); } finally { unguard(); } }
/** {@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 boolean active() { guard(); try { return context().state().publicApiActiveState(true); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public void run() { try { ig.context().state().changeGlobalState( activate, baselineTopology != null ? baselineTopology.currentBaseline() : null, forceChangeBaselineTopology ).get(); } catch (IgniteCheckedException ex) { throw new IgniteException(ex); } } }
/** * Executes validation checks of cluster state and BaselineTopology before changing BaselineTopology to new one. */ private void validateBeforeBaselineChange(Collection<? extends BaselineNode> baselineTop) { verifyBaselineTopologySupport(ctx.discovery().discoCache()); if (!ctx.state().clusterState().active()) throw new IgniteException("Changing BaselineTopology on inactive cluster is not allowed."); if (baselineTop != null) { if (baselineTop.isEmpty()) throw new IgniteException("BaselineTopology must contain at least one node."); Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop); if (onlineNodes != null) { if (!onlineNodes.isEmpty()) throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes); } } }
/** {@inheritDoc} */ @Override public void active(boolean active) { guard(); try { ctx.state().changeGlobalState(active, baselineNodes(), false).get(); } catch (IgniteCheckedException e) { throw U.convertException(e); } finally { unguard(); } }
/** {@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(); } }
/** {@inheritDoc} */ @Override public void setBaselineTopology(Collection<? extends BaselineNode> baselineTop) { guard(); try { if (isInMemoryMode()) return; validateBeforeBaselineChange(baselineTop); ctx.state().changeGlobalState(true, baselineTop, true).get(); } catch (IgniteCheckedException e) { throw U.convertException(e); } finally { unguard(); } }
/** * @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()); } } } }
/** * @param nodes Number of nodes. */ final void checkNoCaches(int nodes) { for (int i = 0; i < nodes; i++) { grid(i).context().state().publicApiActiveState(true); GridCacheProcessor cache = ((IgniteEx)ignite(i)).context().cache(); assertTrue(cache.caches().isEmpty()); assertTrue(cache.internalCaches().stream().allMatch(c -> c.context().isRecoveryMode())); } } }
/** */ public void checkTxFinishAfterDeactivation(boolean commit) throws Exception { IgniteEx node0 = startGrid(0); node0.cluster().active(true); try (Connection conn = connect()) { execute(conn, "CREATE TABLE t1(a INT, b VARCHAR, PRIMARY KEY(a)) WITH \"atomicity=TRANSACTIONAL_SNAPSHOT,backups=1\""); } final CountDownLatch enlistedLatch = new CountDownLatch(1); assert node0.cluster().active(); IgniteInternalFuture txFinishedFut = GridTestUtils.runAsync(() -> { executeTransaction(commit, enlistedLatch, () -> !node0.context().state().publicApiActiveState(true)); return null; }); enlistedLatch.await(); deactivateThroughClient(); log.info(">>> Cluster deactivated ..."); try { txFinishedFut.get(); } catch (Exception e) { e.printStackTrace(); fail("Exception is not expected here"); } }
/** * @param cacheName Cache name. * @param node Node. * @param exp {@code True} if expect that cache is started on node. */ void checkCache(Ignite node, String cacheName, boolean exp) throws IgniteCheckedException { ((IgniteEx)node).context().cache().context().exchange().lastTopologyFuture().get(); ((IgniteEx)node).context().state().publicApiActiveState(true); GridCacheAdapter cache = ((IgniteEx)node).context().cache().internalCache(cacheName); if (exp) assertNotNull("Cache not found [cache=" + cacheName + ", node=" + node.name() + ']', cache); else assertNull("Unexpected cache found [cache=" + cacheName + ", node=" + node.name() + ']', cache); }