Search in sources :

Example 1 with IgniteClientDisconnectedCheckedException

use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException 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 2 with IgniteClientDisconnectedCheckedException

use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.

the class GridCacheProcessor method addCacheConfiguration.

/**
     * @param cacheCfg Cache configuration template.
     * @throws IgniteCheckedException If failed.
     */
public void addCacheConfiguration(CacheConfiguration cacheCfg) throws IgniteCheckedException {
    assert cacheCfg.getName() != null;
    String name = cacheCfg.getName();
    DynamicCacheDescriptor desc = cachesInfo.registeredTemplates().get(name);
    if (desc != null)
        return;
    DynamicCacheChangeRequest req = DynamicCacheChangeRequest.addTemplateRequest(ctx, cacheCfg);
    TemplateConfigurationFuture fut = new TemplateConfigurationFuture(req.cacheName(), req.deploymentId());
    TemplateConfigurationFuture old = (TemplateConfigurationFuture) pendingTemplateFuts.putIfAbsent(cacheCfg.getName(), fut);
    if (old != null)
        fut = old;
    Exception err = null;
    try {
        ctx.discovery().sendCustomEvent(new DynamicCacheChangeBatch(Collections.singleton(req)));
        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)
        fut.onDone(err);
    fut.get();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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 3 with IgniteClientDisconnectedCheckedException

use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.

the class GridCacheDistributedQueryManager method onDisconnected.

/** {@inheritDoc} */
@Override
public void onDisconnected(IgniteFuture<?> reconnectFut) {
    IgniteClientDisconnectedCheckedException err = new IgniteClientDisconnectedCheckedException(reconnectFut, "Query was cancelled, client node disconnected.");
    for (Map.Entry<Long, GridCacheDistributedQueryFuture<?, ?, ?>> e : futs.entrySet()) {
        GridCacheDistributedQueryFuture<?, ?, ?> fut = e.getValue();
        fut.onPage(null, null, err, true);
        futs.remove(e.getKey(), fut);
    }
}
Also used : IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 4 with IgniteClientDisconnectedCheckedException

use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.

the class GridContinuousProcessor method onDisconnected.

/** {@inheritDoc} */
@Override
public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException {
    cancelFutures(new IgniteClientDisconnectedCheckedException(reconnectFut, "Client node disconnected."));
    if (log.isDebugEnabled()) {
        log.debug("onDisconnected [rmtInfos=" + rmtInfos + ", locInfos=" + locInfos + ", clientInfos=" + clientInfos + ']');
    }
    for (Map.Entry<UUID, RemoteRoutineInfo> e : rmtInfos.entrySet()) {
        RemoteRoutineInfo info = e.getValue();
        if (!ctx.localNodeId().equals(info.nodeId) || info.autoUnsubscribe)
            unregisterRemote(e.getKey());
    }
    for (LocalRoutineInfo routine : locInfos.values()) routine.hnd.onClientDisconnected();
    rmtInfos.clear();
    clientInfos.clear();
    if (log.isDebugEnabled()) {
        log.debug("after onDisconnected [rmtInfos=" + rmtInfos + ", locInfos=" + locInfos + ", clientInfos=" + clientInfos + ']');
    }
}
Also used : IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) UUID(java.util.UUID) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 5 with IgniteClientDisconnectedCheckedException

use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.

the class DataStreamerImpl method load0.

/**
     * @param entries Entries.
     * @param resFut Result future.
     * @param activeKeys Active keys.
     * @param remaps Remaps count.
     */
