Search in sources :

Example 1 with ClusterState

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

the class GridDhtPartitionsExchangeFuture method finishExchangeOnCoordinator.

/**
 * @param sndResNodes Additional nodes to send finish message to.
 */
private void finishExchangeOnCoordinator(@Nullable Collection<ClusterNode> sndResNodes) {
    if (isDone() || !enterBusy())
        return;
    try {
        if (!F.isEmpty(exchangeGlobalExceptions) && dynamicCacheStartExchange() && isRollbackSupported()) {
            sendExchangeFailureMessage();
            return;
        }
        AffinityTopologyVersion resTopVer = exchCtx.events().topologyVersion();
        if (log.isInfoEnabled()) {
            log.info("finishExchangeOnCoordinator [topVer=" + initialVersion() + ", resVer=" + resTopVer + ']');
        }
        Map<Integer, CacheGroupAffinityMessage> idealAffDiff = null;
        // Reserve at least 2 threads for system operations.
        int parallelismLvl = U.availableThreadCount(cctx.kernalContext(), GridIoPolicy.SYSTEM_POOL, 2);
        if (exchCtx.mergeExchanges()) {
            synchronized (mux) {
                if (mergedJoinExchMsgs != null) {
                    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : mergedJoinExchMsgs.entrySet()) {
                        msgs.put(e.getKey(), e.getValue());
                        updatePartitionSingleMap(e.getKey(), e.getValue());
                    }
                }
            }
            assert exchCtx.events().hasServerJoin() || exchCtx.events().hasServerLeft();
            exchCtx.events().processEvents(this);
            if (exchCtx.events().hasServerLeft())
                idealAffDiff = cctx.affinity().onServerLeftWithExchangeMergeProtocol(this);
            else
                cctx.affinity().onServerJoinWithExchangeMergeProtocol(this, true);
            doInParallel(parallelismLvl, cctx.kernalContext().pools().getSystemExecutorService(), cctx.affinity().cacheGroups().values(), desc -> {
                if (desc.config().getCacheMode() == CacheMode.LOCAL)
                    return null;
                CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId());
                GridDhtPartitionTopology top = grp != null ? grp.topology() : cctx.exchange().clientTopology(desc.groupId(), events().discoveryCache());
                top.beforeExchange(this, true, true);
                return null;
            });
        }
        span.addLog(() -> "Affinity recalculation (crd)");
        timeBag.finishGlobalStage("Affinity recalculation (crd)");
        Map<Integer, CacheGroupAffinityMessage> joinedNodeAff = new ConcurrentHashMap<>(cctx.cache().cacheGroups().size());
        doInParallel(parallelismLvl, cctx.kernalContext().pools().getSystemExecutorService(), msgs.values(), msg -> {
            processSingleMessageOnCrdFinish(msg, joinedNodeAff);
            return null;
        });
        timeBag.finishGlobalStage("Collect update counters and create affinity messages");
        if (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            assert firstDiscoEvt instanceof DiscoveryCustomEvent;
            if (activateCluster() || changedBaseline())
                assignPartitionsStates(null);
            DiscoveryCustomMessage discoveryCustomMessage = ((DiscoveryCustomEvent) firstDiscoEvt).customMessage();
            if (discoveryCustomMessage instanceof DynamicCacheChangeBatch) {
                if (exchActions != null) {
                    Set<String> caches = exchActions.cachesToResetLostPartitions();
                    if (!F.isEmpty(caches))
                        resetLostPartitions(caches);
                    Set<Integer> cacheGroupsToResetOwners = concat(exchActions.cacheGroupsToStart().stream().map(grp -> grp.descriptor().groupId()), exchActions.cachesToResetLostPartitions().stream().map(CU::cacheId)).collect(Collectors.toSet());
                    assignPartitionsStates(cacheGroupsToResetOwners);
                }
            } else if (discoveryCustomMessage instanceof SnapshotDiscoveryMessage && ((SnapshotDiscoveryMessage) discoveryCustomMessage).needAssignPartitions()) {
                markAffinityReassign();
                assignPartitionsStates(null);
            }
        } else if (exchCtx.events().hasServerJoin())
            assignPartitionsStates(null);
        else if (exchCtx.events().hasServerLeft())
            assignPartitionsStates(emptySet());
        // Validation should happen after resetting owners to avoid false desync reporting.
        validatePartitionsState();
        // Recalculate new affinity based on partitions availability.
        if (!exchCtx.mergeExchanges() && forceAffReassignment) {
            idealAffDiff = cctx.affinity().onCustomEventWithEnforcedAffinityReassignment(this);
            timeBag.finishGlobalStage("Ideal affinity diff calculation (enforced)");
        }
        for (CacheGroupContext grpCtx : cctx.cache().cacheGroups()) {
            if (!grpCtx.isLocal())
                grpCtx.topology().applyUpdateCounters();
        }
        timeBag.finishGlobalStage("Apply update counters");
        updateLastVersion(cctx.versions().last());
        cctx.versions().onExchange(lastVer.get().order());
        IgniteProductVersion minVer = exchCtx.events().discoveryCache().minimumNodeVersion();
        GridDhtPartitionsFullMessage msg = createPartitionsMessage(true, minVer.compareToIgnoreTimestamp(PARTIAL_COUNTERS_MAP_SINCE) >= 0);
        if (!cctx.affinity().rebalanceRequired() && !deactivateCluster())
            msg.rebalanced(true);
        if (exchCtx.mergeExchanges()) {
            assert !centralizedAff;
            msg.resultTopologyVersion(resTopVer);
            if (exchCtx.events().hasServerLeft())
                msg.idealAffinityDiff(idealAffDiff);
        } else if (forceAffReassignment)
            msg.idealAffinityDiff(idealAffDiff);
        msg.prepareMarshal(cctx);
        timeBag.finishGlobalStage("Full message preparing");
        synchronized (mux) {
            finishState = new FinishState(crd.id(), resTopVer, msg);
            state = ExchangeLocalState.DONE;
        }
        if (centralizedAff) {
            assert !exchCtx.mergeExchanges();
            IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut = cctx.affinity().initAffinityOnNodeLeft(this);
            if (!fut.isDone())
                fut.listen(this::onAffinityInitialized);
            else
                onAffinityInitialized(fut);
        } else {
            Set<ClusterNode> nodes;
            Map<UUID, GridDhtPartitionsSingleMessage> mergedJoinExchMsgs0;
            synchronized (mux) {
                srvNodes.remove(cctx.localNode());
                nodes = new LinkedHashSet<>(srvNodes);
                mergedJoinExchMsgs0 = mergedJoinExchMsgs;
                if (mergedJoinExchMsgs != null) {
                    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : mergedJoinExchMsgs.entrySet()) {
                        if (e.getValue() != null) {
                            ClusterNode node = cctx.discovery().node(e.getKey());
                            if (node != null)
                                nodes.add(node);
                        }
                    }
                } else
                    mergedJoinExchMsgs0 = Collections.emptyMap();
                if (!F.isEmpty(sndResNodes))
                    nodes.addAll(sndResNodes);
            }
            if (msg.rebalanced())
                markRebalanced();
            if (!nodes.isEmpty())
                sendAllPartitions(msg, nodes, mergedJoinExchMsgs0, joinedNodeAff);
            timeBag.finishGlobalStage("Full message sending");
            discoveryLag = calculateDiscoveryLag(msgs, mergedJoinExchMsgs0);
            if (!stateChangeExchange())
                onDone(exchCtx.events().topologyVersion(), null);
            for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : pendingSingleMsgs.entrySet()) {
                if (log.isInfoEnabled()) {
                    log.info("Process pending message on coordinator [node=" + e.getKey() + ", ver=" + initialVersion() + ", resVer=" + resTopVer + ']');
                }
                processSingleMessage(e.getKey(), e.getValue());
            }
        }
        if (stateChangeExchange()) {
            StateChangeRequest req = exchActions.stateChangeRequest();
            assert req != null : exchActions;
            boolean stateChangeErr = false;
            if (!F.isEmpty(exchangeGlobalExceptions)) {
                stateChangeErr = true;
                cctx.kernalContext().state().onStateChangeError(exchangeGlobalExceptions, req);
            } else {
                boolean hasMoving = !partsToReload.isEmpty();
                Set<Integer> waitGrps = cctx.affinity().waitGroups();
                if (!hasMoving) {
                    for (CacheGroupContext grpCtx : cctx.cache().cacheGroups()) {
                        if (waitGrps.contains(grpCtx.groupId()) && grpCtx.topology().hasMovingPartitions()) {
                            hasMoving = true;
                            break;
                        }
                    }
                }
                cctx.kernalContext().state().onExchangeFinishedOnCoordinator(this, hasMoving);
            }
            if (!cctx.kernalContext().state().clusterState().localBaselineAutoAdjustment()) {
                ClusterState state = stateChangeErr ? ClusterState.INACTIVE : req.state();
                ChangeGlobalStateFinishMessage stateFinishMsg = new ChangeGlobalStateFinishMessage(req.requestId(), state, !stateChangeErr);
                cctx.discovery().sendCustomEvent(stateFinishMsg);
            }
            timeBag.finishGlobalStage("State finish message sending");
            if (!centralizedAff)
                onDone(exchCtx.events().topologyVersion(), null);
        }
        // Try switch late affinity right now if an exchange has been completed normally.
        if (!centralizedAff && isDone() && error() == null && !cctx.kernalContext().isStopping())
            cctx.exchange().checkRebalanceState();
    } catch (IgniteCheckedException e) {
        if (reconnectOnError(e))
            onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
        else
            onDone(e);
    } finally {
        leaveBusy();
    }
}
Also used : GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterState(org.apache.ignite.cluster.ClusterState) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) CU(org.apache.ignite.internal.util.typedef.internal.CU) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) ChangeGlobalStateFinishMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with ClusterState

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

