Search in sources :

Example 1 with DiscoveryDataClusterState

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

the class GridCacheProcessor method onReconnected.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<?> onReconnected(boolean clusterRestarted) throws IgniteCheckedException {
    List<GridCacheAdapter> reconnected = new ArrayList<>(caches.size());
    DiscoveryDataClusterState state = ctx.state().clusterState();
    boolean active = state.active() && !state.transition();
    ClusterCachesReconnectResult reconnectRes = cachesInfo.onReconnected(active, state.transition());
    final List<GridCacheAdapter> stoppedCaches = new ArrayList<>();
    // Close SQL caches which were not started by client.
    for (String cacheToStop : reconnectRes.stoppedCaches()) {
        if (!caches.keySet().contains(cacheToStop))
            ctx.query().onCacheStop(cacheToStop);
    }
    for (final GridCacheAdapter cache : caches.values()) {
        boolean stopped = reconnectRes.stoppedCacheGroups().contains(cache.context().groupId()) || reconnectRes.stoppedCaches().contains(cache.name());
        if (stopped)
            stopCacheOnReconnect(cache.context(), stoppedCaches);
        else {
            cache.onReconnected();
            reconnected.add(cache);
            if (cache.context().userCache()) {
                DynamicCacheDescriptor desc = cacheDescriptor(cache.name());
                assert desc != null : cache.name();
                if (!QueryUtils.isEnabled(cache.context().config()) && QueryUtils.isEnabled(desc.cacheConfiguration())) {
                    CacheConfiguration newCfg = desc.cacheConfiguration();
                    cache.context().onSchemaAddQueryEntity(newCfg.getQueryEntities(), newCfg.getSqlSchema(), newCfg.isSqlEscapeAll(), newCfg.getQueryParallelism());
                }
                boolean rmvIdx = !cache.context().group().persistenceEnabled();
                // Re-create cache structures inside indexing in order to apply recent schema changes.
                GridCacheContextInfo cacheInfo = new GridCacheContextInfo(cache.context(), false);
                ctx.query().onCacheStop0(cacheInfo, rmvIdx);
                ctx.query().onCacheStart0(cacheInfo, desc.schema(), desc.sql());
            }
        }
    }
    final Set<Integer> stoppedGrps = reconnectRes.stoppedCacheGroups();
    for (CacheGroupContext grp : cacheGrps.values()) {
        if (stoppedGrps.contains(grp.groupId()))
            cacheGrps.remove(grp.groupId());
        else
            grp.onReconnected();
    }
    sharedCtx.onReconnected(active);
    for (GridCacheAdapter cache : reconnected) cache.context().gate().reconnected(false);
    if (!stoppedCaches.isEmpty())
        return sharedCtx.exchange().deferStopCachesOnClientReconnect(stoppedCaches);
    return null;
}
Also used : ArrayList(java.util.ArrayList) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 2 with DiscoveryDataClusterState

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

the class GridCachePartitionExchangeManager method onDiscoveryEvent.

/**
 * @param evt Event.
 * @param cache Discovery data cache.
 */