private void load0(Collection<? extends DataStreamerEntry> entries, final GridFutureAdapter<Object> resFut, @Nullable final Collection<KeyCacheObjectWrapper> activeKeys, final int remaps) {
    try {
        assert entries != null;
        final boolean remap = remaps > 0;
        if (!remap) {
            // Failed data should be processed prior to new data.
            acquireRemapSemaphore();
        }
        if (!isWarningPrinted) {
            synchronized (this) {
                if (!allowOverwrite() && !isWarningPrinted) {
                    U.warn(log, "Data streamer will not overwrite existing cache entries for better performance " + "(to change, set allowOverwrite to true)");
                }
                isWarningPrinted = true;
            }
        }
        Map<ClusterNode, Collection<DataStreamerEntry>> mappings = new HashMap<>();
        boolean initPda = ctx.deploy().enabled() && jobPda == null;
        GridCacheAdapter cache = ctx.cache().internalCache(cacheName);
        if (cache == null)
            throw new IgniteCheckedException("Cache not created or already destroyed.");
        GridCacheContext cctx = cache.context();
        GridCacheGateway gate = null;
        if (!allowOverwrite() && !cctx.isLocal()) {
            // Cases where cctx required.
            gate = cctx.gate();
            gate.enter();
        }
        try {
            AffinityTopologyVersion topVer = allowOverwrite() || cctx.isLocal() ? ctx.cache().context().exchange().readyAffinityVersion() : cctx.topology().topologyVersion();
            for (DataStreamerEntry entry : entries) {
                List<ClusterNode> nodes;
                try {
                    KeyCacheObject key = entry.getKey();
                    assert key != null;
                    if (initPda) {
                        if (cacheObjCtx.addDeploymentInfo())
                            jobPda = new DataStreamerPda(key.value(cacheObjCtx, false), entry.getValue() != null ? entry.getValue().value(cacheObjCtx, false) : null, rcvr);
                        else if (rcvr != null)
                            jobPda = new DataStreamerPda(rcvr);
                        initPda = false;
                    }
                    nodes = nodes(key, topVer, cctx);
                } catch (IgniteCheckedException e) {
                    resFut.onDone(e);
                    return;
                }
                if (F.isEmpty(nodes)) {
                    resFut.onDone(new ClusterTopologyException("Failed to map key to node " + "(no nodes with cache found in topology) [infos=" + entries.size() + ", cacheName=" + cacheName + ']'));
                    return;
                }
                for (ClusterNode node : nodes) {
                    Collection<DataStreamerEntry> col = mappings.get(node);
                    if (col == null)
                        mappings.put(node, col = new ArrayList<>());
                    col.add(entry);
                }
            }
            for (final Map.Entry<ClusterNode, Collection<DataStreamerEntry>> e : mappings.entrySet()) {
                final UUID nodeId = e.getKey().id();
                Buffer buf = bufMappings.get(nodeId);
                if (buf == null) {
                    Buffer old = bufMappings.putIfAbsent(nodeId, buf = new Buffer(e.getKey()));
                    if (old != null)
                        buf = old;
                }
                final Collection<DataStreamerEntry> entriesForNode = e.getValue();
                IgniteInClosure<IgniteInternalFuture<?>> lsnr = new IgniteInClosure<IgniteInternalFuture<?>>() {

                    @Override
                    public void apply(IgniteInternalFuture<?> t) {
                        try {
                            t.get();
                            if (activeKeys != null) {
                                for (DataStreamerEntry e : entriesForNode) activeKeys.remove(new KeyCacheObjectWrapper(e.getKey()));
                                if (activeKeys.isEmpty())
                                    resFut.onDone();
                            } else {
                                assert entriesForNode.size() == 1;
                                // That has been a single key,
                                // so complete result future right away.
                                resFut.onDone();
                            }
                        } catch (IgniteClientDisconnectedCheckedException e1) {
                            if (log.isDebugEnabled())
                                log.debug("Future finished with disconnect error [nodeId=" + nodeId + ", err=" + e1 + ']');
                            resFut.onDone(e1);
                        } catch (IgniteCheckedException e1) {
                            if (log.isDebugEnabled())
                                log.debug("Future finished with error [nodeId=" + nodeId + ", err=" + e1 + ']');
                            if (cancelled) {
                                resFut.onDone(new IgniteCheckedException("Data streamer has been cancelled: " + DataStreamerImpl.this, e1));
                            } else if (remaps + 1 > maxRemapCnt) {
                                resFut.onDone(new IgniteCheckedException("Failed to finish operation (too many remaps): " + remaps, e1));
                            } else {
                                try {
                                    remapSem.acquire();
                                    final Runnable r = new Runnable() {

                                        @Override
                                        public void run() {
                                            try {
                                                if (cancelled)
                                                    throw new IllegalStateException("DataStreamer closed.");
                                                load0(entriesForNode, resFut, activeKeys, remaps + 1);
                                            } catch (Throwable ex) {
                                                resFut.onDone(new IgniteCheckedException("DataStreamer remapping failed. ", ex));
                                            } finally {
                                                remapSem.release();
                                            }
                                        }
                                    };
                                    dataToRemap.add(r);
                                    if (!remapOwning.get() && remapOwning.compareAndSet(false, true)) {
                                        ctx.closure().callLocalSafe(new GPC<Boolean>() {

                                            @Override
                                            public Boolean call() {
                                                boolean locked = true;
                                                while (locked || !dataToRemap.isEmpty()) {
                                                    if (!locked && !remapOwning.compareAndSet(false, true))
                                                        return false;
                                                    try {
                                                        Runnable r = dataToRemap.poll();
                                                        if (r != null)
                                                            r.run();
                                                    } finally {
                                                        if (!dataToRemap.isEmpty())
                                                            locked = true;
                                                        else {
                                                            remapOwning.set(false);
                                                            locked = false;
                                                        }
                                                    }
                                                }
                                                return true;
                                            }
                                        }, true);
                                    }
                                } catch (InterruptedException e2) {
                                    resFut.onDone(e2);
                                }
                            }
                        }
                    }
                };
                final GridFutureAdapter<?> f;
                try {
                    f = buf.update(entriesForNode, topVer, lsnr, remap);
                } catch (IgniteInterruptedCheckedException e1) {
                    resFut.onDone(e1);
                    return;
                }
                if (ctx.discovery().node(nodeId) == null) {
                    if (bufMappings.remove(nodeId, buf)) {
                        final Buffer buf0 = buf;
                        waitAffinityAndRun(new Runnable() {

                            @Override
                            public void run() {
                                buf0.onNodeLeft();
                                if (f != null)
                                    f.onDone(new ClusterTopologyCheckedException("Failed to wait for request completion " + "(node has left): " + nodeId));
                            }
                        }, ctx.discovery().topologyVersion(), false);
                    }
                }
            }
        } finally {
            if (gate != null)
                gate.leave();
        }
    } catch (Exception ex) {
        resFut.onDone(new IgniteCheckedException("DataStreamer data loading failed.", ex));
    }
}
Also used : HashMap(java.util.HashMap) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheGateway(org.apache.ignite.internal.processors.cache.GridCacheGateway) UUID(java.util.UUID) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) Collection(java.util.Collection) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteException (org.apache.ignite.IgniteException)7 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 CacheException (javax.cache.CacheException)2 JMException (javax.management.JMException)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 IgniteDataStreamerTimeoutException (org.apache.ignite.IgniteDataStreamerTimeoutException)2 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)2 CacheExistsException (org.apache.ignite.cache.CacheExistsException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)2