Search in sources :

Example 6 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class IgniteClusterActivateDeactivateTest method checkCaches.

/**
 * @param nodes Number of nodes.
 * @param caches Number of caches.
 */
final void checkCaches(int nodes, int caches, boolean awaitExchange) throws InterruptedException {
    if (awaitExchange)
        awaitPartitionMapExchange();
    ClusterState state = ignite(0).cluster().state();
    assertActive(state);
    for (int i = 0; i < nodes; i++) {
        for (int c = 0; c < caches; c++) {
            IgniteCache<Integer, Integer> cache = ignite(i).cache(CACHE_NAME_PREFIX + c);
            for (int j = 0; j < 10; j++) {
                Integer key = ThreadLocalRandom.current().nextInt(1000);
                Integer value = j;
                if (state == ACTIVE)
                    cache.put(key, j);
                else
                    assertThrowsWithCause(() -> cache.put(key, value), IgniteClusterReadOnlyException.class);
                assertEquals(state == ACTIVE ? value : null, cache.get(key));
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterState(org.apache.ignite.cluster.ClusterState) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException)

Example 7 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class IgniteClusterActivateDeactivateTest method checkClusterStateNotWaitForDeactivation.

/**
 */
private void checkClusterStateNotWaitForDeactivation(ClusterState initialState) throws Exception {
    assertActive(initialState);
    testSpi = true;
    final int nodes = 2;
    IgniteEx crd = startGrids(nodes);
    crd.cluster().state(initialState);
    AffinityTopologyVersion curTopVer = crd.context().discovery().topologyVersionEx();
    AffinityTopologyVersion deactivationTopVer = new AffinityTopologyVersion(curTopVer.topologyVersion(), curTopVer.minorTopologyVersion() + 1);
    for (int gridIdx = 0; gridIdx < nodes; gridIdx++) blockExchangeSingleMessage(TestRecordingCommunicationSpi.spi(grid(gridIdx)), deactivationTopVer);
    IgniteInternalFuture deactivationFut = runAsync(() -> crd.cluster().state(INACTIVE));
    // Wait for deactivation start.
    assertTrue(GridTestUtils.waitForCondition(() -> {
        DiscoveryDataClusterState clusterState = crd.context().state().clusterState();
        return clusterState.transition() && !clusterState.state().active();
    }, getTestTimeout()));
    // Check that deactivation transition wait is not happened.
    ClusterState state = crd.context().state().publicApiState(true);
    assertInactive(state);
    for (int gridIdx = 0; gridIdx < nodes; gridIdx++) TestRecordingCommunicationSpi.spi(grid(gridIdx)).stopBlock();
    deactivationFut.get();
}
Also used : ClusterState(org.apache.ignite.cluster.ClusterState) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 8 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class IgniteClusterActivateDeactivateTest method startNodeAndCheckCaches.

/**
 */
private void startNodeAndCheckCaches(int nodeIdx, boolean client, int cachesCount) throws Exception {
    startGrid(nodeIdx, client);
    ClusterState state = grid(0).cluster().state();
    if (state.active()) {
        checkCachesOnNode(nodeIdx, cachesCount, !client);
        checkCaches(nodeIdx + 1, cachesCount);
    }
}
Also used : ClusterState(org.apache.ignite.cluster.ClusterState) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState)

Example 9 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class IgniteClusterActivateDeactivateTestWithPersistence method testDeactivateClusterWithInMemoryCaches.

/**
 * Tests "soft" deactivation (without using the --force flag)
 * when the client node does not have the configured data storage and the cluster contains in-memory caches.
 *
 * Expected behavior: deactivation should fail due to potential data loss.
 *
 * @throws Exception If failed.
 */
@Test
public void testDeactivateClusterWithInMemoryCaches() throws Exception {
    IgniteEx srv = startGrid(0);
    IgniteEx clientNode = startClientGrid(1);
    clientNode.cluster().state(ACTIVE);
    DataStorageConfiguration dsCfg = srv.configuration().getDataStorageConfiguration();
    DataRegionConfiguration nonPersistentRegion = Arrays.stream(dsCfg.getDataRegionConfigurations()).filter(region -> NO_PERSISTENCE_REGION.equals(region.getName())).findFirst().orElse(null);
    assertTrue("It is assumed that the '" + NO_PERSISTENCE_REGION + "' data storage region exists and non-persistent.", nonPersistentRegion != null && !nonPersistentRegion.isPersistenceEnabled());
    // Create a new cache that is placed into non persistent data region.
    clientNode.getOrCreateCache(new CacheConfiguration<>("test-client-cache").setDataRegionName(nonPersistentRegion.getName()));
    // Try to deactivate the cluster without the `force` flag.
    IgniteInternalFuture<?> deactivateFut = srv.context().state().changeGlobalState(INACTIVE, false, Collections.emptyList(), false);
    assertThrows(log, () -> deactivateFut.get(10, SECONDS), IgniteCheckedException.class, "Deactivation stopped. Deactivation clears in-memory caches (without persistence) including the system caches.");
    awaitPartitionMapExchange();
    // Let's check that all nodes in the cluster have the same state.
    for (Ignite node : G.allGrids()) {
        IgniteEx n = (IgniteEx) node;
        ClusterState state = n.context().state().clusterState().state();
        assertTrue("Node must be in active state. " + "[node=" + n.configuration().getIgniteInstanceName() + ", actual=" + state + ']', ACTIVE == state);
    }
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ClusterState(org.apache.ignite.cluster.ClusterState) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 10 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class IgniteClusterImpl method validateBeforeBaselineChange.

/**
 * 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.");
        List<BaselineNode> currBlT = Optional.ofNullable(ctx.state().clusterState().baselineTopology()).map(BaselineTopology::currentBaseline).orElse(Collections.emptyList());
        Collection<ClusterNode> srvrs = ctx.cluster().get().forServers().nodes();
        for (BaselineNode node : baselineTop) {
            Object consistentId = node.consistentId();
            if (currBlT.stream().noneMatch(currBlTNode -> Objects.equals(currBlTNode.consistentId(), consistentId)) && srvrs.stream().noneMatch(currServersNode -> Objects.equals(currServersNode.consistentId(), consistentId)))
                throw new IgniteException("Check arguments. Node with consistent ID [" + consistentId + "] not found in server nodes.");
        }
        Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop);
        if (onlineNodes != null) {
            if (!onlineNodes.isEmpty())
                throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) ObjectOutput(java.io.ObjectOutput) InetAddress(java.net.InetAddress) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) IgniteNodeStartUtils.parseFile(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.parseFile) Externalizable(java.io.Externalizable) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BaselineAutoAdjustStatus(org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatus) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) ShutdownPolicy(org.apache.ignite.ShutdownPolicy) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DistributedEnumProperty(org.apache.ignite.internal.processors.configuration.distributed.DistributedEnumProperty) ClusterState(org.apache.ignite.cluster.ClusterState) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteComponentType(org.apache.ignite.internal.IgniteComponentType) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) ATTR_IPS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IPS) A(org.apache.ignite.internal.util.typedef.internal.A) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BaselineNode(org.apache.ignite.cluster.BaselineNode) File(java.io.File) ObjectStreamException(java.io.ObjectStreamException) IgniteSshHelper(org.apache.ignite.internal.util.nodestart.IgniteSshHelper) IgniteRemoteStartSpecification(org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification) Collections(java.util.Collections) IgniteNodeStartUtils.specifications(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.specifications) IgniteException(org.apache.ignite.IgniteException) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Aggregations

ClusterState (org.apache.ignite.cluster.ClusterState)20 Map (java.util.Map)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteEx (org.apache.ignite.internal.IgniteEx)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 Test (org.junit.Test)7 Ignite (org.apache.ignite.Ignite)6 DiscoveryDataClusterState (org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState)6 Collection (java.util.Collection)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 Set (java.util.Set)5 UUID (java.util.UUID)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 F (org.apache.ignite.internal.util.typedef.F)5 List (java.util.List)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 CU (org.apache.ignite.internal.util.typedef.internal.CU)4