Search in sources :

Example 1 with DynamicCacheChangeRequest

use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest in project ignite by apache.

the class GridClusterStateProcessor method changeGlobalState.

/**
     *
     */
public IgniteInternalFuture<?> changeGlobalState(final boolean activate) {
    if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
        throw new IgniteException("Cannot " + prettyStr(activate) + " cluster, because cache locked on transaction.");
    if ((globalState == ACTIVE && activate) || (this.globalState == INACTIVE && !activate))
        return new GridFinishedFuture<>();
    final UUID requestId = UUID.randomUUID();
    final GridChangeGlobalStateFuture cgsFut = new GridChangeGlobalStateFuture(requestId, activate, ctx);
    if (!cgsLocFut.compareAndSet(null, cgsFut)) {
        GridChangeGlobalStateFuture locF = cgsLocFut.get();
        if (locF.activate == activate)
            return locF;
        else
            return new GridFinishedFuture<>(new IgniteException("fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate)));
    }
    try {
        if (ctx.clientNode()) {
            AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
            IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute().withAsync();
            if (log.isInfoEnabled())
                log.info("Send " + prettyStr(activate) + " request from client node [id=" + ctx.localNodeId() + " topVer=" + topVer + " ]");
            comp.run(new ClientChangeGlobalStateComputeRequest(activate));
            comp.future().listen(new CI1<IgniteFuture>() {

                @Override
                public void apply(IgniteFuture fut) {
                    try {
                        fut.get();
                        cgsFut.onDone();
                    } catch (Exception e) {
                        cgsFut.onDone(e);
                    }
                }
            });
        } else {
            List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
            DynamicCacheChangeRequest changeGlobalStateReq = new DynamicCacheChangeRequest(requestId, activate ? ACTIVE : INACTIVE, ctx.localNodeId());
            reqs.add(changeGlobalStateReq);
            reqs.addAll(activate ? cacheProc.startAllCachesRequests() : cacheProc.stopAllCachesRequests());
            ChangeGlobalStateMessage changeGlobalStateMsg = new ChangeGlobalStateMessage(requestId, ctx.localNodeId(), activate, new DynamicCacheChangeBatch(reqs));
            try {
                ctx.discovery().sendCustomEvent(changeGlobalStateMsg);
                if (ctx.isStopping())
                    cgsFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(activate) + " request, " + "node is stopping."));
            } catch (IgniteCheckedException e) {
                log.error("Fail create or send change global state request." + cgsFut, e);
                cgsFut.onDone(e);
            }
        }
    } catch (IgniteCheckedException e) {
        log.error("Fail create or send change global state request." + cgsFut, e);
        cgsFut.onDone(e);
    }
    return cgsFut;
}
Also used : DynamicCacheChangeRequest(org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 2 with DynamicCacheChangeRequest

use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest in project ignite by apache.

the class GridClusterStateProcessor method onActivate.

/**
     *
     */
private Exception onActivate(ChangeGlobalStateContext cgsCtx) {
    final boolean client = ctx.clientNode();
    if (log.isInfoEnabled())
        log.info("Start activation process [nodeId=" + this.ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]");
    Collection<CacheConfiguration> cfgs = new ArrayList<>();
    for (DynamicCacheChangeRequest req : cgsCtx.batch.requests()) {
        if (req.startCacheConfiguration() != null)
            cfgs.add(req.startCacheConfiguration());
    }
    try {
        if (!client) {
            sharedCtx.database().lock();
            IgnitePageStoreManager pageStore = sharedCtx.pageStore();
            if (pageStore != null)
                pageStore.onActivate(ctx);
            if (sharedCtx.wal() != null)
                sharedCtx.wal().onActivate(ctx);
            sharedCtx.database().initDataBase();
            for (CacheConfiguration cfg : cfgs) {
                if (CU.isSystemCache(cfg.getName()))
                    if (pageStore != null)
                        pageStore.initializeForCache(cfg);
            }
            for (CacheConfiguration cfg : cfgs) {
                if (!CU.isSystemCache(cfg.getName()))
                    if (pageStore != null)
                        pageStore.initializeForCache(cfg);
            }
            sharedCtx.database().onActivate(ctx);
        }
        if (log.isInfoEnabled())
            log.info("Success activate wal, dataBase, pageStore [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]");
        return null;
    } catch (Exception e) {
        log.error("Fail activate wal, dataBase, pageStore [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]", e);
        if (!ctx.clientNode())
            sharedCtx.database().unLock();
        return e;
    }
}
Also used : DynamicCacheChangeRequest(org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 3 with DynamicCacheChangeRequest

use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest in project ignite by apache.

the class IgniteServiceProcessor method processDynamicCacheChangeRequest.

/**
 * @param msg Message.
 */
private void processDynamicCacheChangeRequest(DynamicCacheChangeBatch msg) {
    Map<IgniteUuid, ServiceInfo> toUndeploy = new HashMap<>();
    for (DynamicCacheChangeRequest chReq : msg.requests()) {
        if (chReq.stop()) {
            registeredServices.entrySet().removeIf(e -> {
                ServiceInfo desc = e.getValue();
                if (Objects.equals(desc.cacheName(), chReq.cacheName())) {
                    toUndeploy.put(desc.serviceId(), desc);
                    return true;
                }
                return false;
            });
        }
    }
    if (!toUndeploy.isEmpty()) {
        ServiceDeploymentActions depActions = new ServiceDeploymentActions();
        depActions.servicesToUndeploy(toUndeploy);
        msg.servicesDeploymentActions(depActions);
    }
}
Also used : DynamicCacheChangeRequest(org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Aggregations

DynamicCacheChangeRequest (org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest)3 ArrayList (java.util.ArrayList)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IgniteCompute (org.apache.ignite.IgniteCompute)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgnitePageStoreManager (org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 ChangeGlobalStateMessage (org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage)1 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)1 IgniteFuture (org.apache.ignite.lang.IgniteFuture)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1