private void onDiscoveryEvent(DiscoveryEvent evt, DiscoCache cache) {
    ClusterNode loc = cctx.localNode();
    assert evt.type() == EVT_NODE_JOINED || evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED || evt.type() == EVT_DISCOVERY_CUSTOM_EVT;
    final ClusterNode n = evt.eventNode();
    GridDhtPartitionExchangeId exchId = null;
    GridDhtPartitionsExchangeFuture exchFut = null;
    if (evt.type() != EVT_DISCOVERY_CUSTOM_EVT) {
        assert evt.type() != EVT_NODE_JOINED || n.isLocal() || n.order() > loc.order() : "Node joined with smaller-than-local " + "order [newOrder=" + n.order() + ", locOrder=" + loc.order() + ", evt=" + evt + ']';
        exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
        ExchangeActions exchActs = null;
        boolean locJoin = evt.type() == EVT_NODE_JOINED && evt.eventNode().isLocal();
        if (locJoin) {
            LocalJoinCachesContext locJoinCtx = cctx.cache().localJoinCachesContext();
            if (locJoinCtx != null) {
                exchActs = new ExchangeActions();
                exchActs.localJoinContext(locJoinCtx);
            }
        }
        if (!n.isClient() && !n.isDaemon())
            exchActs = cctx.kernalContext().state().autoAdjustExchangeActions(exchActs);
        exchFut = exchangeFuture(exchId, evt, cache, exchActs, null);
    } else {
        DiscoveryCustomMessage customMsg = ((DiscoveryCustomEvent) evt).customMessage();
        if (customMsg instanceof ChangeGlobalStateMessage) {
            ChangeGlobalStateMessage stateChangeMsg = (ChangeGlobalStateMessage) customMsg;
            ExchangeActions exchActions = stateChangeMsg.exchangeActions();
            if (exchActions != null) {
                exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
                exchFut = exchangeFuture(exchId, evt, cache, exchActions, null);
                boolean baselineChanging;
                if (stateChangeMsg.forceChangeBaselineTopology())
                    baselineChanging = true;
                else {
                    DiscoveryDataClusterState state = cctx.kernalContext().state().clusterState();
                    assert state.transition() : state;
                    baselineChanging = exchActions.changedBaseline() || // Or it is the first activation.
                    state.state() != ClusterState.INACTIVE && !state.previouslyActive() && state.previousBaselineTopology() == null;
                }
                exchFut.listen(f -> onClusterStateChangeFinish(f, exchActions, baselineChanging));
            }
        } else if (customMsg instanceof DynamicCacheChangeBatch) {
            DynamicCacheChangeBatch batch = (DynamicCacheChangeBatch) customMsg;
            ExchangeActions exchActions = batch.exchangeActions();
            if (exchActions != null) {
                exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
                exchFut = exchangeFuture(exchId, evt, cache, exchActions, null);
            }
        } else if (customMsg instanceof CacheAffinityChangeMessage) {
            CacheAffinityChangeMessage msg = (CacheAffinityChangeMessage) customMsg;
            if (msg.exchangeId() == null) {
                if (msg.exchangeNeeded()) {
                    exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
                    exchFut = exchangeFuture(exchId, evt, cache, null, msg);
                }
            } else if (msg.exchangeId().topologyVersion().topologyVersion() >= cctx.discovery().localJoinEvent().topologyVersion())
                exchangeFuture(msg.exchangeId(), null, null, null, null).onAffinityChangeMessage(evt.eventNode(), msg);
        } else if (customMsg instanceof DynamicCacheChangeFailureMessage) {
            DynamicCacheChangeFailureMessage msg = (DynamicCacheChangeFailureMessage) customMsg;
            if (msg.exchangeId().topologyVersion().topologyVersion() >= affinityTopologyVersion(cctx.discovery().localJoinEvent()).topologyVersion())
                exchangeFuture(msg.exchangeId(), null, null, null, null).onDynamicCacheChangeFail(evt.eventNode(), msg);
        } else if (customMsg instanceof SnapshotDiscoveryMessage && ((SnapshotDiscoveryMessage) customMsg).needExchange()) {
            exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
            exchFut = exchangeFuture(exchId, evt, null, null, null);
        } else if (customMsg instanceof WalStateAbstractMessage && ((WalStateAbstractMessage) customMsg).needExchange()) {
            exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
            exchFut = exchangeFuture(exchId, evt, null, null, null);
        } else {
            // Process event as custom discovery task if needed.
            CachePartitionExchangeWorkerTask task = cctx.cache().exchangeTaskForCustomDiscoveryMessage(customMsg);
            if (task != null)
                exchWorker.addCustomTask(task);
        }
    }
    if (exchId != null) {
        if (log.isDebugEnabled())
            log.debug("Discovery event (will start exchange): " + exchId);
        // Event callback - without this callback future will never complete.
        exchFut.onEvent(exchId, evt, cache);
        Span span = cctx.kernalContext().tracing().create(EXCHANGE_FUTURE, evt.span());
        if (exchId != null) {
            GridDhtPartitionExchangeId exchIdf = exchId;
            span.addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> evt.eventNode().id().toString());
            span.addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> evt.eventNode().consistentId().toString());
            span.addTag(SpanTags.tag(SpanTags.EVENT, SpanTags.TYPE), () -> String.valueOf(evt.type()));
            span.addTag(SpanTags.tag(SpanTags.EXCHANGE, SpanTags.ID), () -> String.valueOf(exchIdf.toString()));
            span.addTag(SpanTags.tag(SpanTags.INITIAL, SpanTags.TOPOLOGY_VERSION, SpanTags.MAJOR), () -> String.valueOf(exchIdf.topologyVersion().topologyVersion()));
            span.addTag(SpanTags.tag(SpanTags.INITIAL, SpanTags.TOPOLOGY_VERSION, SpanTags.MINOR), () -> String.valueOf(exchIdf.topologyVersion().minorTopologyVersion()));
        }
        span.addTag(SpanTags.NODE_ID, () -> cctx.localNodeId().toString());
        span.addLog(() -> "Created");
        exchFut.span(span);
        // Start exchange process.
        addFuture(exchFut);
    } else {
        if (log.isDebugEnabled())
            log.debug("Do not start exchange for discovery event: " + evt);
    }
    notifyNodeFail(evt);
    // Notify indexing engine about node leave so that we can re-map coordinator accordingly.
    if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
        SecurityContext secCtx = remoteSecurityContext(cctx.kernalContext());
        exchWorker.addCustomTask(new SchemaNodeLeaveExchangeWorkerTask(secCtx, evt.eventNode()));
        exchWorker.addCustomTask(new WalStateNodeLeaveExchangeTask(secCtx, evt.eventNode()));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Span(org.apache.ignite.internal.processors.tracing.Span) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) SecurityUtils.remoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.remoteSecurityContext) SecurityUtils.withRemoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.withRemoteSecurityContext) OperationSecurityContext(org.apache.ignite.internal.processors.security.OperationSecurityContext) SchemaNodeLeaveExchangeWorkerTask(org.apache.ignite.internal.processors.query.schema.SchemaNodeLeaveExchangeWorkerTask)