the class JmxExporterSpiTest method testIgniteKernal.

/**
 * @throws Exception If failed.
 */
@Test
public void testIgniteKernal() throws Exception {
    DynamicMBean mbn = metricRegistry(ignite.name(), null, IGNITE_METRICS);
    assertNotNull(mbn);
    assertEquals(36, mbn.getMBeanInfo().getAttributes().length);
    assertFalse(stream(mbn.getMBeanInfo().getAttributes()).anyMatch(a -> F.isEmpty(a.getDescription())));
    assertFalse(F.isEmpty((String) mbn.getAttribute("fullVersion")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("copyright")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("osInformation")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("jdkInformation")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("vmName")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("discoverySpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("communicationSpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("deploymentSpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("checkpointSpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("collisionSpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("eventStorageSpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("failoverSpiFormatted")));
    assertFalse(F.isEmpty((String) mbn.getAttribute("loadBalancingSpiFormatted")));
    assertEquals(System.getProperty("user.name"), (String) mbn.getAttribute("osUser"));
    assertNotNull(DateFormat.getDateTimeInstance().parse((String) mbn.getAttribute("startTimestampFormatted")));
    assertNotNull(LocalTime.parse((String) mbn.getAttribute("uptimeFormatted")));
    assertTrue((boolean) mbn.getAttribute("isRebalanceEnabled"));
    assertTrue((boolean) mbn.getAttribute("isNodeInBaseline"));
    assertTrue((boolean) mbn.getAttribute("active"));
    assertTrue((long) mbn.getAttribute("startTimestamp") > 0);
    assertTrue((long) mbn.getAttribute("uptime") > 0);
    assertEquals(ignite.name(), (String) mbn.getAttribute("instanceName"));
    assertEquals(Collections.emptyList(), mbn.getAttribute("userAttributesFormatted"));
    assertEquals(Collections.emptyList(), mbn.getAttribute("lifecycleBeansFormatted"));
    assertEquals(Collections.emptyMap(), mbn.getAttribute("longJVMPauseLastEvents"));
    assertEquals(0L, mbn.getAttribute("longJVMPausesCount"));
    assertEquals(0L, mbn.getAttribute("longJVMPausesTotalDuration"));
    long clusterStateChangeTime = (long) mbn.getAttribute("lastClusterStateChangeTime");
    assertTrue(0 < clusterStateChangeTime && clusterStateChangeTime < System.currentTimeMillis());
    assertEquals(String.valueOf(ignite.configuration().getPublicThreadPoolSize()), mbn.getAttribute("executorServiceFormatted"));
    assertEquals(ignite.configuration().isPeerClassLoadingEnabled(), mbn.getAttribute("isPeerClassLoadingEnabled"));
    assertTrue(((String) mbn.getAttribute("currentCoordinatorFormatted")).contains(ignite.localNode().id().toString()));
    assertEquals(ignite.configuration().getIgniteHome(), (String) mbn.getAttribute("igniteHome"));
    assertEquals(ignite.localNode().id(), mbn.getAttribute("localNodeId"));
    assertEquals(ignite.configuration().getGridLogger().toString(), (String) mbn.getAttribute("gridLoggerFormatted"));
    assertEquals(ignite.configuration().getMBeanServer().toString(), (String) mbn.getAttribute("mBeanServerFormatted"));
    assertEquals(ClusterState.ACTIVE.toString(), mbn.getAttribute("clusterState"));
}
Also used : Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) TestObjectEnum(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum) Map(java.util.Map) FILTER_OPERATION(org.apache.ignite.internal.managers.systemview.SystemViewMBean.FILTER_OPERATION) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) CACHE_METRICS(org.apache.ignite.internal.processors.cache.CacheMetricsImpl.CACHE_METRICS) GC_CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD_DESCRIPTION) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) MBeanOperationInfo(javax.management.MBeanOperationInfo) Set(java.util.Set) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TEST_TRANSFORMER(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER) MBeanFeatureInfo(javax.management.MBeanFeatureInfo) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) DynamicMBean(javax.management.DynamicMBean) VIEWS(org.apache.ignite.internal.managers.systemview.SystemViewMBean.VIEWS) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD_DESCRIPTION) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) BINARY_METADATA_VIEW(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW) DISTRIBUTED_METASTORE_VIEW(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW) IgniteClient(org.apache.ignite.client.IgniteClient) TEST_PREDICATE(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE) TestTransformer(org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer) STREAM_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.STREAM_POOL_QUEUE_VIEW) TASKS_VIEW(org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW) Properties(java.util.Properties) CompositeData(javax.management.openmbean.CompositeData) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Field(java.lang.reflect.Field) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) SCAN_QRY_SYS_VIEW(org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW) CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CachePagesListViewWalker(org.apache.ignite.internal.managers.systemview.walker.CachePagesListViewWalker) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) Connection(java.sql.Connection) ProtocolVersion(org.apache.ignite.internal.client.thin.ProtocolVersion) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) Transaction(org.apache.ignite.transactions.Transaction) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CACHE_GRP_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW) IgniteEx(org.apache.ignite.internal.IgniteEx) METASTORE_VIEW(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalTime(java.time.LocalTime) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) DateFormat(java.text.DateFormat) Collectors.toSet(java.util.stream.Collectors.toSet) CyclicBarrier(java.util.concurrent.CyclicBarrier) SVCS_VIEW(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.SVCS_VIEW) CLI_CONN_VIEW(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) IGNITE_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.IGNITE_METRICS) MetricRegistryMBean.searchHistogram(org.apache.ignite.spi.metric.jmx.MetricRegistryMBean.searchHistogram) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Optional(java.util.Optional) ACTIVE(org.apache.ignite.transactions.TransactionState.ACTIVE) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) SYS_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.SYS_METRICS) DummyService(org.apache.ignite.internal.processors.service.DummyService) Arrays.stream(java.util.Arrays.stream) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) MBeanParameterInfo(javax.management.MBeanParameterInfo) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) CACHES_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) SYS_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.SYS_POOL_QUEUE_VIEW) TestRunnable(org.apache.ignite.internal.metric.SystemViewSelfTest.TestRunnable) GC_CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) TestPredicate(org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate) F(org.apache.ignite.internal.util.typedef.F) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) JdbcConnectionContext(org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext) CACHE_GRPS_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW) TestObjectAllTypes(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes) Consumer(java.util.function.Consumer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Ignition(org.apache.ignite.Ignition) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) DynamicMBean(javax.management.DynamicMBean) Test(org.junit.Test)

