Search in sources :

Example 6 with DiscoveryDataClusterState

use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.

the class GridDiscoveryManager method topologySnapshotMessage.

/**
 * @param clo Wrapper of logger.
 * @param topVer Topology version.
 * @param discoCache Discovery cache.
 * @param evtType Event type.
 * @param evtNode Event node.
 * @param srvNodesNum Server nodes number.
 * @param clientNodesNum Client nodes number.
 * @param totalCpus Total cpu number.
 * @param heap Heap size.
 * @param offheap Offheap size.
 * @param needNodesDetails Flag for additional alive nodes logging.
 */
private void topologySnapshotMessage(IgniteClosure<String, Void> clo, long topVer, DiscoCache discoCache, int evtType, ClusterNode evtNode, int srvNodesNum, int clientNodesNum, int totalCpus, double heap, double offheap, boolean needNodesDetails) {
    DiscoveryDataClusterState state = discoCache.state();
    SB summary = new SB(PREFIX);
    summary.a(" [");
    summary.a(discoOrdered ? "ver=" + topVer + ", " : "");
    summary.a("locNode=").a(U.id8(discoCache.localNode().id()));
    summary.a(", servers=").a(srvNodesNum);
    summary.a(", clients=").a(clientNodesNum);
    summary.a(", state=").a(state.active() ? "ACTIVE" : "INACTIVE");
    summary.a(", CPUs=").a(totalCpus);
    summary.a(", offheap=").a(offheap).a("GB");
    summary.a(", heap=").a(heap).a("GB");
    if ((evtType == EVT_NODE_JOINED || evtType == EVT_NODE_LEFT || evtType == EVT_NODE_FAILED) && needNodesDetails) {
        summary.a(", aliveNodes=[");
        for (ClusterNode clusterNode : discoCache.allNodes()) {
            if (discoCache.alive(clusterNode.id()))
                summary.a(nodeDescription(clusterNode)).a(", ");
        }
        summary.setLength(summary.length() - 2);
        summary.a(']');
    }
    summary.a(']');
    clo.apply(summary.toString());
    ClusterNode currCrd = discoCache.oldestServerNode();
    if ((evtType == EventType.EVT_NODE_FAILED || evtType == EventType.EVT_NODE_LEFT) && currCrd != null && currCrd.order() > evtNode.order() && !evtNode.isClient() && !evtNode.isDaemon())
        clo.apply("Coordinator changed [prev=" + evtNode + ", cur=" + currCrd + "]");
    BaselineTopology blt = state.baselineTopology();
    if (blt != null && discoCache.baselineNodes() != null) {
        int bltSize = discoCache.baselineNodes().size();
        int bltOnline = discoCache.aliveBaselineNodes().size();
        int bltOffline = bltSize - bltOnline;
        clo.apply("  ^-- Baseline [id=" + blt.id() + ", size=" + bltSize + ", online=" + bltOnline + ", offline=" + bltOffline + ']');
        ClusterState targetState = ctx.config().getClusterStateOnStart();
        if (targetState == null)
            targetState = ctx.config().isAutoActivationEnabled() ? ACTIVE : INACTIVE;
        if (!state.state().active() && targetState.active()) {
            String offlineConsistentIds = "";
            if (bltOffline > 0 && bltOffline <= 5) {
                Collection<BaselineNode> offlineNodes = new HashSet<>(discoCache.baselineNodes());
                offlineNodes.removeAll(discoCache.aliveBaselineNodes());
                offlineConsistentIds = ' ' + F.nodeConsistentIds(offlineNodes).toString();
            }
            if (bltOffline == 0) {
                if (evtType == EVT_NODE_JOINED && discoCache.baselineNode(evtNode))
                    clo.apply("  ^-- All baseline nodes are online, will start auto-activation");
            } else
                clo.apply("  ^-- " + bltOffline + " nodes left for auto-activation" + offlineConsistentIds);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterState(org.apache.ignite.cluster.ClusterState) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) SB(org.apache.ignite.internal.util.typedef.internal.SB) BaselineNode(org.apache.ignite.cluster.BaselineNode) HashSet(java.util.HashSet)

Example 7 with DiscoveryDataClusterState

use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.

the class GridCachePartitionExchangeManager method onClusterStateChangeFinish.

/**
 */
private void onClusterStateChangeFinish(IgniteInternalFuture<AffinityTopologyVersion> fut, ExchangeActions exchActions, boolean baselineChanging) {
    A.notNull(exchActions, "exchActions");
    GridEventStorageManager evtMngr = cctx.kernalContext().event();
    if (exchActions.activate() && evtMngr.isRecordable(EVT_CLUSTER_ACTIVATED) || exchActions.deactivate() && evtMngr.isRecordable(EVT_CLUSTER_DEACTIVATED) || exchActions.changedClusterState() && evtMngr.isRecordable(EVT_CLUSTER_STATE_CHANGED)) {
        List<Event> evts = new ArrayList<>(2);
        ClusterNode locNode = cctx.kernalContext().discovery().localNode();
        Collection<BaselineNode> bltNodes = cctx.kernalContext().cluster().get().currentBaselineTopology();
        boolean collectionUsed = false;
        if (exchActions.activate() && evtMngr.isRecordable(EVT_CLUSTER_ACTIVATED)) {
            assert !exchActions.deactivate() : exchActions;
            collectionUsed = true;
            evts.add(new ClusterActivationEvent(locNode, "Cluster activated.", EVT_CLUSTER_ACTIVATED, bltNodes));
        }
        if (exchActions.deactivate() && evtMngr.isRecordable(EVT_CLUSTER_DEACTIVATED)) {
            assert !exchActions.activate() : exchActions;
            collectionUsed = true;
            evts.add(new ClusterActivationEvent(locNode, "Cluster deactivated.", EVT_CLUSTER_DEACTIVATED, bltNodes));
        }
        if (exchActions.changedClusterState() && evtMngr.isRecordable(EVT_CLUSTER_STATE_CHANGED)) {
            StateChangeRequest req = exchActions.stateChangeRequest();
            if (collectionUsed && bltNodes != null)
                bltNodes = new ArrayList<>(bltNodes);
            evts.add(new ClusterStateChangeEvent(req.prevState(), req.state(), bltNodes, locNode, "Cluster state changed."));
        }
        A.notEmpty(evts, "events " + exchActions);
        cctx.kernalContext().pools().getSystemExecutorService().submit(() -> evts.forEach(e -> cctx.kernalContext().event().record(e)));
    }
    GridKernalContext ctx = cctx.kernalContext();
    DiscoveryDataClusterState state = ctx.state().clusterState();
    if (baselineChanging) {
        ctx.pools().getStripedExecutorService().execute(new Runnable() {

            @Override
            public void run() {
                if (ctx.event().isRecordable(EventType.EVT_BASELINE_CHANGED)) {
                    ctx.event().record(new BaselineChangedEvent(ctx.discovery().localNode(), "Baseline changed.", EventType.EVT_BASELINE_CHANGED, ctx.cluster().get().currentBaselineTopology()));
                }
            }
        });
    }
}
Also used : GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) RebalanceFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander.RebalanceFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) GridDhtPartitionsSingleRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleRequest) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) Map(java.util.Map) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ClusterActivationEvent(org.apache.ignite.events.ClusterActivationEvent) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) FinishPreloadingTask(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.FinishPreloadingTask) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) ChangeGlobalStateFinishMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage) TRANSACTION_OWNER_THREAD_DUMP_PROVIDING(org.apache.ignite.internal.IgniteFeatures.TRANSACTION_OWNER_THREAD_DUMP_PROVIDING) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IGNITE_DIAGNOSTIC_WARN_LIMIT(org.apache.ignite.IgniteSystemProperties.IGNITE_DIAGNOSTIC_WARN_LIMIT) CountDownLatch(java.util.concurrent.CountDownLatch) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteDhtPartitionsToReloadMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionsToReloadMap) SYSTEM_WORKER_TERMINATION(org.apache.ignite.failure.FailureType.SYSTEM_WORKER_TERMINATION) DiscoveryLocalJoinData(org.apache.ignite.internal.managers.discovery.DiscoveryLocalJoinData) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridListSet(org.apache.ignite.internal.util.GridListSet) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IgniteCompute(org.apache.ignite.IgniteCompute) IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) IgniteThread(org.apache.ignite.thread.IgniteThread) SecurityUtils.remoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.remoteSecurityContext) ClusterState(org.apache.ignite.cluster.ClusterState) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_DISCOVERY_CUSTOM_EVT(org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteDiagnosticAware(org.apache.ignite.internal.IgniteDiagnosticAware) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) EXCHANGE_FUTURE(org.apache.ignite.internal.processors.tracing.SpanType.EXCHANGE_FUTURE) IGNITE_IO_DUMP_ON_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_IO_DUMP_ON_TIMEOUT) A(org.apache.ignite.internal.util.typedef.internal.A) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) Ignite(org.apache.ignite.Ignite) BaselineNode(org.apache.ignite.cluster.BaselineNode) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) RebalanceReassignExchangeTask(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.RebalanceReassignExchangeTask) T2(org.apache.ignite.internal.util.typedef.T2) NONE(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion.NONE) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) CLUSTER_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.CLUSTER_METRICS) GridDhtPartitionsExchangeFuture.nextDumpTimeout(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.nextDumpTimeout) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) CRITICAL_ERROR(org.apache.ignite.failure.FailureType.CRITICAL_ERROR) SYSTEM_POOL(org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) ExchangeLatchManager(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.latch.ExchangeLatchManager) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) StopCachesOnClientReconnectExchangeTask(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.StopCachesOnClientReconnectExchangeTask) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) PME_OPS_BLOCKED_DURATION(org.apache.ignite.internal.processors.metric.GridMetricManager.PME_OPS_BLOCKED_DURATION) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BooleanMetricImpl(org.apache.ignite.internal.processors.metric.impl.BooleanMetricImpl) X(org.apache.ignite.internal.util.typedef.X) IgniteDhtPartitionHistorySuppliersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtPartitionHistorySuppliersMap) PME_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.PME_METRICS) IgniteFuture(org.apache.ignite.lang.IgniteFuture) SecurityUtils.withRemoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.withRemoteSecurityContext) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) EventType(org.apache.ignite.events.EventType) OperationSecurityContext(org.apache.ignite.internal.processors.security.OperationSecurityContext) IgniteFeatures.allNodesSupports(org.apache.ignite.internal.IgniteFeatures.allNodesSupports) Collection(java.util.Collection) SpanTags(org.apache.ignite.internal.processors.tracing.SpanTags) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EVT_CLUSTER_ACTIVATED(org.apache.ignite.events.EventType.EVT_CLUSTER_ACTIVATED) NavigableSet(java.util.NavigableSet) IgniteDiagnosticPrepareContext(org.apache.ignite.internal.IgniteDiagnosticPrepareContext) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) UUID(java.util.UUID) Instant(java.time.Instant) CI2(org.apache.ignite.internal.util.typedef.CI2) Collectors(java.util.stream.Collectors) IGNITE_PRELOAD_RESEND_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_PRELOAD_RESEND_TIMEOUT) IgniteSystemProperties.getLong(org.apache.ignite.IgniteSystemProperties.getLong) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) DiscoveryEventListener(org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) TOPIC_CACHE(org.apache.ignite.internal.GridTopic.TOPIC_CACHE) BaselineChangedEvent(org.apache.ignite.events.BaselineChangedEvent) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridDhtPartitionDemandLegacyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandLegacyMessage) Optional(java.util.Optional) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) ForceRebalanceExchangeTask(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.ForceRebalanceExchangeTask) PME_DURATION_HISTOGRAM(org.apache.ignite.internal.processors.metric.GridMetricManager.PME_DURATION_HISTOGRAM) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Span(org.apache.ignite.internal.processors.tracing.Span) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) DFLT_PRELOAD_RESEND_TIMEOUT(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader.DFLT_PRELOAD_RESEND_TIMEOUT) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SchemaNodeLeaveExchangeWorkerTask(org.apache.ignite.internal.processors.query.schema.SchemaNodeLeaveExchangeWorkerTask) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridClientPartitionTopology) FailureContext(org.apache.ignite.failure.FailureContext) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) PME_OPS_BLOCKED_DURATION_HISTOGRAM(org.apache.ignite.internal.processors.metric.GridMetricManager.PME_OPS_BLOCKED_DURATION_HISTOGRAM) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EVT_CLUSTER_DEACTIVATED(org.apache.ignite.events.EventType.EVT_CLUSTER_DEACTIVATED) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) EVT_CLUSTER_STATE_CHANGED(org.apache.ignite.events.EventType.EVT_CLUSTER_STATE_CHANGED) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) PARTIAL_COUNTERS_MAP_SINCE(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap.PARTIAL_COUNTERS_MAP_SINCE) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) TimeUnit(java.util.concurrent.TimeUnit) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) TransactionState(org.apache.ignite.transactions.TransactionState) PME_DURATION(org.apache.ignite.internal.processors.metric.GridMetricManager.PME_DURATION) REBALANCED(org.apache.ignite.internal.processors.metric.GridMetricManager.REBALANCED) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) Comparator(java.util.Comparator) Collections(java.util.Collections) GridKernalContext(org.apache.ignite.internal.GridKernalContext) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) BaselineNode(org.apache.ignite.cluster.BaselineNode) ClusterActivationEvent(org.apache.ignite.events.ClusterActivationEvent) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) ClusterActivationEvent(org.apache.ignite.events.ClusterActivationEvent) Event(org.apache.ignite.events.Event) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) BaselineChangedEvent(org.apache.ignite.events.BaselineChangedEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) BaselineChangedEvent(org.apache.ignite.events.BaselineChangedEvent)

