Search in sources :

Example 26 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) {
    cctx.gridEvents().removeDiscoveryEventListener(discoLsnr);
    cctx.io().removeHandler(0, GridDhtPartitionsSingleMessage.class);
    cctx.io().removeHandler(0, GridDhtPartitionsFullMessage.class);
    cctx.io().removeHandler(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());
    // Finish all exchange futures.
    ExchangeFutureSet exchFuts0 = exchFuts;
    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(rebalanceTopic(cnt));
    }
    U.cancel(exchWorker);
    if (log.isDebugEnabled())
        log.debug("Before joining on exchange worker: " + exchWorker);
    U.join(exchWorker, log);
    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)

Example 27 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 28 with IgniteInterruptedCheckedException

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

the class GridContinuousOperationsLoadTest method main.

/**
     * Main method.
     *
     * @param args Command line arguments.
     * @throws Exception If error occurs.
     */
public static void main(String[] args) throws Exception {
    final String cfgPath = args.length > 0 ? args[0] : "examples/config/example-cache.xml";
    final String cacheName = getStringProperty(CACHE_NAME, "partitioned");
    final Integer valSize = getIntProperty(VALUE_SIZE, 1024);
    final Integer threadsCnt = getIntProperty(THREADS_CNT, 8);
    final Integer testDurSec = getIntProperty(TEST_DUR_SEC, 180);
    final Integer filterSkipProb = getIntProperty("FILTER_SKIP_PROBABILITY", 10, new C1<Integer, String>() {

        @Nullable
        @Override
        public String apply(Integer val) {
            if (val < 0 || val > 100)
                return "The value should be between 1 and 100.";
            return null;
        }
    });
    final boolean useQry = getBooleanProperty("IGNITE_USE_QUERIES", true);
    final int bufSize = getIntProperty("IGNITE_BUFFER_SIZE", 1);
    final long timeInterval = getLongProperty("IGNITE_TIME_INTERVAL", 0);
    final int parallelCnt = getIntProperty("IGNITE_PARALLEL_COUNT", 8);
    final int keyRange = getIntProperty("IGNITE_KEY_RANGE", 100000);
    final long updSleepMs = getLongProperty("IGNITE_UPDATE_SLEEP_MS", 0);
    final long filterSleepMs = getLongProperty("IGNITE_FILTER_SLEEP_MS", 0);
    final long cbSleepMs = getLongProperty("IGNITE_CALLBACK_SLEEP_MS", 0);
    X.println("The test will start with the following parameters:");
    dumpProperties(System.out);
    try (Ignite ignite = Ignition.start(cfgPath)) {
        final IgniteCache<Object, Object> cache = ignite.cache(cacheName);
        if (cache == null)
            throw new IgniteCheckedException("Cache is not configured: " + cacheName);
        // Continuous query manager, used to monitor queue size.
        final CacheContinuousQueryManager contQryMgr = ((IgniteKernal) ignite).context().cache().cache(cacheName).context().continuousQueries();
        if (contQryMgr == null)
            throw new IgniteCheckedException("Could not access CacheContinuousQueryManager");
        // Stop flag.
        final AtomicBoolean stop = new AtomicBoolean();
        // Callback counter.
        final AtomicLong cbCntr = new AtomicLong();
        // Update counter.
        final AtomicLong updCntr = new AtomicLong();
        for (int i = 0; i < parallelCnt; i++) {
            if (useQry) {
                ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
                qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

                    @Override
                    public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
                        if (cbSleepMs > 0) {
                            try {
                                U.sleep(cbSleepMs);
                            } catch (IgniteInterruptedCheckedException e) {
                                throw new IgniteException(e);
                            }
                        }
                        for (CacheEntryEvent<?, ?> ignored : evts) cbCntr.incrementAndGet();
                    }
                });
                qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {

                    @Override
                    public boolean evaluate(CacheEntryEvent<?, ?> evt) {
                        if (filterSleepMs > 0) {
                            try {
                                U.sleep(filterSleepMs);
                            } catch (IgniteInterruptedCheckedException e) {
                                throw new IgniteException(e);
                            }
                        }
                        return Math.random() * 100 >= filterSkipProb;
                    }
                });
                qry.setPageSize(bufSize);
                qry.setTimeInterval(timeInterval);
                cache.query(qry);
            } else {
                ignite.events().remoteListen(bufSize, timeInterval, true, new PX2<UUID, Event>() {

                    @Override
                    public boolean applyx(UUID uuid, Event evt) throws IgniteInterruptedCheckedException {
                        if (cbSleepMs > 0)
                            U.sleep(cbSleepMs);
                        cbCntr.incrementAndGet();
                        // Continue listening.
                        return true;
                    }
                }, new PX1<Event>() {

                    @Override
                    public boolean applyx(Event evt) throws IgniteInterruptedCheckedException {
                        if (filterSleepMs > 0)
                            U.sleep(filterSleepMs);
                        return Math.random() * 100 >= filterSkipProb;
                    }
                }, EVT_CACHE_OBJECT_PUT);
            }
        }
        // Start collector thread.
        startDaemon(new Runnable() {

            @Override
            public void run() {
                try {
                    while (!stop.get() && !Thread.currentThread().isInterrupted()) {
                        long cbCntr0 = cbCntr.get();
                        long updCntr0 = updCntr.get();
                        U.sleep(1000);
                        long cbDelta = cbCntr.get() - cbCntr0;
                        long updDelta = updCntr.get() - updCntr0;
                        X.println("Stats [entriesPerSec=" + cbDelta + ", updatesPerSec=" + updDelta + ']');
                    }
                } catch (IgniteInterruptedCheckedException ignored) {
                // No-op.
                }
            }
        });
        X.println("Starting " + threadsCnt + " generator thread(s).");
        // Start generator threads.
        IgniteInternalFuture<Long> genFut = runMultiThreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                byte[] val = new byte[valSize];
                ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
                while (!stop.get() && !Thread.currentThread().isInterrupted()) {
                    Integer key = rnd.nextInt(keyRange);
                    cache.put(key, val);
                    updCntr.incrementAndGet();
                    if (updSleepMs > 0)
                        U.sleep(updSleepMs);
                }
                return true;
            }
        }, threadsCnt, "load-test-generator");
        U.sleep(testDurSec * 1000);
        stop.set(true);
        genFut.get();
    }
}
Also used : CacheEntryEvent(javax.cache.event.CacheEntryEvent) CacheContinuousQueryManager(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ThreadLocalRandom8(org.jsr166.ThreadLocalRandom8) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Event(org.apache.ignite.events.Event) CacheEntryEvent(javax.cache.event.CacheEntryEvent) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with IgniteInterruptedCheckedException

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

the class GridIoManagerBenchmark method sendMessages.

/**
     * @param g Kernal.
     * @param threads Number of send threads.
     * @param duration Test duration.
     * @param outputFilename Output file name.
     */
@SuppressWarnings("deprecation")
private static void sendMessages(IgniteKernal g, int threads, int duration, @Nullable final String outputFilename) {
    X.println(">>> Sending messages.");
    g.context().io().addMessageListener(TEST_TOPIC, new SenderMessageListener());
    Thread collector = startDaemon(new Runnable() {

        @Override
        public void run() {
            final long initTs = System.currentTimeMillis();
            long ts = initTs;
            long queries = msgCntr.sum();
            GridCumulativeAverage qpsAvg = new GridCumulativeAverage();
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    U.sleep(10000);
                    long newTs = System.currentTimeMillis();
                    long newQueries = msgCntr.sum();
                    long executed = newQueries - queries;
                    long time = newTs - ts;
                    long qps = executed * 1000 / time;
                    boolean recordAvg = ts - initTs > WARM_UP_DUR;
                    if (recordAvg)
                        qpsAvg.update(qps);
                    X.println("Communication benchmark [qps=" + qps + (recordAvg ? ", qpsAvg=" + qpsAvg : "") + ", executed=" + executed + ", time=" + time + ']');
                    ts = newTs;
                    queries = newQueries;
                }
            } catch (IgniteInterruptedCheckedException ignored) {
            // No-op.
            }
            X.println("Average QPS: " + qpsAvg);
            if (outputFilename != null) {
                try {
                    X.println("Saving results to output file: " + outputFilename);
                    appendLineToFile(outputFilename, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), qpsAvg.get());
                } catch (IOException e) {
                    X.println("Failed to record results to a file: " + e.getMessage());
                }
            }
        }
    });
    Collection<SendThread> sndThreads = new ArrayList<>(threads);
    for (int i = 0; i < threads; i++) {
        SendThread t = new SendThread(g);
        sndThreads.add(t);
        t.start();
    }
    try {
        U.sleep(duration > 0 ? duration * 1000 + WARM_UP_DUR : Long.MAX_VALUE);
    } catch (IgniteInterruptedCheckedException ignored) {
    // No-op.
    }
    collector.interrupt();
    for (SendThread t : sndThreads) t.interrupt();
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date)

