Search in sources :

Example 36 with IgniteInterruptedCheckedException

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

the class GridClientAbstractProjection method withReconnectHandling.

/**
 * This method executes request to a communication layer and handles connection error, if it occurs. Server
 * is picked up according to the projection affinity and key given. Connection will be made with the node
 * on which key is cached. In case of communication exception client instance is notified and new instance
 * of client is created. If none of servers can be reached, an exception is thrown.
 *
 * @param c Closure to be executed.
 * @param cacheName Cache name for which mapped node will be calculated.
 * @param affKey Affinity key.
 * @param <R> Type of result in future.
 * @return Operation future.
 */
protected <R> GridClientFuture<R> withReconnectHandling(ClientProjectionClosure<R> c, String cacheName, @Nullable Object affKey) {
    GridClientDataAffinity affinity = client.affinity(cacheName);
    // If pinned (fixed-nodes) or no affinity provided use balancer.
    if (nodes != null || affinity == null || affKey == null)
        return withReconnectHandling(c);
    try {
        Collection<? extends GridClientNode> prjNodes = projectionNodes();
        if (prjNodes.isEmpty())
            throw new GridServerUnreachableException("Failed to get affinity node (no nodes in topology were " + "accepted by the filter): " + filter);
        GridClientNode node = affinity.node(affKey, prjNodes);
        for (int i = 0; i < RETRY_CNT; i++) {
            GridClientConnection conn = null;
            try {
                conn = client.connectionManager().connection(node);
                return c.apply(conn, node.nodeId());
            } catch (GridConnectionIdleClosedException e) {
                client.connectionManager().terminateConnection(conn, node, e);
            } catch (GridClientConnectionResetException e) {
                client.connectionManager().terminateConnection(conn, node, e);
                if (!checkNodeAlive(node.nodeId()))
                    throw new GridServerUnreachableException("Failed to communicate with mapped grid node for " + "given affinity key (node left the grid) [nodeId=" + node.nodeId() + ", affKey=" + affKey + ']', e);
            } catch (RuntimeException | Error e) {
                if (conn != null)
                    client.connectionManager().terminateConnection(conn, node, e);
                throw e;
            }
            U.sleep(RETRY_DELAY);
        }
        throw new GridServerUnreachableException("Failed to communicate with mapped grid node for given affinity " + "key (did node leave the grid?) [nodeId=" + node.nodeId() + ", affKey=" + affKey + ']');
    } catch (GridClientException e) {
        return new GridClientFutureAdapter<>(e);
    } catch (IgniteInterruptedCheckedException | InterruptedException e) {
        Thread.currentThread().interrupt();
        return new GridClientFutureAdapter<>(new GridClientException("Interrupted when (re)trying to perform " + "request.", e));
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridConnectionIdleClosedException(org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 37 with IgniteInterruptedCheckedException

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

the class CacheLockImpl method tryLock.

/**
 * {@inheritDoc}
 */
@Override
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
    if (Thread.interrupted())
        throw new InterruptedException();
    if (time <= 0)
        return tryLock();
    CacheOperationContext prev = gate.enter(opCtx);
    try {
        checkTx();
        IgniteInternalFuture<Boolean> fut = delegate.lockAllAsync(keys, unit.toMillis(time));
        try {
            boolean res = fut.get();
            if (res)
                incrementLockCounter();
            return res;
        } catch (IgniteInterruptedCheckedException e) {
            if (!fut.cancel()) {
                if (fut.isDone()) {
                    Boolean res = fut.get();
                    Thread.currentThread().interrupt();
                    if (res)
                        incrementLockCounter();
                    return res;
                }
            }
            if (e.getCause() instanceof InterruptedException)
                throw (InterruptedException) e.getCause();
            throw new InterruptedException();
        }
    } catch (IgniteCheckedException e) {
        throw new CacheException(e.getMessage(), e);
    } finally {
        gate.leave(prev);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException)

Example 38 with IgniteInterruptedCheckedException

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

the class GridDhtPartitionDemander method preloadEntry.

/**
 * Adds {@code entry} to partition {@code p}.
 *
 * @param from Node which sent entry.
 * @param p Partition id.
 * @param entry Preloaded entry.
 * @param topVer Topology version.
 * @return {@code False} if partition has become invalid during preloading.
 * @throws IgniteInterruptedCheckedException If interrupted.
 */
private boolean preloadEntry(ClusterNode from, int p, GridCacheEntryInfo entry, AffinityTopologyVersion topVer) throws IgniteCheckedException {
    ctx.database().checkpointReadLock();
    try {
        GridCacheEntryEx cached = null;
        try {
            GridCacheContext cctx = grp.sharedGroup() ? ctx.cacheContext(entry.cacheId()) : grp.singleCacheContext();
            cached = cctx.dhtCache().entryEx(entry.key());
            if (log.isDebugEnabled())
                log.debug("Rebalancing key [key=" + entry.key() + ", part=" + p + ", node=" + from.id() + ']');
            cctx.shared().database().checkpointReadLock();
            try {
                if (preloadPred == null || preloadPred.apply(entry)) {
                    if (cached.initialValue(entry.value(), entry.version(), entry.ttl(), entry.expireTime(), true, topVer, cctx.isDrEnabled() ? DR_PRELOAD : DR_NONE, false)) {
                        // Start tracking.
                        cctx.evicts().touch(cached, topVer);
                        if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_LOADED) && !cached.isInternal())
                            cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, entry.value(), true, null, false, null, null, null, true);
                    } else {
                        // Start tracking.
                        cctx.evicts().touch(cached, topVer);
                        if (log.isDebugEnabled())
                            log.debug("Rebalancing entry is already in cache (will ignore) [key=" + cached.key() + ", part=" + p + ']');
                    }
                } else if (log.isDebugEnabled())
                    log.debug("Rebalance predicate evaluated to false for entry (will ignore): " + entry);
            } finally {
                cctx.shared().database().checkpointReadUnlock();
            }
        } catch (GridCacheEntryRemovedException ignored) {
            if (log.isDebugEnabled())
                log.debug("Entry has been concurrently removed while rebalancing (will ignore) [key=" + cached.key() + ", part=" + p + ']');
        } catch (GridDhtInvalidPartitionException ignored) {
            if (log.isDebugEnabled())
                log.debug("Partition became invalid during rebalancing (will ignore): " + p);
            return false;
        }
    } catch (IgniteInterruptedCheckedException e) {
        throw e;
    } catch (IgniteCheckedException e) {
        throw new IgniteCheckedException("Failed to cache rebalanced entry (will stop rebalancing) [local=" + ctx.localNode() + ", node=" + from.id() + ", key=" + entry.key() + ", part=" + p + ']', e);
    } finally {
        ctx.database().checkpointReadUnlock();
    }
    return true;
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 39 with IgniteInterruptedCheckedException

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

the class GridDhtPartitionsExchangeFuture method init.

/**
 * Starts activity.
 *
 * @param newCrd {@code True} if node become coordinator on this exchange.
 * @throws IgniteInterruptedCheckedException If interrupted.
 */
public void init(boolean newCrd) throws IgniteInterruptedCheckedException {
    if (isDone())
        return;
    assert !cctx.kernalContext().isDaemon();
    initTs = U.currentTimeMillis();
    U.await(evtLatch);
    assert firstDiscoEvt != null : this;
    assert exchId.nodeId().equals(firstDiscoEvt.eventNode().id()) : this;
    try {
        AffinityTopologyVersion topVer = initialVersion();
        srvNodes = new ArrayList<>(firstEvtDiscoCache.serverNodes());
        remaining.addAll(F.nodeIds(F.view(srvNodes, F.remoteNodes(cctx.localNodeId()))));
        crd = srvNodes.isEmpty() ? null : srvNodes.get(0);
        boolean crdNode = crd != null && crd.isLocal();
        exchCtx = new ExchangeContext(crdNode, this);
        assert state == null : state;
        if (crdNode)
            state = ExchangeLocalState.CRD;
        else
            state = cctx.kernalContext().clientNode() ? ExchangeLocalState.CLIENT : ExchangeLocalState.SRV;
        if (exchLog.isInfoEnabled()) {
            exchLog.info("Started exchange init [topVer=" + topVer + ", crd=" + crdNode + ", evt=" + IgniteUtils.gridEventName(firstDiscoEvt.type()) + ", evtNode=" + firstDiscoEvt.eventNode().id() + ", customEvt=" + (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT ? ((DiscoveryCustomEvent) firstDiscoEvt).customMessage() : null) + ", allowMerge=" + exchCtx.mergeExchanges() + ']');
        }
        ExchangeType exchange;
        if (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            assert !exchCtx.mergeExchanges();
            DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) firstDiscoEvt).customMessage();
            forceAffReassignment = DiscoveryCustomEvent.requiresCentralizedAffinityAssignment(msg) && firstEventCache().minimumNodeVersion().compareToIgnoreTimestamp(FORCE_AFF_REASSIGNMENT_SINCE) >= 0;
            if (msg instanceof ChangeGlobalStateMessage) {
                assert exchActions != null && !exchActions.empty();
                exchange = onClusterStateChangeRequest(crdNode);
            } else if (msg instanceof DynamicCacheChangeBatch) {
                assert exchActions != null && !exchActions.empty();
                exchange = onCacheChangeRequest(crdNode);
            } else if (msg instanceof SnapshotDiscoveryMessage) {
                exchange = onCustomMessageNoAffinityChange(crdNode);
            } else if (msg instanceof WalStateAbstractMessage)
                exchange = onCustomMessageNoAffinityChange(crdNode);
            else {
                assert affChangeMsg != null : this;
                exchange = onAffinityChangeRequest(crdNode);
            }
            if (forceAffReassignment)
                cctx.affinity().onCentralizedAffinityChange(this, crdNode);
            initCoordinatorCaches(newCrd);
        } else {
            if (firstDiscoEvt.type() == EVT_NODE_JOINED) {
                if (!firstDiscoEvt.eventNode().isLocal()) {
                    Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(firstDiscoEvt.eventNode().id(), topVer);
                    cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
                } else
                    initCachesOnLocalJoin();
            }
            initCoordinatorCaches(newCrd);
            if (exchCtx.mergeExchanges()) {
                if (localJoinExchange()) {
                    if (cctx.kernalContext().clientNode()) {
                        onClientNodeEvent(crdNode);
                        exchange = ExchangeType.CLIENT;
                    } else {
                        onServerNodeEvent(crdNode);
                        exchange = ExchangeType.ALL;
                    }
                } else {
                    if (CU.clientNode(firstDiscoEvt.eventNode()))
                        exchange = onClientNodeEvent(crdNode);
                    else
                        exchange = cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL;
                }
                if (exchId.isLeft())
                    onLeft();
            } else {
                exchange = CU.clientNode(firstDiscoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
            }
        }
        updateTopologies(crdNode);
        switch(exchange) {
            case ALL:
                {
                    distributedExchange();
                    break;
                }
            case CLIENT:
                {
                    if (!exchCtx.mergeExchanges() && exchCtx.fetchAffinityOnJoin())
                        initTopologies();
                    clientOnlyExchange();
                    break;
                }
            case NONE:
                {
                    initTopologies();
                    onDone(topVer);
                    break;
                }
            default:
                assert false;
        }
        if (cctx.localNode().isClient())
            tryToPerformLocalSnapshotOperation();
        if (exchLog.isInfoEnabled())
            exchLog.info("Finished exchange init [topVer=" + topVer + ", crd=" + crdNode + ']');
    } catch (IgniteInterruptedCheckedException e) {
        onDone(e);
        throw e;
    } catch (IgniteNeedReconnectException e) {
        onDone(e);
    } catch (Throwable e) {
        if (reconnectOnError(e))
            onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
        else {
            U.error(log, "Failed to reinitialize local partitions (preloading will be stopped): " + exchId, e);
            onDone(e);
        }
        if (e instanceof Error)
            throw (Error) e;
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) ExchangeContext(org.apache.ignite.internal.processors.cache.ExchangeContext) WalStateAbstractMessage(org.apache.ignite.internal.processors.cache.WalStateAbstractMessage) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException)

