Search in sources :

Example 16 with IgniteThread

use of org.apache.ignite.thread.IgniteThread in project ignite by apache.

the class GridCachePartitionExchangeManager method onKernalStart0.

/** {@inheritDoc} */
@Override
protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException {
    super.onKernalStart0(reconnect);
    ClusterNode loc = cctx.localNode();
    long startTime = loc.metrics().getStartTime();
    assert startTime > 0;
    // Generate dummy discovery event for local node joining.
    T2<DiscoveryEvent, DiscoCache> locJoin = cctx.discovery().localJoin();
    DiscoveryEvent discoEvt = locJoin.get1();
    DiscoCache discoCache = locJoin.get2();
    GridDhtPartitionExchangeId exchId = initialExchangeId();
    GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, discoCache, null, null);
    if (reconnect)
        reconnectExchangeFut = new GridFutureAdapter<>();
    exchWorker.addFirstExchangeFuture(fut);
    if (!cctx.kernalContext().clientNode()) {
        for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) {
            final int idx = cnt;
            cctx.io().addOrderedHandler(rebalanceTopic(cnt), new CI2<UUID, GridCacheMessage>() {

                @Override
                public void apply(final UUID id, final GridCacheMessage m) {
                    if (!enterBusy())
                        return;
                    try {
                        GridCacheContext cacheCtx = cctx.cacheContext(m.cacheId);
                        if (cacheCtx != null) {
                            if (m instanceof GridDhtPartitionSupplyMessage)
                                cacheCtx.preloader().handleSupplyMessage(idx, id, (GridDhtPartitionSupplyMessage) m);
                            else if (m instanceof GridDhtPartitionDemandMessage)
                                cacheCtx.preloader().handleDemandMessage(idx, id, (GridDhtPartitionDemandMessage) m);
                            else
                                U.error(log, "Unsupported message type: " + m.getClass().getName());
                        }
                    } finally {
                        leaveBusy();
                    }
                }
            });
        }
    }
    new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
    if (reconnect) {
        fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                try {
                    fut.get();
                    for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(null);
                    reconnectExchangeFut.onDone();
                } catch (IgniteCheckedException e) {
                    for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(e);
                    reconnectExchangeFut.onDone(e);
                }
            }
        });
    } else {
        if (log.isDebugEnabled())
            log.debug("Beginning to wait on local exchange future: " + fut);
        boolean first = true;
        while (true) {
            try {
                fut.get(cctx.preloadExchangeTimeout());
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (first) {
                    U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + "  ^-- Transactions in deadlock." + U.nl() + "  ^-- Long running transactions (ignore if this is the case)." + U.nl() + "  ^-- Unreleased explicit locks.");
                    first = false;
                } else
                    U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
            } catch (IgniteNeedReconnectException e) {
                throw e;
            } catch (Exception e) {
                if (fut.reconnectOnError(e))
                    throw new IgniteNeedReconnectException(cctx.localNode(), e);
                throw e;
            }
        }
        AffinityTopologyVersion nodeStartVer = new AffinityTopologyVersion(discoEvt.topologyVersion(), 0);
        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
            if (nodeStartVer.equals(cacheCtx.startTopologyVersion()))
                cacheCtx.preloader().onInitialExchangeComplete(null);
        }
        if (log.isDebugEnabled())
            log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
    }
}
Also used : DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) UUID(java.util.UUID) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)

Example 17 with IgniteThread

use of org.apache.ignite.thread.IgniteThread in project ignite by apache.

the class HadoopExternalCommunication method createShmemClient.

/**
     * @param desc Process descriptor.
     * @param port Port.
     * @return Client.
     * @throws IgniteCheckedException If failed.
     */