Example 8 with DiscoveryDataClusterState

use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.

the class IgniteSnapshotManager method createSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public IgniteFuture<Void> createSnapshot(String name) {
    A.notNullOrEmpty(name, "Snapshot name cannot be null or empty.");
    A.ensure(U.alphanumericUnderscore(name), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
    try {
        cctx.kernalContext().security().authorize(ADMIN_SNAPSHOT);
        if (!IgniteFeatures.allNodesSupports(cctx.discovery().aliveServerNodes(), PERSISTENCE_CACHE_SNAPSHOT))
            throw new IgniteException("Not all nodes in the cluster support a snapshot operation.");
        if (!CU.isPersistenceEnabled(cctx.gridConfig())) {
            throw new IgniteException("Create snapshot request has been rejected. Snapshots on an in-memory " + "clusters are not allowed.");
        }
        if (!cctx.kernalContext().state().clusterState().state().active())
            throw new IgniteException("Snapshot operation has been rejected. The cluster is inactive.");
        DiscoveryDataClusterState clusterState = cctx.kernalContext().state().clusterState();
        if (!clusterState.hasBaselineTopology())
            throw new IgniteException("Snapshot operation has been rejected. The baseline topology is not configured for cluster.");
        if (cctx.kernalContext().clientNode()) {
            ClusterNode crd = U.oldest(cctx.kernalContext().discovery().aliveServerNodes(), null);
            if (crd == null)
                throw new IgniteException("There is no alive server nodes in the cluster");
            return new IgniteSnapshotFutureImpl(cctx.kernalContext().closure().callAsyncNoFailover(BALANCE, new CreateSnapshotCallable(name), Collections.singletonList(crd), false, 0, true));
        }
        ClusterSnapshotFuture snpFut0;
        synchronized (snpOpMux) {
            if (clusterSnpFut != null && !clusterSnpFut.isDone()) {
                throw new IgniteException("Create snapshot request has been rejected. The previous snapshot operation was not completed.");
            }
            if (clusterSnpReq != null)
                throw new IgniteException("Create snapshot request has been rejected. Parallel snapshot processes are not allowed.");
            if (localSnapshotNames().contains(name)) {
                throw new IgniteException("Create snapshot request has been rejected. Snapshot with given name already exists on local node.");
            }
            if (isRestoring()) {
                throw new IgniteException("Snapshot operation has been rejected. Cache group restore operation is currently in progress.");
            }
            snpFut0 = new ClusterSnapshotFuture(UUID.randomUUID(), name);
            clusterSnpFut = snpFut0;
            lastSeenSnpFut = snpFut0;
        }
        List<String> grps = cctx.cache().persistentGroups().stream().filter(g -> cctx.cache().cacheType(g.cacheOrGroupName()) == CacheType.USER).map(CacheGroupDescriptor::cacheOrGroupName).collect(Collectors.toList());
        grps.add(METASTORAGE_CACHE_NAME);
        List<ClusterNode> srvNodes = cctx.discovery().serverNodes(AffinityTopologyVersion.NONE);
        snpFut0.listen(f -> {
            if (f.error() == null)
                recordSnapshotEvent(name, SNAPSHOT_FINISHED_MSG + grps, EVT_CLUSTER_SNAPSHOT_FINISHED);
            else
                recordSnapshotEvent(name, SNAPSHOT_FAILED_MSG + f.error().getMessage(), EVT_CLUSTER_SNAPSHOT_FAILED);
        });
        startSnpProc.start(snpFut0.rqId, new SnapshotOperationRequest(snpFut0.rqId, cctx.localNodeId(), name, grps, new HashSet<>(F.viewReadOnly(srvNodes, F.node2id(), (node) -> CU.baselineNode(node, clusterState)))));
        String msg = "Cluster-wide snapshot operation started [snpName=" + name + ", grps=" + grps + ']';
        recordSnapshotEvent(name, msg, EVT_CLUSTER_SNAPSHOT_STARTED);
        if (log.isInfoEnabled())
            log.info(msg);
        return new IgniteFutureImpl<>(snpFut0);
    } catch (Exception e) {
        recordSnapshotEvent(name, SNAPSHOT_FAILED_MSG + e.getMessage(), EVT_CLUSTER_SNAPSHOT_FAILED);
        U.error(log, SNAPSHOT_FAILED_MSG, e);
        lastSeenSnpFut = new ClusterSnapshotFuture(name, e);
        return new IgniteFinishedFutureImpl<>(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName) EVT_CLUSTER_SNAPSHOT_FINISHED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_FINISHED) BufferedInputStream(java.io.BufferedInputStream) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) MetastorageLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener) CacheObjectBinaryProcessorImpl.binaryWorkDir(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.binaryWorkDir) ReadOnlyMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) METASTORAGE_CACHE_ID(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_ID) Map(java.util.Map) TransmissionHandler(org.apache.ignite.internal.managers.communication.TransmissionHandler) Path(java.nio.file.Path) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Serializable(java.io.Serializable) ByteOrder(java.nio.ByteOrder) FileVisitResult(java.nio.file.FileVisitResult) SnapshotEvent(org.apache.ignite.events.SnapshotEvent) END_SNAPSHOT(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.END_SNAPSHOT) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_DISCOVERY_CUSTOM_EVT(org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) IgniteLogger(org.apache.ignite.IgniteLogger) EVT_CLUSTER_SNAPSHOT_STARTED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_STARTED) PageIO.getVersion(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getVersion) ReadWriteMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage) S(org.apache.ignite.internal.util.typedef.internal.S) METASTORAGE_CACHE_NAME(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME) GridInternal(org.apache.ignite.internal.processors.task.GridInternal) A(org.apache.ignite.internal.util.typedef.internal.A) MarshallerContextImpl.resolveMappingFileStoreWorkDir(org.apache.ignite.internal.MarshallerContextImpl.resolveMappingFileStoreWorkDir) IOException(java.io.IOException) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) T2(org.apache.ignite.internal.util.typedef.T2) BinaryType(org.apache.ignite.binary.BinaryType) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DFLT_BINARY_METADATA_PATH(org.apache.ignite.configuration.DataStorageConfiguration.DFLT_BINARY_METADATA_PATH) GroupPartitionId.getTypeByPartId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId.getTypeByPartId) PageIdUtils.flag(org.apache.ignite.internal.pagemem.PageIdUtils.flag) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) START_SNAPSHOT(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.START_SNAPSHOT) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) PageIdUtils.pageId(org.apache.ignite.internal.pagemem.PageIdUtils.pageId) PageIdUtils.toDetailString(org.apache.ignite.internal.pagemem.PageIdUtils.toDetailString) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) IgniteFeatures.nodeSupports(org.apache.ignite.internal.IgniteFeatures.nodeSupports) BiFunction(java.util.function.BiFunction) SYSTEM_POOL(org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MarshallerContextImpl.mappingFileStoreWorkDir(org.apache.ignite.internal.MarshallerContextImpl.mappingFileStoreWorkDir) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) FastCrc(org.apache.ignite.internal.processors.cache.persistence.wal.crc.FastCrc) InitMessage(org.apache.ignite.internal.util.distributed.InitMessage) FilePageStoreManager.cacheDirectories(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirectories) CU(org.apache.ignite.internal.util.typedef.internal.CU) Queue(java.util.Queue) FilePageStoreManager.getPartitionFile(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFile) MarshallerUtils(org.apache.ignite.marshaller.MarshallerUtils) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload) SnapshotViewWalker(org.apache.ignite.internal.managers.systemview.walker.SnapshotViewWalker) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SnapshotView(org.apache.ignite.spi.systemview.view.SnapshotView) GridUnsafe.bufferAddress(org.apache.ignite.internal.util.GridUnsafe.bufferAddress) DFLT_MARSHALLER_PATH(org.apache.ignite.configuration.DataStorageConfiguration.DFLT_MARSHALLER_PATH) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) TC_SUBGRID(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_SUBGRID) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GroupPartitionId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId) FileInputStream(java.io.FileInputStream) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) Consumer(java.util.function.Consumer) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) BitSet(java.util.BitSet) FileChannel(java.nio.channels.FileChannel) IgniteSnapshot(org.apache.ignite.IgniteSnapshot) TransmissionMeta(org.apache.ignite.internal.managers.communication.TransmissionMeta) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) Arrays(java.util.Arrays) CacheType(org.apache.ignite.internal.processors.cache.CacheType) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) MAX_PARTITION_ID(org.apache.ignite.internal.pagemem.PageIdAllocator.MAX_PARTITION_ID) BooleanSupplier(java.util.function.BooleanSupplier) DirectoryStream(java.nio.file.DirectoryStream) GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) MarshallerContextImpl.saveMappings(org.apache.ignite.internal.MarshallerContextImpl.saveMappings) ComputeTask(org.apache.ignite.compute.ComputeTask) T_DATA(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.T_DATA) DataRow(org.apache.ignite.internal.processors.cache.tree.DataRow) PERSISTENCE_CACHE_SNAPSHOT(org.apache.ignite.internal.IgniteFeatures.PERSISTENCE_CACHE_SNAPSHOT) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) EnumMap(java.util.EnumMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridBusyLock(org.apache.ignite.internal.util.GridBusyLock) TransmissionCancelledException(org.apache.ignite.internal.managers.communication.TransmissionCancelledException) CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter) PageIO.getType(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getType) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PageIdUtils.pageIndex(org.apache.ignite.internal.pagemem.PageIdUtils.pageIndex) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteUtils.isLocalNodeCoordinator(org.apache.ignite.internal.util.IgniteUtils.isLocalNodeCoordinator) CacheObjectBinaryProcessorImpl.resolveBinaryWorkDir(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.resolveBinaryWorkDir) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) READ(java.nio.file.StandardOpenOption.READ) ClusterNode(org.apache.ignite.cluster.ClusterNode) DB_DEFAULT_FOLDER(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.DB_DEFAULT_FOLDER) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) BiConsumer(java.util.function.BiConsumer) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) TC_SKIP_AUTH(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_SKIP_AUTH) FileOutputStream(java.io.FileOutputStream) Marshaller(org.apache.ignite.marshaller.Marshaller) File(java.io.File) GridTopic(org.apache.ignite.internal.GridTopic) Paths(java.nio.file.Paths) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl) SNAPSHOT_SYS_VIEW(org.apache.ignite.spi.systemview.view.SnapshotView.SNAPSHOT_SYS_VIEW) ArrayDeque(java.util.ArrayDeque) IgniteUuid(org.apache.ignite.lang.IgniteUuid) FLAG_DATA(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteChangeGlobalStateSupport(org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport) ByteBuffer(java.nio.ByteBuffer) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) SNAPSHOT_SYS_VIEW_DESC(org.apache.ignite.spi.systemview.view.SnapshotView.SNAPSHOT_SYS_VIEW_DESC) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) IgniteFuture(org.apache.ignite.lang.IgniteFuture) PART_FILE_TEMPLATE(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.PART_FILE_TEMPLATE) FailureType(org.apache.ignite.failure.FailureType) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) Predicate(java.util.function.Predicate) IgniteException(org.apache.ignite.IgniteException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridCacheSharedManagerAdapter(org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) DiscoveryEventListener(org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) FilePageStoreManager.getPartitionFileName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFileName) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) HashMap(java.util.HashMap) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) Deque(java.util.Deque) EVT_CLUSTER_SNAPSHOT_FAILED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_FAILED) IgniteCallable(org.apache.ignite.lang.IgniteCallable) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) FailureContext(org.apache.ignite.failure.FailureContext) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) BALANCE(org.apache.ignite.internal.GridClosureCallMode.BALANCE) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) IgniteThrowableFunction(org.apache.ignite.internal.util.lang.IgniteThrowableFunction) DistributedMetaStorageImpl(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl) OutputStream(java.io.OutputStream) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) F(org.apache.ignite.internal.util.typedef.F) PageIO.getPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getPageIO) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TransmissionPolicy(org.apache.ignite.internal.managers.communication.TransmissionPolicy) ADMIN_SNAPSHOT(org.apache.ignite.plugin.security.SecurityPermission.ADMIN_SNAPSHOT) INDEX_FILE_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.INDEX_FILE_NAME) Collections(java.util.Collections) InputStream(java.io.InputStream) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) PageIdUtils.toDetailString(org.apache.ignite.internal.pagemem.PageIdUtils.toDetailString) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransmissionCancelledException(org.apache.ignite.internal.managers.communication.TransmissionCancelledException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) HashSet(java.util.HashSet)

