Search in sources :

Example 31 with IgniteInterruptedCheckedException

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

the class TcpDiscoveryMulticastIpFinder method requestAddresses.

/**
 * Sends multicast address request message and waits for reply. Response wait time and number
 * of request attempts are configured as properties {@link #setResponseWaitTime} and
 * {@link #setAddressRequestAttempts}.
 *
 * @param mcastAddr Multicast address where to send request.
 * @param sockItf Optional interface multicast socket should be bound to.
 * @return Tuple where first value is collection of received addresses, second is boolean which is
 *      {@code true} if got error on send.
 */
private T2<Collection<InetSocketAddress>, Boolean> requestAddresses(InetAddress mcastAddr, @Nullable InetAddress sockItf) {
    Collection<InetSocketAddress> rmtAddrs = new HashSet<>();
    boolean sndErr = false;
    try {
        DatagramPacket reqPckt = new DatagramPacket(MSG_ADDR_REQ_DATA, MSG_ADDR_REQ_DATA.length, mcastAddr, mcastPort);
        byte[] resData = new byte[AddressResponse.MAX_DATA_LENGTH];
        DatagramPacket resPckt = new DatagramPacket(resData, resData.length);
        boolean sndError = false;
        for (int i = 0; i < addrReqAttempts; i++) {
            MulticastSocket sock = null;
            try {
                sock = new MulticastSocket(0);
                // Use 'false' to enable support for more than one node on the same machine.
                sock.setLoopbackMode(false);
                if (sockItf != null)
                    sock.setInterface(sockItf);
                sock.setSoTimeout(resWaitTime);
                if (ttl != -1)
                    sock.setTimeToLive(ttl);
                reqPckt.setData(MSG_ADDR_REQ_DATA);
                try {
                    sock.send(reqPckt);
                } catch (IOException e) {
                    sndErr = true;
                    if (!handleNetworkError(e))
                        break;
                    if (i < addrReqAttempts - 1) {
                        if (log.isDebugEnabled())
                            log.debug("Failed to send multicast address request (will retry in 500 ms): " + e);
                        U.sleep(500);
                    } else {
                        if (log.isDebugEnabled())
                            log.debug("Failed to send multicast address request: " + e);
                    }
                    sndError = true;
                    continue;
                }
                long rcvEnd = U.currentTimeMillis() + resWaitTime;
                try {
                    while (U.currentTimeMillis() < rcvEnd) {
                        // Try to receive multiple responses.
                        sock.receive(resPckt);
                        byte[] data = resPckt.getData();
                        if (!U.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length)) {
                            U.error(log, "Failed to verify message header.");
                            continue;
                        }
                        AddressResponse addrRes;
                        try {
                            addrRes = new AddressResponse(data);
                        } catch (IgniteCheckedException e) {
                            LT.error(log, e, "Failed to deserialize multicast response.");
                            continue;
                        }
                        rmtAddrs.addAll(addrRes.addresses());
                    }
                } catch (SocketTimeoutException ignored) {
                    if (// DatagramSocket.receive timeout has expired.
                    log.isDebugEnabled())
                        log.debug("Address receive timeout.");
                }
            } catch (IOException e) {
                U.error(log, "Failed to request nodes addresses.", e);
            } finally {
                U.close(sock);
            }
            if (// Wait some time before re-sending address request.
            i < addrReqAttempts - 1)
                U.sleep(200);
        }
        if (log.isDebugEnabled())
            log.debug("Received nodes addresses: " + rmtAddrs);
        if (rmtAddrs.isEmpty() && sndError)
            U.quietAndWarn(log, "Failed to send multicast message (is multicast enabled on this node?).");
        return new T2<>(rmtAddrs, sndErr);
    } catch (IgniteInterruptedCheckedException ignored) {
        U.warn(log, "Got interrupted while sending address request.");
        Thread.currentThread().interrupt();
        return new T2<>(rmtAddrs, sndErr);
    }
}
Also used : MulticastSocket(java.net.MulticastSocket) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SocketTimeoutException(java.net.SocketTimeoutException) DatagramPacket(java.net.DatagramPacket) T2(org.apache.ignite.internal.util.typedef.T2) HashSet(java.util.HashSet)

Example 32 with IgniteInterruptedCheckedException

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

the class TcpDiscoverySharedFsIpFinder method initFolder.