@Nullable
protected HadoopCommunicationClient createShmemClient(HadoopProcessDescriptor desc, int port) throws IgniteCheckedException {
    int attempt = 1;
    int connectAttempts = 1;
    long connTimeout0 = connTimeout;
    while (true) {
        IpcEndpoint clientEndpoint;
        try {
            clientEndpoint = new IpcSharedMemoryClientEndpoint(port, (int) connTimeout, log);
        } catch (IgniteCheckedException e) {
            // Reconnect for the second time, if connection is not established.
            if (connectAttempts < 2 && X.hasCause(e, ConnectException.class)) {
                connectAttempts++;
                continue;
            }
            throw e;
        }
        HadoopCommunicationClient client = null;
        try {
            ShmemWorker worker = new ShmemWorker(clientEndpoint, false);
            shmemWorkers.add(worker);
            GridNioSession ses = worker.session();
            HandshakeFinish fin = new HandshakeFinish();
            // We are in lock, it is safe to get session and attach
            ses.addMeta(HANDSHAKE_FINISH_META, fin);
            client = new HadoopTcpNioCommunicationClient(ses);
            new IgniteThread(worker).start();
            fin.await(connTimeout0);
        } catch (HadoopHandshakeTimeoutException e) {
            if (log.isDebugEnabled())
                log.debug("Handshake timed out (will retry with increased timeout) [timeout=" + connTimeout0 + ", err=" + e.getMessage() + ", client=" + client + ']');
            if (client != null)
                client.forceClose();
            if (attempt == reconCnt || connTimeout0 > maxConnTimeout) {
                if (log.isDebugEnabled())
                    log.debug("Handshake timedout (will stop attempts to perform the handshake) " + "[timeout=" + connTimeout0 + ", maxConnTimeout=" + maxConnTimeout + ", attempt=" + attempt + ", reconCnt=" + reconCnt + ", err=" + e.getMessage() + ", client=" + client + ']');
                throw e;
            } else {
                attempt++;
                connTimeout0 *= 2;
                continue;
            }
        } catch (RuntimeException | Error e) {
            if (log.isDebugEnabled())
                log.debug("Caught exception (will close client) [err=" + e.getMessage() + ", client=" + client + ']');
            if (client != null)
                client.forceClose();
            throw e;
        }
        return client;
    }
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) IpcSharedMemoryClientEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryClientEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with IgniteThread

use of org.apache.ignite.thread.IgniteThread 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 19 with IgniteThread

use of org.apache.ignite.thread.IgniteThread in project ignite by apache.

the class IgfsFragmentizerManager method start0.

/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
    if (!igfsCtx.configuration().isFragmentizerEnabled())
        return;
    // We care only about node leave and fail events.
    igfsCtx.kernalContext().event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
            DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
            checkLaunchCoordinator(discoEvt);
        }
    }, EVT_NODE_LEFT, EVT_NODE_FAILED);
    fragmentizerWorker = new FragmentizerWorker();
    String igfsName = igfsCtx.configuration().getName();
    topic = F.isEmpty(igfsName) ? TOPIC_IGFS : TOPIC_IGFS.topic(igfsName);
    igfsCtx.kernalContext().io().addMessageListener(topic, fragmentizerWorker);
    new IgniteThread(fragmentizerWorker).start();
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteThread(org.apache.ignite.thread.IgniteThread)

Example 20 with IgniteThread

use of org.apache.ignite.thread.IgniteThread in project ignite by apache.

the class IpcSharedMemoryServerEndpoint method start.

/** {@inheritDoc} */
@Override
public void start() throws IgniteCheckedException {
    IpcSharedMemoryNativeLoader.load(log);
    pid = IpcSharedMemoryUtils.pid();
    if (pid == -1)
        throw new IpcEndpointBindException("Failed to get PID of the current process.");
    if (size <= 0)
        throw new IpcEndpointBindException("Space size should be positive: " + size);
    String tokDirPath = this.tokDirPath;
    if (F.isEmpty(tokDirPath))
        throw new IpcEndpointBindException("Token directory path is empty.");
    tokDirPath = tokDirPath + '/' + locNodeId.toString() + '-' + IpcSharedMemoryUtils.pid();
    tokDir = U.resolveWorkDirectory(workDir, tokDirPath, false);
    if (port <= 0 || port >= 0xffff)
        throw new IpcEndpointBindException("Port value is illegal: " + port);
    try {
        srvSock = new ServerSocket();
        // Always bind to loopback.
        srvSock.bind(new InetSocketAddress("127.0.0.1", port));
    } catch (IOException e) {
        // Although empty socket constructor never throws exception, close it just in case.
        U.closeQuiet(srvSock);
        throw new IpcEndpointBindException("Failed to bind shared memory IPC endpoint (is port already " + "in use?): " + port, e);
    }
    gcWorker = new GcWorker(igniteInstanceName, "ipc-shmem-gc", log);
    new IgniteThread(gcWorker).start();
    if (log.isInfoEnabled())
        log.info("IPC shared memory server endpoint started [port=" + port + ", tokDir=" + tokDir.getAbsolutePath() + ']');
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) IgniteThread(org.apache.ignite.thread.IgniteThread) IpcEndpointBindException(org.apache.ignite.internal.util.ipc.IpcEndpointBindException)

Aggregations

IgniteThread (org.apache.ignite.thread.IgniteThread)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IOException (java.io.IOException)3 Ignite (org.apache.ignite.Ignite)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 GridWorker (org.apache.ignite.internal.util.worker.GridWorker)3 Collection (java.util.Collection)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 CI1 (org.apache.ignite.internal.util.typedef.CI1)2 SparseDistributedMatrix (org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix)2 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1