Search in sources :

Example 11 with DiscoveryDataClusterState

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

the class GridDhtPartitionsExchangeFuture method onClusterStateChangeRequest.

/**
 * @param crd Coordinator flag.
 * @return Exchange type.
 */
private ExchangeType onClusterStateChangeRequest(boolean crd) {
    assert exchActions != null && !exchActions.empty() : this;
    StateChangeRequest req = exchActions.stateChangeRequest();
    assert req != null : exchActions;
    GridKernalContext kctx = cctx.kernalContext();
    DiscoveryDataClusterState state = kctx.state().clusterState();
    if (state.transitionError() != null)
        exchangeLocE = state.transitionError();
    if (req.activeChanged()) {
        if (req.state().active()) {
            if (log.isInfoEnabled()) {
                log.info("Start activation process [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]. New state: " + req.state());
            }
            try {
                cctx.exchange().exchangerBlockingSectionBegin();
                try {
                    cctx.activate();
                } finally {
                    cctx.exchange().exchangerBlockingSectionEnd();
                }
                assert registerCachesFuture == null : "No caches registration should be scheduled before new caches have started.";
                cctx.exchange().exchangerBlockingSectionBegin();
                try {
                    registerCachesFuture = cctx.affinity().onCacheChangeRequest(this, crd, exchActions);
                    if (!kctx.clientNode())
                        cctx.cache().shutdownNotFinishedRecoveryCaches();
                } finally {
                    cctx.exchange().exchangerBlockingSectionEnd();
                }
                if (log.isInfoEnabled()) {
                    log.info("Successfully activated caches [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + ", newState=" + req.state() + "]");
                }
            } catch (Exception e) {
                U.error(log, "Failed to activate node components [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + ", newState=" + req.state() + "]", e);
                exchangeLocE = e;
                if (crd) {
                    cctx.exchange().exchangerBlockingSectionBegin();
                    try {
                        synchronized (mux) {
                            exchangeGlobalExceptions.put(cctx.localNodeId(), e);
                        }
                    } finally {
                        cctx.exchange().exchangerBlockingSectionEnd();
                    }
                }
            }
        } else {
            if (log.isInfoEnabled()) {
                log.info("Start deactivation process [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]");
            }
            cctx.exchange().exchangerBlockingSectionBegin();
            try {
                kctx.dataStructures().onDeActivate(kctx);
                assert registerCachesFuture == null : "No caches registration should be scheduled before new caches have started.";
                registerCachesFuture = cctx.affinity().onCacheChangeRequest(this, crd, exchActions);
                kctx.encryption().onDeActivate(kctx);
                ((IgniteChangeGlobalStateSupport) kctx.distributedMetastorage()).onDeActivate(kctx);
                if (log.isInfoEnabled()) {
                    log.info("Successfully deactivated data structures, services and caches [" + "nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]");
                }
            } catch (Exception e) {
                U.error(log, "Failed to deactivate node components [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]", e);
                exchangeLocE = e;
            } finally {
                cctx.exchange().exchangerBlockingSectionEnd();
            }
        }
    } else if (req.state().active()) {
        cctx.exchange().exchangerBlockingSectionBegin();
        // TODO: BLT changes on inactive cluster can't be handled easily because persistent storage hasn't been initialized yet.
        try {
            if (!forceAffReassignment) {
                // possible only if cluster contains nodes without forceAffReassignment mode
                assert firstEventCache().minimumNodeVersion().compareToIgnoreTimestamp(FORCE_AFF_REASSIGNMENT_SINCE) < 0 : firstEventCache().minimumNodeVersion();
                cctx.affinity().onBaselineTopologyChanged(this, crd);
            }
            if (CU.isPersistenceEnabled(kctx.config()) && !kctx.clientNode())
                kctx.state().onBaselineTopologyChanged(req.baselineTopology(), req.prevBaselineTopologyHistoryItem());
        } catch (Exception e) {
            U.error(log, "Failed to change baseline topology [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]", e);
            exchangeLocE = e;
        } finally {
            cctx.exchange().exchangerBlockingSectionEnd();
        }
    }
    return kctx.clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL;
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) IgniteChangeGlobalStateSupport(org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 12 with DiscoveryDataClusterState

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

the class IgniteServiceProcessor method processServicesChangeRequest.

/**
 * @param snd Sender.
 * @param msg Message.
 */
private void processServicesChangeRequest(ClusterNode snd, ServiceChangeBatchRequest msg) {
    DiscoveryDataClusterState state = ctx.state().clusterState();
    if (!state.active() || state.transition()) {
        for (ServiceChangeAbstractRequest req : msg.requests()) {
            GridFutureAdapter<?> fut = null;
            if (req instanceof ServiceDeploymentRequest)
                fut = depFuts.remove(req.serviceId());
            else if (req instanceof ServiceUndeploymentRequest)
                fut = undepFuts.remove(req.serviceId());
            if (fut != null) {
                fut.onDone(new IgniteCheckedException("Operation has been canceled, cluster state " + "change is in progress."));
            }
        }
        return;
    }
    Map<IgniteUuid, ServiceInfo> toDeploy = new HashMap<>();
    Map<IgniteUuid, ServiceInfo> toUndeploy = new HashMap<>();
    for (ServiceChangeAbstractRequest req : msg.requests()) {
        IgniteUuid reqSrvcId = req.serviceId();
        ServiceInfo oldDesc = registeredServices.get(reqSrvcId);
        if (req instanceof ServiceDeploymentRequest) {
            Exception err = null;
            if (oldDesc != null) {
                // In case of a collision of IgniteUuid.randomUuid() (almost impossible case)
                err = new IgniteCheckedException("Failed to deploy service. Service with generated id already" + "exists : [" + "srvcId" + reqSrvcId + ", srvcTop=" + oldDesc.topologySnapshot() + ']');
            } else {
                ServiceConfiguration cfg = ((ServiceDeploymentRequest) req).configuration();
                if (ctx.security().enabled())
                    err = checkPermissions(((ServiceDeploymentRequest) req).configuration().getName(), SERVICE_DEPLOY);
                if (err == null) {
                    oldDesc = lookupInRegisteredServices(cfg.getName());
                    if (oldDesc == null) {
                        if (cfg.getCacheName() != null && ctx.cache().cacheDescriptor(cfg.getCacheName()) == null) {
                            err = new IgniteCheckedException("Failed to deploy service, " + "affinity cache is not found, cfg=" + cfg);
                        } else {
                            ServiceInfo desc = new ServiceInfo(snd.id(), reqSrvcId, cfg);
                            registerService(desc);
                            toDeploy.put(reqSrvcId, desc);
                        }
                    } else {
                        if (!oldDesc.configuration().equalsIgnoreNodeFilter(cfg)) {
                            err = new IgniteCheckedException("Failed to deploy service " + "(service already exists with different configuration) : " + "[deployed=" + oldDesc.configuration() + ", new=" + cfg + ']');
                        } else {
                            GridServiceDeploymentFuture<IgniteUuid> fut = depFuts.remove(reqSrvcId);
                            if (fut != null) {
                                fut.onDone();
                                if (log.isDebugEnabled()) {
                                    log.debug("Service sent to deploy is already deployed : " + "[srvcId=" + oldDesc.serviceId() + ", cfg=" + oldDesc.configuration());
                                }
                            }
                        }
                    }
                }
            }
            if (err != null) {
                completeInitiatingFuture(true, reqSrvcId, err);
                U.warn(log, err.getMessage(), err);
            }
        } else if (req instanceof ServiceUndeploymentRequest) {
            ServiceInfo rmv = registeredServices.remove(reqSrvcId);
            assert oldDesc == rmv : "Concurrent map modification.";
            toUndeploy.put(reqSrvcId, rmv);
        }
    }
    if (!toDeploy.isEmpty() || !toUndeploy.isEmpty()) {
        ServiceDeploymentActions depActions = new ServiceDeploymentActions();
        if (!toDeploy.isEmpty())
            depActions.servicesToDeploy(toDeploy);
        if (!toUndeploy.isEmpty())
            depActions.servicesToUndeploy(toUndeploy);
        msg.servicesDeploymentActions(depActions);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) SecurityException(org.apache.ignite.plugin.security.SecurityException) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

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