Example 9 with DiscoveryDataClusterState

use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.

the class SnapshotRestoreProcess method start.

/**
 * Start cache group restore operation.
 *
 * @param snpName Snapshot name.
 * @param cacheGrpNames Cache groups to be restored or {@code null} to restore all cache groups from the snapshot.
 * @return Future that will be completed when the restore operation is complete and the cache groups are started.
 */
public IgniteFuture<Void> start(String snpName, @Nullable Collection<String> cacheGrpNames) {
    IgniteSnapshotManager snpMgr = ctx.cache().context().snapshotMgr();
    ClusterSnapshotFuture fut0;
    try {
        if (ctx.clientNode())
            throw new IgniteException(OP_REJECT_MSG + "Client and daemon nodes can not perform this operation.");
        DiscoveryDataClusterState clusterState = ctx.state().clusterState();
        if (clusterState.state() != ClusterState.ACTIVE || clusterState.transition())
            throw new IgniteException(OP_REJECT_MSG + "The cluster should be active.");
        if (!clusterState.hasBaselineTopology())
            throw new IgniteException(OP_REJECT_MSG + "The baseline topology is not configured for cluster.");
        if (!IgniteFeatures.allNodesSupports(ctx.grid().cluster().nodes(), SNAPSHOT_RESTORE_CACHE_GROUP))
            throw new IgniteException(OP_REJECT_MSG + "Not all nodes in the cluster support restore operation.");
        if (snpMgr.isSnapshotCreating())
            throw new IgniteException(OP_REJECT_MSG + "A cluster snapshot operation is in progress.");
        synchronized (this) {
            if (restoringSnapshotName() != null)
                throw new IgniteException(OP_REJECT_MSG + "The previous snapshot restore operation was not completed.");
            fut = new ClusterSnapshotFuture(UUID.randomUUID(), snpName);
            fut0 = fut;
        }
    } catch (IgniteException e) {
        snpMgr.recordSnapshotEvent(snpName, OP_FAILED_MSG + ": " + e.getMessage(), EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED);
        return new IgniteFinishedFutureImpl<>(e);
    }
    fut0.listen(f -> {
        if (f.error() != null) {
            snpMgr.recordSnapshotEvent(snpName, OP_FAILED_MSG + ": " + f.error().getMessage() + " [reqId=" + fut0.rqId + "].", EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED);
        } else {
            snpMgr.recordSnapshotEvent(snpName, OP_FINISHED_MSG + " [reqId=" + fut0.rqId + "].", EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED);
        }
    });
    String msg = "Cluster-wide snapshot restore operation started [reqId=" + fut0.rqId + ", snpName=" + snpName + (cacheGrpNames == null ? "" : ", caches=" + cacheGrpNames) + ']';
    if (log.isInfoEnabled())
        log.info(msg);
    snpMgr.recordSnapshotEvent(snpName, msg, EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED);
    snpMgr.checkSnapshot(snpName, cacheGrpNames, true).listen(f -> {
        if (f.error() != null) {
            finishProcess(fut0.rqId, f.error());
            return;
        }
        if (!F.isEmpty(f.result().exceptions())) {
            finishProcess(fut0.rqId, F.first(f.result().exceptions().values()));
            return;
        }
        if (fut0.interruptEx != null) {
            finishProcess(fut0.rqId, fut0.interruptEx);
            return;
        }
        Set<UUID> dataNodes = new HashSet<>();
        Set<String> snpBltNodes = null;
        Map<ClusterNode, List<SnapshotMetadata>> metas = f.result().metas();
        Map<Integer, String> reqGrpIds = cacheGrpNames == null ? Collections.emptyMap() : cacheGrpNames.stream().collect(Collectors.toMap(CU::cacheId, v -> v));
        for (Map.Entry<ClusterNode, List<SnapshotMetadata>> entry : metas.entrySet()) {
            dataNodes.add(entry.getKey().id());
            for (SnapshotMetadata meta : entry.getValue()) {
                assert meta != null : entry.getKey().id();
                if (snpBltNodes == null)
                    snpBltNodes = new HashSet<>(meta.baselineNodes());
                reqGrpIds.keySet().removeAll(meta.partitions().keySet());
            }
        }
        if (snpBltNodes == null) {
            finishProcess(fut0.rqId, new IllegalArgumentException(OP_REJECT_MSG + "No snapshot data " + "has been found [groups=" + reqGrpIds.values() + ", snapshot=" + snpName + ']'));
            return;
        }
        if (!reqGrpIds.isEmpty()) {
            finishProcess(fut0.rqId, new IllegalArgumentException(OP_REJECT_MSG + "Cache group(s) was not " + "found in the snapshot [groups=" + reqGrpIds.values() + ", snapshot=" + snpName + ']'));
            return;
        }
        Collection<UUID> bltNodes = F.viewReadOnly(ctx.discovery().discoCache().aliveBaselineNodes(), F.node2id());
        SnapshotOperationRequest req = new SnapshotOperationRequest(fut0.rqId, F.first(dataNodes), snpName, cacheGrpNames, new HashSet<>(bltNodes));
        prepareRestoreProc.start(req.requestId(), req);
    });
    return new IgniteFutureImpl<>(fut0);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CU(org.apache.ignite.internal.util.typedef.internal.CU) IgniteException(org.apache.ignite.IgniteException) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ClusterSnapshotFuture(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.ClusterSnapshotFuture) HashSet(java.util.HashSet)

Example 10 with DiscoveryDataClusterState

use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.

the class ClusterCachesInfo method onCacheChangeRequested.

/**
 * @param batch Cache change request.
 * @param topVer Topology version.
 * @return {@code True} if minor topology version should be increased.
 */
public boolean onCacheChangeRequested(DynamicCacheChangeBatch batch, AffinityTopologyVersion topVer) {
    DiscoveryDataClusterState state = ctx.state().clusterState();
    if (state.active() && !state.transition()) {
        Set<IgniteUuid> restartIds = new HashSet<>(F.viewReadOnly(batch.requests(), DynamicCacheChangeRequest::restartId, req -> req.start() && req.restartId() != null));
        assert restartIds.size() <= 1 : batch.requests();
        Collection<UUID> nodes = ctx.cache().context().snapshotMgr().cacheStartRequiredAliveNodes(F.first(restartIds));
        for (UUID nodeId : nodes) {
            ClusterNode node = ctx.discovery().node(nodeId);
            if (node != null && CU.baselineNode(node, state) && ctx.discovery().alive(node))
                continue;
            ClusterTopologyCheckedException err = new ClusterTopologyCheckedException("Required node has left the cluster [nodeId=" + nodeId + ']');
            for (DynamicCacheChangeRequest req : batch.requests()) ctx.cache().completeCacheStartFuture(req, false, err);
            return false;
        }
        ExchangeActions exchangeActions = new ExchangeActions();
        CacheChangeProcessResult res = processCacheChangeRequests(exchangeActions, batch.requests(), topVer, false);
        if (res.needExchange) {
            assert !exchangeActions.empty() : exchangeActions;
            batch.exchangeActions(exchangeActions);
            if (!nodes.isEmpty())
                exchangeActions.cacheStartRequiredAliveNodes(nodes);
        }
        return res.needExchange;
    } else {
        IgniteCheckedException err = new IgniteCheckedException("Failed to start/stop cache, cluster state change " + "is in progress.");
        for (DynamicCacheChangeRequest req : batch.requests()) {
            if (req.template()) {
                ctx.cache().completeTemplateAddFuture(req.startCacheConfiguration().getName(), req.deploymentId());
            } else
                ctx.cache().completeCacheStartFuture(req, false, err);
        }
        return false;
    }
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) CacheGroupViewWalker(org.apache.ignite.internal.managers.systemview.walker.CacheGroupViewWalker) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) GridCachePluginContext(org.apache.ignite.internal.GridCachePluginContext) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) IgniteNodeAttributes(org.apache.ignite.internal.IgniteNodeAttributes) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) GridFunc(org.apache.ignite.internal.util.lang.GridFunc) Map(java.util.Map) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) QueryEntity(org.apache.ignite.cache.QueryEntity) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) CacheViewWalker(org.apache.ignite.internal.managers.systemview.walker.CacheViewWalker) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) LOCAL(org.apache.ignite.cache.CacheMode.LOCAL) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ChangeGlobalStateFinishMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) Nullable(org.jetbrains.annotations.Nullable) CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) CacheView(org.apache.ignite.spi.systemview.view.CacheView) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) CacheExistsException(org.apache.ignite.cache.CacheExistsException) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) CachePluginContext(org.apache.ignite.plugin.CachePluginContext) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SNP_IN_PROGRESS_ERR_MSG(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNP_IN_PROGRESS_ERR_MSG) ClusterNode(org.apache.ignite.cluster.ClusterNode) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) CachePluginProvider(org.apache.ignite.plugin.CachePluginProvider) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) QuerySchemaPatch(org.apache.ignite.internal.processors.query.QuerySchemaPatch) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) Iterator(java.util.Iterator) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager) CacheGroupView(org.apache.ignite.spi.systemview.view.CacheGroupView) T2(org.apache.ignite.internal.util.typedef.T2) PluginProvider(org.apache.ignite.plugin.PluginProvider) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) CACHE_PROC(org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.CACHE_PROC) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Comparator(java.util.Comparator) Collections(java.util.Collections) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) HashSet(java.util.HashSet) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

DiscoveryDataClusterState (org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 UUID (java.util.UUID)5 List (java.util.List)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 IgniteException (org.apache.ignite.IgniteException)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 GridKernalContext (org.apache.ignite.internal.GridKernalContext)4 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 CU (org.apache.ignite.internal.util.typedef.internal.CU)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 Collection (java.util.Collection)3