Example 3 with DiscoveryDataClusterState

use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState 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 4 with DiscoveryDataClusterState

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

the class SnapshotRestoreProcess method prepare.

/**
 * @param req Request to prepare cache group restore from the snapshot.
 * @return Result future.
 */
private IgniteInternalFuture<SnapshotRestoreOperationResponse> prepare(SnapshotOperationRequest req) {
    if (ctx.clientNode())
        return new GridFinishedFuture<>();
    try {
        DiscoveryDataClusterState state = ctx.state().clusterState();
        IgniteSnapshotManager snpMgr = ctx.cache().context().snapshotMgr();
        if (state.state() != ClusterState.ACTIVE || state.transition())
            throw new IgniteCheckedException(OP_REJECT_MSG + "The cluster should be active.");
        if (snpMgr.isSnapshotCreating())
            throw new IgniteCheckedException(OP_REJECT_MSG + "A cluster snapshot operation is in progress.");
        if (ctx.encryption().isMasterKeyChangeInProgress()) {
            return new GridFinishedFuture<>(new IgniteCheckedException(OP_REJECT_MSG + "Master key changing " + "process is not finished yet."));
        }
        if (ctx.encryption().reencryptionInProgress()) {
            return new GridFinishedFuture<>(new IgniteCheckedException(OP_REJECT_MSG + "Caches re-encryption " + "process is not finished yet."));
        }
        for (UUID nodeId : req.nodes()) {
            ClusterNode node = ctx.discovery().node(nodeId);
            if (node == null || !CU.baselineNode(node, state) || !ctx.discovery().alive(node)) {
                throw new IgniteCheckedException(OP_REJECT_MSG + "Required node has left the cluster [nodeId-" + nodeId + ']');
            }
        }
        if (log.isInfoEnabled()) {
            log.info("Starting local snapshot prepare restore operation" + " [reqId=" + req.requestId() + ", snapshot=" + req.snapshotName() + ", caches=" + req.groups() + ']');
        }
        List<SnapshotMetadata> locMetas = snpMgr.readSnapshotMetadatas(req.snapshotName());
        SnapshotRestoreContext opCtx0 = prepareContext(req, locMetas);
        synchronized (this) {
            lastOpCtx = opCtx = opCtx0;
            ClusterSnapshotFuture fut0 = fut;
            if (fut0 != null)
                opCtx0.errHnd.accept(fut0.interruptEx);
        }
        // Ensure that shared cache groups has no conflicts.
        for (StoredCacheData cfg : opCtx0.cfgs.values()) {
            ensureCacheAbsent(cfg.config().getName());
            if (!F.isEmpty(cfg.config().getGroupName()))
                ensureCacheAbsent(cfg.config().getGroupName());
        }
        if (ctx.isStopping())
            throw new NodeStoppingException("The node is stopping: " + ctx.localNodeId());
        return new GridFinishedFuture<>(new SnapshotRestoreOperationResponse(opCtx0.cfgs.values(), locMetas));
    } catch (IgniteIllegalStateException | IgniteCheckedException | RejectedExecutionException e) {
        log.error("Unable to restore cache group(s) from the snapshot " + "[reqId=" + req.requestId() + ", snapshot=" + req.snapshotName() + ']', e);
        return new GridFinishedFuture<>(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID) ClusterSnapshotFuture(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.ClusterSnapshotFuture)

Example 5 with DiscoveryDataClusterState

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

the class IgniteKernal method nodeInBaseline.

/**
 * @return {@code True} if current node is in the baseline. {@code False} otherwise.
 */
boolean nodeInBaseline() {
    ctx.gateway().readLockAnyway();
    try {
        if (ctx.gateway().getState() != STARTED)
            return false;
        ClusterNode locNode = localNode();
        if (locNode.isClient() || locNode.isDaemon())
            return false;
        DiscoveryDataClusterState clusterState = ctx.state().clusterState();
        return clusterState.hasBaselineTopology() && CU.baselineNode(locNode, clusterState);
    } finally {
        ctx.gateway().readUnlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState)

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