Search in sources :

Example 31 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.

the class InitNewCoordinatorFuture method init.

/**
 * @param exchFut Current future.
 * @throws IgniteCheckedException If failed.
 */
public void init(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException {
    initTopVer = exchFut.initialVersion();
    GridCacheSharedContext cctx = exchFut.sharedContext();
    restoreState = exchangeProtocolVersion(exchFut.context().events().discoveryCache().minimumNodeVersion()) > 1;
    boolean newAff = exchFut.localJoinExchange();
    IgniteInternalFuture<?> fut = cctx.affinity().initCoordinatorCaches(exchFut, newAff);
    if (fut != null)
        add(fut);
    if (restoreState) {
        DiscoCache curDiscoCache = cctx.discovery().discoCache();
        DiscoCache discoCache = exchFut.events().discoveryCache();
        List<ClusterNode> nodes = new ArrayList<>();
        synchronized (this) {
            for (ClusterNode node : discoCache.allNodes()) {
                if (!node.isLocal() && cctx.discovery().alive(node)) {
                    awaited.add(node.id());
                    nodes.add(node);
                } else if (!node.isLocal()) {
                    if (log.isInfoEnabled())
                        log.info("Init new coordinator future will skip remote node: " + node);
                }
            }
            if (exchFut.context().mergeExchanges() && !curDiscoCache.version().equals(discoCache.version())) {
                for (ClusterNode node : curDiscoCache.allNodes()) {
                    if (discoCache.node(node.id()) == null) {
                        if (exchangeProtocolVersion(node.version()) == 1)
                            break;
                        awaited.add(node.id());
                        nodes.add(node);
                        if (joinedNodes == null)
                            joinedNodes = new HashMap<>();
                        GridDhtPartitionExchangeId exchId = new GridDhtPartitionExchangeId(node.id(), EVT_NODE_JOINED, new AffinityTopologyVersion(node.order()));
                        joinedNodes.put(node.id(), exchId);
                    }
                }
            }
            if (joinedNodes == null)
                joinedNodes = Collections.emptyMap();
            if (!awaited.isEmpty()) {
                restoreStateFut = new GridFutureAdapter();
                add(restoreStateFut);
            }
        }
        if (log.isInfoEnabled()) {
            log.info("Try restore exchange result [awaited=" + awaited + ", joined=" + joinedNodes.keySet() + ", nodes=" + U.nodeIds(nodes) + ", discoAllNodes=" + U.nodeIds(discoCache.allNodes()) + ']');
        }
        if (!nodes.isEmpty()) {
            GridDhtPartitionsSingleRequest req = GridDhtPartitionsSingleRequest.restoreStateRequest(exchFut.exchangeId(), exchFut.exchangeId());
            for (ClusterNode node : nodes) {
                try {
                    GridDhtPartitionsSingleRequest sndReq = req;
                    if (joinedNodes.containsKey(node.id())) {
                        sndReq = GridDhtPartitionsSingleRequest.restoreStateRequest(joinedNodes.get(node.id()), exchFut.exchangeId());
                    }
                    cctx.io().send(node, sndReq, GridIoPolicy.SYSTEM_POOL);
                } catch (ClusterTopologyCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to send partitions request, node failed: " + node);
                    onNodeLeft(node.id());
                }
            }
        }
    }
    markInitialized();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) HashMap(java.util.HashMap) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 32 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.

the class MvccProcessorImpl method onCoordinatorFailed.

/**
 */
private void onCoordinatorFailed(UUID nodeId) {
    // 1. Notify all listeners waiting for a snapshot.
    Map<Long, MvccSnapshotResponseListener> map = snapLsnrs.remove(nodeId);
    if (map != null) {
        ClusterTopologyCheckedException ex = new ClusterTopologyCheckedException("Failed to request mvcc " + "version, coordinator left: " + nodeId);
        MvccSnapshotResponseListener lsnr;
        for (Long id : map.keySet()) {
            if ((lsnr = map.remove(id)) != null)
                lsnr.onError(ex);
        }
    }
    // 2. Notify acknowledge futures.
    for (WaitAckFuture fut : ackFuts.values()) fut.onNodeLeft(nodeId);
}
Also used : GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 33 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.

the class MvccProcessorImpl method ackTxRollback.

/**
 * {@inheritDoc}
 */
@Override
public void ackTxRollback(MvccVersion updateVer) {
    assert updateVer != null;
    MvccCoordinator crd = curCrd;
    if (crd.disconnected() || crd.version() != updateVer.coordinatorVersion())
        return;
    MvccAckRequestTx msg = new MvccAckRequestTx((long) -1, updateVer.counter());
    msg.skipResponse(true);
    try {
        sendMessage(crd.nodeId(), msg);
    } catch (ClusterTopologyCheckedException e) {
        if (log.isDebugEnabled())
            log.debug("Failed to send tx rollback ack, node left [msg=" + msg + ", node=" + crd.nodeId() + ']');
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send tx rollback ack [msg=" + msg + ", node=" + crd.nodeId() + ']', e);
    }
}
Also used : MvccAckRequestTx(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 34 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.

the class IgniteSnapshotManager method processLocalSnapshotStartStageResult.

/**
 * @param id Request id.
 * @param res Results.
 * @param err Errors.
 */
private void processLocalSnapshotStartStageResult(UUID id, Map<UUID, SnapshotOperationResponse> res, Map<UUID, Exception> err) {
    if (cctx.kernalContext().clientNode())
        return;
    SnapshotOperationRequest snpReq = clusterSnpReq;
    boolean cancelled = err.values().stream().anyMatch(e -> e instanceof IgniteFutureCancelledCheckedException);
    if (snpReq == null || !snpReq.requestId().equals(id)) {
        synchronized (snpOpMux) {
            if (clusterSnpFut != null && clusterSnpFut.rqId.equals(id)) {
                if (cancelled) {
                    clusterSnpFut.onDone(new IgniteFutureCancelledCheckedException("Execution of snapshot tasks " + "has been cancelled by external process [err=" + err + ", snpReq=" + snpReq + ']'));
                } else {
                    clusterSnpFut.onDone(new IgniteCheckedException("Snapshot operation has not been fully completed " + "[err=" + err + ", snpReq=" + snpReq + ']'));
                }
                clusterSnpFut = null;
            }
            return;
        }
    }
    snpReq.startStageEnded(true);
    if (isLocalNodeCoordinator(cctx.discovery())) {
        Set<UUID> missed = new HashSet<>(snpReq.nodes());
        missed.removeAll(res.keySet());
        missed.removeAll(err.keySet());
        if (cancelled) {
            snpReq.error(new IgniteFutureCancelledCheckedException("Execution of snapshot tasks " + "has been cancelled by external process [err=" + err + ", missed=" + missed + ']'));
        } else if (!missed.isEmpty()) {
            snpReq.error(new ClusterTopologyCheckedException("Snapshot operation interrupted, because baseline " + "node left the cluster. Uncompleted snapshot will be deleted [missed=" + missed + ']'));
        } else if (!F.isEmpty(err)) {
            snpReq.error(new IgniteCheckedException("Execution of local snapshot tasks fails. " + "Uncompleted snapshot will be deleted [err=" + err + ']'));
        }
        completeHandlersAsyncIfNeeded(snpReq, res.values()).listen(f -> {
            if (f.error() != null)
                snpReq.error(f.error());
            endSnpProc.start(snpReq.requestId(), snpReq);
        });
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) UUID(java.util.UUID) HashSet(java.util.HashSet) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 35 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.

the class IgniteTxHandler method sendReply.

/**
 * Sends tx finish response to remote node, if response is requested.
 *
 * @param nodeId Node id that originated finish request.
 * @param req Request.
 * @param committed {@code True} if transaction committed on this node.
 * @param nearTxId Near tx version.
 */
private void sendReply(UUID nodeId, GridDhtTxFinishRequest req, boolean committed, GridCacheVersion nearTxId) {
    if (req.replyRequired() || req.checkCommitted()) {
        GridDhtTxFinishResponse res = new GridDhtTxFinishResponse(req.partition(), req.version(), req.futureId(), req.miniId());
        if (req.checkCommitted()) {
            res.checkCommitted(true);
            if (committed) {
                if (req.needReturnValue()) {
                    try {
                        GridCacheReturnCompletableWrapper wrapper = ctx.tm().getCommittedTxReturn(req.version());
                        if (wrapper != null)
                            res.returnValue(wrapper.fut().get());
                        else
                            assert !ctx.discovery().alive(nodeId) : nodeId;
                    } catch (IgniteCheckedException ignored) {
                        if (txFinishMsgLog.isDebugEnabled()) {
                            txFinishMsgLog.debug("Failed to gain entry processor return value. [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
                        }
                    }
                }
            } else {
                ClusterTopologyCheckedException cause = new ClusterTopologyCheckedException("Primary node left grid.");
                res.checkCommittedError(new IgniteTxRollbackCheckedException("Failed to commit transaction " + "(transaction has been rolled back on backup node): " + req.version(), cause));
            }
        }
        try {
            ctx.io().send(nodeId, res, req.policy());
            if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Sent dht tx finish response [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ", checkCommitted=" + req.checkCommitted() + ']');
            }
        } catch (Throwable e) {
            // Double-check.
            if (ctx.discovery().node(nodeId) == null) {
                if (txFinishMsgLog.isDebugEnabled()) {
                    txFinishMsgLog.debug("Node left while send dht tx finish response [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
                }
            } else {
                U.error(log, "Failed to send finish response to node [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", nodeId=" + nodeId + ", res=" + res + ']', e);
            }
            if (e instanceof Error)
                throw (Error) e;
        }
    } else {
        if (txFinishMsgLog.isDebugEnabled()) {
            txFinishMsgLog.debug("Skip send dht tx finish response [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishResponse) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridCacheReturnCompletableWrapper(org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)112 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)82 ClusterNode (org.apache.ignite.cluster.ClusterNode)62 UUID (java.util.UUID)31 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)25 Map (java.util.Map)23 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)22 HashMap (java.util.HashMap)20 ArrayList (java.util.ArrayList)18 IgniteException (org.apache.ignite.IgniteException)18 Collection (java.util.Collection)16 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)15 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)15 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)14 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)12 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)12 Nullable (org.jetbrains.annotations.Nullable)12 List (java.util.List)11 ConcurrentMap (java.util.concurrent.ConcurrentMap)11 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)11