Search in sources :

Example 11 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridClusterStateProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    super.start(activeOnStart);
    globalState = activeOnStart ? ACTIVE : INACTIVE;
    cacheProc = ctx.cache();
    sharedCtx = cacheProc.context();
    sharedCtx.io().addHandler(0, GridChangeGlobalStateMessageResponse.class, new CI2<UUID, GridChangeGlobalStateMessageResponse>() {

        @Override
        public void apply(UUID nodeId, GridChangeGlobalStateMessageResponse msg) {
            processChangeGlobalStateResponse(nodeId, msg);
        }
    });
    ctx.discovery().setCustomEventListener(ChangeGlobalStateMessage.class, new CustomEventListener<ChangeGlobalStateMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, ChangeGlobalStateMessage msg) {
            assert topVer != null;
            assert snd != null;
            assert msg != null;
            boolean activate = msg.activate();
            ChangeGlobalStateContext actx = lastCgsCtx;
            if (actx != null && globalState == TRANSITION) {
                GridChangeGlobalStateFuture f = cgsLocFut.get();
                if (log.isDebugEnabled())
                    log.debug("Concurrent " + prettyStr(activate) + " [id=" + ctx.localNodeId() + " topVer=" + topVer + " actx=" + actx + ", msg=" + msg + "]");
                if (f != null && f.requestId.equals(msg.requestId()))
                    f.onDone(new IgniteCheckedException("Concurrent change state, now in progress=" + (activate) + ", initiatingNodeId=" + actx.initiatingNodeId + ", you try=" + (prettyStr(activate)) + ", locNodeId=" + ctx.localNodeId()));
                msg.concurrentChangeState();
            } else {
                if (log.isInfoEnabled())
                    log.info("Create " + prettyStr(activate) + " context [id=" + ctx.localNodeId() + " topVer=" + topVer + ", reqId=" + msg.requestId() + ", initiatingNodeId=" + msg.initiatorNodeId() + "]");
                lastCgsCtx = new ChangeGlobalStateContext(msg.requestId(), msg.initiatorNodeId(), msg.getDynamicCacheChangeBatch(), msg.activate());
                globalState = TRANSITION;
            }
        }
    });
    ctx.event().addLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage) UUID(java.util.UUID) GridChangeGlobalStateMessageResponse(org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse)

Example 12 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class DataStructuresProcessor method getAtomic.

/**
     * @param c Closure creating data structure instance.
     * @param dsInfo Data structure info.
     * @param create Create flag.
     * @param cls Expected data structure class.
     * @return Data structure instance.
     * @throws IgniteCheckedException If failed.
     */
@Nullable
private <T> T getAtomic(final IgniteOutClosureX<T> c, final DataStructureInfo dsInfo, final boolean create, Class<? extends T> cls) throws IgniteCheckedException {
    Map<String, DataStructureInfo> dsMap = utilityCache.get(DATA_STRUCTURES_KEY);
    if (!create && (dsMap == null || !dsMap.containsKey(dsInfo.name)))
        return null;
    IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, create);
    if (err != null)
        throw err;
    final GridCacheInternalKey key = new GridCacheInternalKeyImpl(dsInfo.name);
    // Check type of structure received by key from local cache.
    T dataStructure = cast(this.dsMap.get(key), cls);
    if (dataStructure != null)
        return dataStructure;
    return retryTopologySafe(new IgniteOutClosureX<T>() {

        @Override
        public T applyx() throws IgniteCheckedException {
            if (!create)
                return c.applyx();
            try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
                IgniteCheckedException err = utilityCache.invoke(DATA_STRUCTURES_KEY, new AddAtomicProcessor(dsInfo)).get();
                if (err != null)
                    throw err;
                T dataStructure = c.applyx();
                tx.commit();
                return dataStructure;
            }
        }
    });
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) SET(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SET) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class DataStructuresProcessor method removeDataStructure.

/**
     * @param c Closure.
     * @param name Data structure name.
     * @param type Data structure type.
     * @param afterRmv Optional closure to run after data structure removed.
     * @throws IgniteCheckedException If failed.
     */
private <T> void removeDataStructure(final IgniteOutClosureX<T> c, String name, DataStructureType type, @Nullable final IgniteInClosureX<T> afterRmv) throws IgniteCheckedException {
    Map<String, DataStructureInfo> dsMap = utilityCache.get(DATA_STRUCTURES_KEY);
    if (dsMap == null || !dsMap.containsKey(name))
        return;
    final DataStructureInfo dsInfo = new DataStructureInfo(name, type, null);
    IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, false);
    if (err != null)
        throw err;
    retryTopologySafe(new IgniteOutClosureX<Void>() {

        @Override
        public Void applyx() throws IgniteCheckedException {
            try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
                T2<Boolean, IgniteCheckedException> res = utilityCache.invoke(DATA_STRUCTURES_KEY, new RemoveDataStructureProcessor(dsInfo)).get();
                IgniteCheckedException err = res.get2();
                if (err != null)
                    throw err;
                assert res.get1() != null;
                boolean exists = res.get1();
                if (!exists)
                    return null;
                T rmvInfo = c.applyx();
                tx.commit();
                if (afterRmv != null && rmvInfo != null)
                    afterRmv.applyx(rmvInfo);
                return null;
            }
        }
    });
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) SET(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SET) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) T2(org.apache.ignite.internal.util.typedef.T2)

Example 14 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class DataStructuresProcessor method removeCountDownLatch.

/**
     * Removes count down latch from cache.
     *
     * @param name Name of the latch.
     * @throws IgniteCheckedException If operation failed.
     */
public void removeCountDownLatch(final String name) throws IgniteCheckedException {
    assert name != null;
    assert dsCacheCtx != null;
    awaitInitialization();
    removeDataStructure(new IgniteOutClosureX<Void>() {

        @Override
        public Void applyx() throws IgniteCheckedException {
            GridCacheInternal key = new GridCacheInternalKeyImpl(name);
            dsCacheCtx.gate().enter();
            try (GridNearTxLocal tx = CU.txStartInternal(dsCacheCtx, dsView, PESSIMISTIC, REPEATABLE_READ)) {
                // Check correctness type of removable object.
                GridCacheCountDownLatchValue val = cast(dsView.get(key), GridCacheCountDownLatchValue.class);
                if (val != null) {
                    if (val.get() > 0) {
                        throw new IgniteCheckedException("Failed to remove count down latch " + "with non-zero count: " + val.get());
                    }
                    dsView.remove(key);
                    tx.commit();
                } else
                    tx.setRollbackOnly();
                return null;
            } finally {
                dsCacheCtx.gate().leave();
            }
        }
    }, name, COUNT_DOWN_LATCH, null);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)

Example 15 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridJobProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    if (metricsUpdateFreq < -1)
        throw new IgniteCheckedException("Invalid value for 'metricsUpdateFrequency' configuration property " + "(should be greater than or equals to -1): " + metricsUpdateFreq);
    if (metricsUpdateFreq == -1)
        U.warn(log, "Job metrics are disabled (use with caution).");
    if (!jobAlwaysActivate)
        ctx.collision().setCollisionExternalListener(new CollisionExternalListener());
    GridIoManager ioMgr = ctx.io();
    ioMgr.addMessageListener(TOPIC_JOB_CANCEL, cancelLsnr);
    ioMgr.addMessageListener(TOPIC_JOB, jobExecLsnr);
    ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_NODE_METRICS_UPDATED);
    if (log.isDebugEnabled())
        log.debug("Job processor started.");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96