Example 40 with IgniteInterruptedCheckedException

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

the class DataStreamerImpl method acquireRemapSemaphore.

/**
 */
private void acquireRemapSemaphore() throws IgniteInterruptedCheckedException {
    try {
        if (remapSem.availablePermits() != REMAP_SEMAPHORE_PERMISSIONS_COUNT) {
            if (timeout == DFLT_UNLIMIT_TIMEOUT) {
                // Wait until failed data being processed.
                remapSem.acquire(REMAP_SEMAPHORE_PERMISSIONS_COUNT);
                remapSem.release(REMAP_SEMAPHORE_PERMISSIONS_COUNT);
            } else {
                // Wait until failed data being processed.
                boolean res = remapSem.tryAcquire(REMAP_SEMAPHORE_PERMISSIONS_COUNT, timeout, TimeUnit.MILLISECONDS);
                if (res)
                    remapSem.release(REMAP_SEMAPHORE_PERMISSIONS_COUNT);
                else
                    throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout " + "while was waiting for failed data resending finished.");
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IgniteInterruptedCheckedException(e);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException)

Aggregations

IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)53 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)24 IOException (java.io.IOException)14 IgniteException (org.apache.ignite.IgniteException)11 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)11 ArrayList (java.util.ArrayList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 File (java.io.File)5 CacheException (javax.cache.CacheException)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 InetSocketAddress (java.net.InetSocketAddress)4 List (java.util.List)4 UUID (java.util.UUID)4 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)4 SocketTimeoutException (java.net.SocketTimeoutException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3