Search in sources :

Example 31 with IgniteCheckedException

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

the class CacheAffinitySharedManager method initCoordinatorCaches.

/**
     * @param fut Exchange future.
     * @throws IgniteCheckedException If failed.
     * @return Future completed when caches initialization is done.
     */
private IgniteInternalFuture<?> initCoordinatorCaches(final GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException {
    final List<IgniteInternalFuture<AffinityTopologyVersion>> futs = new ArrayList<>();
    forAllRegisteredCaches(new IgniteInClosureX<DynamicCacheDescriptor>() {

        @Override
        public void applyx(DynamicCacheDescriptor desc) throws IgniteCheckedException {
            CacheHolder cache = caches.get(desc.cacheId());
            if (cache != null) {
                if (cache.client())
                    cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache());
                return;
            }
            final Integer cacheId = desc.cacheId();
            GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
            if (cacheCtx == null) {
                cctx.io().addHandler(desc.cacheId(), GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure<UUID, GridDhtAffinityAssignmentResponse>() {

                    @Override
                    public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) {
                        processAffinityAssignmentResponse(nodeId, res);
                    }
                });
                cache = CacheHolder2.create(cctx, desc, fut, null);
                final GridAffinityAssignmentCache aff = cache.affinity();
                List<GridDhtPartitionsExchangeFuture> exchFuts = cctx.exchange().exchangeFutures();
                int idx = exchFuts.indexOf(fut);
                assert idx >= 0 && idx < exchFuts.size() - 1 : "Invalid exchange futures state [cur=" + idx + ", total=" + exchFuts.size() + ']';
                final GridDhtPartitionsExchangeFuture prev = exchFuts.get(idx + 1);
                if (log.isDebugEnabled()) {
                    log.debug("Need initialize affinity on coordinator [" + "cache=" + desc.cacheConfiguration().getName() + "prevAff=" + prev.topologyVersion() + ']');
                }
                assert prev.topologyVersion().compareTo(fut.topologyVersion()) < 0 : prev;
                GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, desc, prev.topologyVersion(), prev.discoCache());
                fetchFut.init();
                final GridFutureAdapter<AffinityTopologyVersion> affFut = new GridFutureAdapter<>();
                fetchFut.listen(new IgniteInClosureX<IgniteInternalFuture<GridDhtAffinityAssignmentResponse>>() {

                    @Override
                    public void applyx(IgniteInternalFuture<GridDhtAffinityAssignmentResponse> fetchFut) throws IgniteCheckedException {
                        fetchAffinity(prev, aff, (GridDhtAssignmentFetchFuture) fetchFut);
                        aff.calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache());
                        affFut.onDone(fut.topologyVersion());
                    }
                });
                futs.add(affFut);
            } else
                cache = new CacheHolder1(cacheCtx, null);
            CacheHolder old = caches.put(cache.cacheId(), cache);
            assert old == null : old;
        }
    });
    if (!futs.isEmpty()) {
        GridCompoundFuture<AffinityTopologyVersion, ?> affFut = new GridCompoundFuture<>();
        for (IgniteInternalFuture<AffinityTopologyVersion> f : futs) affFut.add(f);
        affFut.markInitialized();
        return affFut;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInClosureX(org.apache.ignite.internal.util.lang.IgniteInClosureX) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridDhtAssignmentFetchFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAssignmentFetchFuture) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtAffinityAssignmentResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse)

Example 32 with IgniteCheckedException

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

the class GridCacheProcessor method prepareCacheChangeRequest.

/**
     * Prepares DynamicCacheChangeRequest for cache creation.
     *
     * @param ccfg Cache configuration
     * @param cacheName Cache name
     * @param nearCfg Near cache configuration
     * @param cacheType Cache type
     * @param sql Whether the cache needs to be created as the result of SQL {@code CREATE TABLE} command.
     * @param failIfExists Fail if exists flag.
     * @param failIfNotStarted If {@code true} fails if cache is not started.
     * @return Request or {@code null} if cache already exists.
     * @throws IgniteCheckedException if some of pre-checks failed
     * @throws CacheExistsException if cache exists and failIfExists flag is {@code true}
     */