/**
 * Initializes folder to work with.
 *
 * @return Folder.
 * @throws org.apache.ignite.spi.IgniteSpiException If failed.
 */
private File initFolder() throws IgniteSpiException {
    if (initGuard.compareAndSet(false, true)) {
        if (path == null)
            throw new IgniteSpiException("Shared file system path is null " + "(it should be configured via setPath(..) configuration property).");
        if (path.equals(DFLT_PATH) && warnGuard.compareAndSet(false, true))
            U.warn(log, "Default local computer-only share is used by IP finder.");
        try {
            File tmp;
            if (new File(path).exists())
                tmp = new File(path);
            else {
                try {
                    tmp = U.resolveWorkDirectory(ignite.configuration().getWorkDirectory(), path, false);
                } catch (IgniteCheckedException e) {
                    throw new IgniteSpiException("Failed to resolve directory [path=" + path + ", exception=" + e.getMessage() + ']');
                }
            }
            if (!tmp.isDirectory())
                throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must point to folder): " + path);
            if (!tmp.canRead() || !tmp.canWrite())
                throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must be readable and writable): " + path);
            folder = tmp;
        } finally {
            initLatch.countDown();
        }
    } else {
        try {
            U.await(initLatch);
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteSpiException("Thread has been interrupted.", e);
        }
        if (folder == null)
            throw new IgniteSpiException("Failed to initialize shared file system folder (check logs for errors).");
    }
    return folder;
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File)

Example 33 with IgniteInterruptedCheckedException

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

the class GridContinuousProcessor method registerHandler.

/**
 * @param nodeId Node ID.
 * @param routineId Consume ID.
 * @param hnd Handler.
 * @param bufSize Buffer size.
 * @param interval Time interval.
 * @param autoUnsubscribe Automatic unsubscribe flag.
 * @param loc Local registration flag.
 * @return Whether listener was actually registered.
 * @throws IgniteCheckedException In case of error.
 */
private boolean registerHandler(final UUID nodeId, final UUID routineId, final GridContinuousHandler hnd, int bufSize, final long interval, boolean autoUnsubscribe, boolean loc) throws IgniteCheckedException {
    assert nodeId != null;
    assert routineId != null;
    assert hnd != null;
    assert bufSize > 0;
    assert interval >= 0;
    final RemoteRoutineInfo info = new RemoteRoutineInfo(nodeId, hnd, bufSize, interval, autoUnsubscribe);
    boolean doRegister = loc;
    if (!doRegister) {
        stopLock.lock();
        try {
            doRegister = !stopped.remove(routineId) && rmtInfos.putIfAbsent(routineId, info) == null;
        } finally {
            stopLock.unlock();
        }
    }
    if (doRegister) {
        if (log.isDebugEnabled())
            log.debug("Register handler: [nodeId=" + nodeId + ", routineId=" + routineId + ", info=" + info + ']');
        if (interval > 0) {
            IgniteThread checker = new IgniteThread(new GridWorker(ctx.igniteInstanceName(), "continuous-buffer-checker", log) {

                @SuppressWarnings("ConstantConditions")
                @Override
                protected void body() {
                    long interval0 = interval;
                    while (!isCancelled()) {
                        try {
                            U.sleep(interval0);
                        } catch (IgniteInterruptedCheckedException ignored) {
                            break;
                        }
                        IgniteBiTuple<GridContinuousBatch, Long> t = info.checkInterval();
                        final GridContinuousBatch batch = t.get1();
                        if (batch != null && batch.size() > 0) {
                            try {
                                Collection<Object> toSnd = batch.collect();
                                boolean msg = toSnd.iterator().next() instanceof Message;
                                CI1<IgniteException> ackC = new CI1<IgniteException>() {

                                    @Override
                                    public void apply(IgniteException e) {
                                        if (e == null)
                                            info.hnd.onBatchAcknowledged(routineId, batch, ctx);
                                    }
                                };
                                sendNotification(nodeId, routineId, null, toSnd, hnd.orderedTopic(), msg, ackC);
                            } catch (ClusterTopologyCheckedException ignored) {
                                if (log.isDebugEnabled())
                                    log.debug("Failed to send notification to node (is node alive?): " + nodeId);
                            } catch (IgniteCheckedException e) {
                                U.error(log, "Failed to send notification to node: " + nodeId, e);
                            }
                        }
                        interval0 = t.get2();
                    }
                }
            });
            bufCheckThreads.put(routineId, checker);
            checker.start();
        }
        GridContinuousHandler.RegisterStatus status = hnd.register(nodeId, routineId, ctx);
        if (status == GridContinuousHandler.RegisterStatus.DELAYED) {
            info.markDelayedRegister();
            return false;
        } else
            return status == GridContinuousHandler.RegisterStatus.REGISTERED;
    }
    return false;
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) CI1(org.apache.ignite.internal.util.typedef.CI1) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) IgniteThread(org.apache.ignite.thread.IgniteThread) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 34 with IgniteInterruptedCheckedException

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