Example 3 with ClusterState

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

the class ClusterActivationStartedEventTest method testActivationDeactivationStartedLocalEvents.

/**
 */
@Test
public void testActivationDeactivationStartedLocalEvents() throws Exception {
    AtomicBoolean activationStarted = new AtomicBoolean();
    AtomicBoolean activationFinished = new AtomicBoolean();
    AtomicBoolean deactivationStarted = new AtomicBoolean();
    AtomicBoolean deactivationFinished = new AtomicBoolean();
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(false);
    ignite.events().localListen(event -> {
        ClusterStateChangeStartedEvent changeStartedEvt = (ClusterStateChangeStartedEvent) event;
        ClusterState clusterState = changeStartedEvt.state();
        ClusterState prevState = changeStartedEvt.previousState();
        if (clusterState == ClusterState.ACTIVE) {
            assertEquals(ClusterState.INACTIVE, prevState);
            activationStarted.set(true);
        } else if (clusterState == ClusterState.INACTIVE) {
            assertEquals(ClusterState.ACTIVE, prevState);
            deactivationStarted.set(true);
        } else
            fail("Unexpected event state: " + clusterState);
        return true;
    }, EventType.EVT_CLUSTER_STATE_CHANGE_STARTED);
    ignite.events().localListen(event -> {
        assertTrue(activationStarted.get());
        activationFinished.set(true);
        return true;
    }, EventType.EVT_CLUSTER_ACTIVATED);
    ignite.events().localListen(event -> {
        assertTrue(deactivationStarted.get());
        deactivationFinished.set(true);
        return true;
    }, EventType.EVT_CLUSTER_DEACTIVATED);
    ignite.cluster().active(true);
    assertTrue(activationStarted.get());
    assertTrue(GridTestUtils.waitForCondition(activationFinished::get, 5_000));
    assertFalse(deactivationStarted.get());
    activationStarted.set(false);
    activationFinished.set(false);
    ignite.cluster().active(true);
    assertFalse(activationStarted.get());
    ignite.cluster().active(false);
    assertTrue(deactivationStarted.get());
    assertTrue(GridTestUtils.waitForCondition(deactivationFinished::get, 5_000));
    assertFalse(activationStarted.get());
    deactivationStarted.set(false);
    deactivationFinished.set(false);
    ignite.cluster().active(false);
    assertFalse(deactivationStarted.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterState(org.apache.ignite.cluster.ClusterState) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with ClusterState

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

the class IgniteClusterActivateDeactivateTestWithPersistence method testDeactivateClusterWithPersistentCache.

/**
 * Tests "soft" deactivation (without using the --force flag)
 * when the client node does not have the configured data storage and the cluster contains persistent caches.
 *
 * Expected behavior: the cluster should be deactivated successfully (there is no data loss).
 *
 * @throws Exception If failed.
 */
@Test
public void testDeactivateClusterWithPersistentCache() throws Exception {
    IgniteEx srv = startGrid(0);
    IgniteEx clientNode = startClientGrid(1);
    clientNode.cluster().state(ACTIVE);
    DataRegionConfiguration dfltDataRegion = srv.configuration().getDataStorageConfiguration().getDefaultDataRegionConfiguration();
    assertTrue("It is assumed that the default data storage region is persistent.", dfltDataRegion.isPersistenceEnabled());
    // Create new caches that are placed into the default pesristent data region.
    clientNode.getOrCreateCache(new CacheConfiguration<>("test-client-cache-default-region-implicit"));
    clientNode.getOrCreateCache(new CacheConfiguration<>("test-client-cache-default-region-explicit").setDataRegionName(dfltDataRegion.getName()));
    // Try to deactivate the cluster without the `force` flag.
    IgniteInternalFuture<?> deactivateFut = srv.context().state().changeGlobalState(INACTIVE, false, Collections.emptyList(), false);
    try {
        deactivateFut.get(10, SECONDS);
    } catch (IgniteCheckedException e) {
        log.error("Failed to deactivate the cluster.", e);
        fail("Failed to deactivate the cluster. [err=" + e.getMessage() + ']');
    }
    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 inactive state. " + "[node=" + n.configuration().getIgniteInstanceName() + ", actual=" + state + ']', INACTIVE == state);
    }
}
Also used : ClusterState(org.apache.ignite.cluster.ClusterState) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 5 with ClusterState

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

the class StateCommand method execute.

/**
 * Print cluster state.
 *
 * @param clientCfg Client configuration.
 * @throws Exception If failed to print state.
 */
@Override
public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
    try (GridClient client = Command.startClient(clientCfg)) {
        GridClientClusterState state = client.state();
        UUID id = state.id();
        String tag = state.tag();
        log.info("Cluster  ID: " + id);
        log.info("Cluster tag: " + tag);
        log.info(CommandHandler.DELIM);
        ClusterState clusterState = state.state();
        switch(clusterState) {
            case ACTIVE:
                log.info("Cluster is active");
                break;
            case INACTIVE:
                log.info("Cluster is inactive");
                break;
            case ACTIVE_READ_ONLY:
                log.info("Cluster is active (read-only)");
                break;
            default:
                throw new IllegalStateException("Unknown state: " + clusterState);
        }
    } catch (Throwable e) {
        if (!CommandHandler.isAuthError(e))
            log.severe("Failed to get cluster state.");
        throw e;
    }
    return null;
}
Also used : GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState) ClusterState(org.apache.ignite.cluster.ClusterState) GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState) GridClient(org.apache.ignite.internal.client.GridClient) UUID(java.util.UUID)

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