Example 30 with IgniteInterruptedCheckedException

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

the class IgniteProcessProxy method close.

/** {@inheritDoc} */
@Override
public void close() throws IgniteException {
    if (locJvmGrid != null) {
        final CountDownLatch rmtNodeStoppedLatch = new CountDownLatch(1);
        locJvmGrid.events().localListen(new IgnitePredicateX<Event>() {

            @Override
            public boolean applyx(Event e) {
                if (((DiscoveryEvent) e).eventNode().id().equals(id)) {
                    rmtNodeStoppedLatch.countDown();
                    return false;
                }
                return true;
            }
        }, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED);
        compute().run(new StopGridTask(localJvmGrid().name(), true));
        try {
            assert U.await(rmtNodeStoppedLatch, 15, TimeUnit.SECONDS) : "NodeId=" + id;
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteException(e);
        }
    }
    try {
        getProcess().kill();
    } catch (Exception e) {
        X.printerr("Could not kill process after close.", e);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) PluginNotFoundException(org.apache.ignite.plugin.PluginNotFoundException)

Aggregations

IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)45 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)23 IOException (java.io.IOException)13 IgniteException (org.apache.ignite.IgniteException)10 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)10 ArrayList (java.util.ArrayList)8 File (java.io.File)5 CacheException (javax.cache.CacheException)5 List (java.util.List)4 UUID (java.util.UUID)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 JobContextImpl (org.apache.hadoop.mapred.JobContextImpl)3 OutputFormat (org.apache.hadoop.mapreduce.OutputFormat)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 ServerSocket (java.net.ServerSocket)2