the class GridCachePartitionEvictionDuringReadThroughSelfTest method testPartitionRent.

/**
 * @throws Exception if failed.
 */
public void testPartitionRent() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-5759");
    startGrid(DATA_READ_GRID_IDX);
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<Long> gridAndCacheAccessFut = GridTestUtils.runMultiThreadedAsync(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            final Set<Integer> keysSet = new LinkedHashSet<>();
            keysSet.add(1);
            keysSet.add(2);
            keysSet.add(FAILING_KEY);
            keysSet.add(4);
            keysSet.add(5);
            while (!done.get()) {
                try {
                    grid(DATA_READ_GRID_IDX).<Integer, Integer>cache("config").getAll(keysSet);
                } catch (Throwable ignore) {
                // No-op.
                }
                if (Thread.currentThread().isInterrupted())
                    throw new IgniteInterruptedCheckedException("Execution of [" + Thread.currentThread().getName() + "] Interrupted. Test is probably timed out");
            }
            return null;
        }
    }, 4, "loader");
    IgniteInternalFuture<Void> startFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            for (int i = 1; i < 5; i++) {
                startGrid(i);
                awaitPartitionMapExchange();
            }
            return null;
        }
    });
    try {
        startFut.get();
    } catch (Exception e) {
        gridAndCacheAccessFut.cancel();
        U.error(log, e);
        throw e;
    }
    done.set(true);
    gridAndCacheAccessFut.get();
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 35 with IgniteInterruptedCheckedException

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

the class GridCachePartitionExchangeManager method onKernalStop0.

/**
 * {@inheritDoc}
 */
@Override
protected void onKernalStop0(boolean cancel) {
    exchWorker.onKernalStop();
    cctx.gridEvents().removeDiscoveryEventListener(discoLsnr);
    cctx.io().removeHandler(false, 0, GridDhtPartitionsSingleMessage.class);
    cctx.io().removeHandler(false, 0, GridDhtPartitionsFullMessage.class);
    cctx.io().removeHandler(false, 0, GridDhtPartitionsSingleRequest.class);
    stopErr = cctx.kernalContext().clientDisconnected() ? new IgniteClientDisconnectedCheckedException(cctx.kernalContext().cluster().clientReconnectFuture(), "Client node disconnected: " + cctx.igniteInstanceName()) : new IgniteInterruptedCheckedException("Node is stopping: " + cctx.igniteInstanceName());
    // Stop exchange worker
    U.cancel(exchWorker);
    if (log.isDebugEnabled())
        log.debug("Before joining on exchange worker: " + exchWorker);
    U.join(exchWorker, log);
    // Finish all exchange futures.
    ExchangeFutureSet exchFuts0 = exchFuts;
    for (CachePartitionExchangeWorkerTask task : exchWorker.futQ) {
        if (task instanceof GridDhtPartitionsExchangeFuture)
            ((GridDhtPartitionsExchangeFuture) task).onDone(stopErr);
    }
    if (exchFuts0 != null) {
        for (GridDhtPartitionsExchangeFuture f : exchFuts.values()) f.onDone(stopErr);
    }
    for (AffinityReadyFuture f : readyFuts.values()) f.onDone(stopErr);
    if (!cctx.kernalContext().clientNode()) {
        for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) cctx.io().removeOrderedHandler(true, rebalanceTopic(cnt));
    }
    ResendTimeoutObject resendTimeoutObj = pendingResend.getAndSet(null);
    if (resendTimeoutObj != null)
        cctx.time().removeTimeoutObject(resendTimeoutObj);
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)

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