private DynamicCacheChangeRequest prepareCacheChangeRequest(@Nullable CacheConfiguration ccfg, String cacheName, @Nullable NearCacheConfiguration nearCfg, CacheType cacheType, boolean sql, boolean failIfExists, boolean failIfNotStarted) throws IgniteCheckedException {
    DynamicCacheDescriptor desc = cacheDescriptor(cacheName);
    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
    req.sql(sql);
    req.failIfExists(failIfExists);
    if (ccfg != null) {
        cloneCheckSerializable(ccfg);
        if (desc != null) {
            if (failIfExists) {
                throw new CacheExistsException("Failed to start cache " + "(a cache with the same name is already started): " + cacheName);
            } else {
                CacheConfiguration descCfg = desc.cacheConfiguration();
                // Check if we were asked to start a near cache.
                if (nearCfg != null) {
                    if (CU.affinityNode(ctx.discovery().localNode(), descCfg.getNodeFilter())) {
                        // If we are on a data node and near cache was enabled, return success, else - fail.
                        if (descCfg.getNearConfiguration() != null)
                            return null;
                        else
                            throw new IgniteCheckedException("Failed to start near " + "cache (local node is an affinity node for cache): " + cacheName);
                    } else
                        // If local node has near cache, return success.
                        req.clientStartOnly(true);
                } else
                    req.clientStartOnly(true);
                req.deploymentId(desc.deploymentId());
                req.startCacheConfiguration(descCfg);
                req.schema(desc.schema());
            }
        } else {
            req.deploymentId(IgniteUuid.randomUuid());
            CacheConfiguration cfg = new CacheConfiguration(ccfg);
            CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
            initialize(cfg, cacheObjCtx);
            req.startCacheConfiguration(cfg);
            req.schema(new QuerySchema(cfg.getQueryEntities()));
        }
    } else {
        req.clientStartOnly(true);
        if (desc != null)
            ccfg = desc.cacheConfiguration();
        if (ccfg == null) {
            if (failIfNotStarted) {
                throw new CacheExistsException("Failed to start client cache " + "(a cache with the given name is not started): " + cacheName);
            } else
                return null;
        }
        req.deploymentId(desc.deploymentId());
        req.startCacheConfiguration(ccfg);
        req.schema(desc.schema());
    }
    if (nearCfg != null)
        req.nearCacheConfiguration(nearCfg);
    req.cacheType(cacheType);
    return req;
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheExistsException(org.apache.ignite.cache.CacheExistsException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 33 with IgniteCheckedException

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

the class GridCacheProcessor method initiateCacheChanges.

/**
     * @param reqs Requests.
     * @param failIfExists Fail if exists flag.
     * @return Collection of futures.
     */
@SuppressWarnings("TypeMayBeWeakened")
private Collection<DynamicCacheStartFuture> initiateCacheChanges(Collection<DynamicCacheChangeRequest> reqs, boolean failIfExists) {
    Collection<DynamicCacheStartFuture> res = new ArrayList<>(reqs.size());
    Collection<DynamicCacheChangeRequest> sndReqs = new ArrayList<>(reqs.size());
    for (DynamicCacheChangeRequest req : reqs) {
        DynamicCacheStartFuture fut = new DynamicCacheStartFuture(req.cacheName(), req);
        try {
            if (req.stop() || req.close()) {
                DynamicCacheDescriptor desc = cacheDescriptor(req.cacheName());
                if (desc == null)
                    // No-op.
                    fut.onDone(false);
                else {
                    assert desc.cacheConfiguration() != null : desc;
                    if (req.close() && desc.cacheConfiguration().getCacheMode() == LOCAL) {
                        req.close(false);
                        req.stop(true);
                    }
                }
            }
            if (fut.isDone())
                continue;
            DynamicCacheStartFuture old = (DynamicCacheStartFuture) pendingFuts.putIfAbsent(req.requestId(), fut);
            assert old == null;
            if (fut.isDone())
                continue;
            sndReqs.add(req);
        } catch (Exception e) {
            fut.onDone(e);
        } finally {
            res.add(fut);
        }
    }
    Exception err = null;
    if (!sndReqs.isEmpty()) {
        try {
            ctx.discovery().sendCustomEvent(new DynamicCacheChangeBatch(sndReqs));
            if (ctx.isStopping()) {
                err = new IgniteCheckedException("Failed to execute dynamic cache change request, " + "node is stopping.");
            } else if (ctx.clientDisconnected()) {
                err = new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to execute dynamic cache change request, client node disconnected.");
            }
        } catch (IgniteCheckedException e) {
            err = e;
        }
    }
    if (err != null) {
        for (DynamicCacheStartFuture fut : res) fut.onDone(err);
    }
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JMException(javax.management.JMException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheExistsException(org.apache.ignite.cache.CacheExistsException)

Example 34 with IgniteCheckedException

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

the class IgniteCacheDatabaseSharedManager method checkPolicySize.

/**
     * @param plcCfg MemoryPolicyConfiguration to validate.
     * @throws IgniteCheckedException If config is invalid.
     */
private void checkPolicySize(MemoryPolicyConfiguration plcCfg) throws IgniteCheckedException {
    if (plcCfg.getInitialSize() < MIN_PAGE_MEMORY_SIZE)
        throw new IgniteCheckedException("MemoryPolicy must have size more than 10MB (use " + "MemoryPolicyConfiguration.initialSize property to set correct size in bytes) " + "[name=" + plcCfg.getName() + ", size=" + U.readableSize(plcCfg.getInitialSize(), true) + "]");
    if (plcCfg.getMaxSize() < plcCfg.getInitialSize()) {
        // We will know for sure if initialSize has been changed if we compare Longs by "==".
        if (plcCfg.getInitialSize() == DFLT_MEMORY_POLICY_INITIAL_SIZE) {
            plcCfg.setInitialSize(plcCfg.getMaxSize());
            LT.warn(log, "MemoryPolicy maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + " is smaller than defaultInitialSize=" + U.readableSize(MemoryConfiguration.DFLT_MEMORY_POLICY_INITIAL_SIZE, true) + ", setting initialSize to " + U.readableSize(plcCfg.getMaxSize(), true));
        } else {
            throw new IgniteCheckedException("MemoryPolicy maxSize must not be smaller than " + "initialSize [name=" + plcCfg.getName() + ", initSize=" + U.readableSize(plcCfg.getInitialSize(), true) + ", maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + ']');
        }
    }
    if (U.jvm32Bit() && plcCfg.getInitialSize() > MAX_PAGE_MEMORY_INIT_SIZE_32_BIT)
        throw new IgniteCheckedException("MemoryPolicy initialSize exceeds 2GB on 32-bit JVM (use " + "MemoryPolicyConfiguration.initialSize property to set correct size in bytes or use 64-bit JVM) " + "[name=" + plcCfg.getName() + ", size=" + U.readableSize(plcCfg.getInitialSize(), true) + "]");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 35 with IgniteCheckedException

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

the class BPlusTree method doPut.

/**
     * @param row New value.
     * @param needOld {@code True} If need return old value.
     * @return Old row.
     * @throws IgniteCheckedException If failed.
     */
private T doPut(T row, boolean needOld) throws IgniteCheckedException {
    checkDestroyed();
    Put p = new Put(row, needOld);
    try {
        for (; ; ) {
            // Go down with retries.
            p.init();
            Result res = putDown(p, p.rootId, 0L, p.rootLvl);
            switch(res) {
                case RETRY:
                case RETRY_ROOT:
                    checkInterrupted();
                    continue;
                case FOUND:
                    // We may need to insert split key into upper level here.
                    if (!p.isFinished()) {
                        // write lock on current root, so it can't concurrently change.
                        assert p.btmLvl <= getRootLevel();
                        checkInterrupted();
                        continue;
                    }
                    return p.oldRow;
                default:
                    throw new IllegalStateException("Result: " + res);
            }
        }
    } catch (IgniteCheckedException e) {
        throw new IgniteCheckedException("Runtime failure on row: " + row, e);
    } catch (RuntimeException e) {
        throw new IgniteException("Runtime failure on row: " + row, e);
    } catch (AssertionError e) {
        throw new AssertionError("Assertion error on row: " + row, e);
    } finally {
        checkDestroyed();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

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