Search in sources :

Example 1 with GridManager

use of org.apache.ignite.internal.managers.GridManager in project ignite by apache.

the class IgniteKernal method start.

/**
 * @param cfg Configuration to use.
 * @param utilityCachePool Utility cache pool.
 * @param execSvc Executor service.
 * @param sysExecSvc System executor service.
 * @param stripedExecSvc Striped executor.
 * @param p2pExecSvc P2P executor service.
 * @param mgmtExecSvc Management executor service.
 * @param igfsExecSvc IGFS executor service.
 * @param dataStreamExecSvc data stream executor service.
 * @param restExecSvc Reset executor service.
 * @param affExecSvc Affinity executor service.
 * @param idxExecSvc Indexing executor service.
 * @param callbackExecSvc Callback executor service.
 * @param qryExecSvc Query executor service.
 * @param schemaExecSvc Schema executor service.
 * @param customExecSvcs Custom named executors.
 * @param errHnd Error handler to use for notification about startup problems.
 * @throws IgniteCheckedException Thrown in case of any errors.
 */
@SuppressWarnings({ "CatchGenericClass", "unchecked" })
public void start(final IgniteConfiguration cfg, ExecutorService utilityCachePool, final ExecutorService execSvc, final ExecutorService svcExecSvc, final ExecutorService sysExecSvc, final StripedExecutor stripedExecSvc, ExecutorService p2pExecSvc, ExecutorService mgmtExecSvc, ExecutorService igfsExecSvc, StripedExecutor dataStreamExecSvc, ExecutorService restExecSvc, ExecutorService affExecSvc, @Nullable ExecutorService idxExecSvc, IgniteStripedThreadPoolExecutor callbackExecSvc, ExecutorService qryExecSvc, ExecutorService schemaExecSvc, @Nullable final Map<String, ? extends ExecutorService> customExecSvcs, GridAbsClosure errHnd) throws IgniteCheckedException {
    gw.compareAndSet(null, new GridKernalGatewayImpl(cfg.getIgniteInstanceName()));
    GridKernalGateway gw = this.gw.get();
    gw.writeLock();
    try {
        switch(gw.getState()) {
            case STARTED:
                {
                    U.warn(log, "Grid has already been started (ignored).");
                    return;
                }
            case STARTING:
                {
                    U.warn(log, "Grid is already in process of being started (ignored).");
                    return;
                }
            case STOPPING:
                {
                    throw new IgniteCheckedException("Grid is in process of being stopped");
                }
            case STOPPED:
                {
                    break;
                }
        }
        gw.setState(STARTING);
    } finally {
        gw.writeUnlock();
    }
    assert cfg != null;
    // Make sure we got proper configuration.
    validateCommon(cfg);
    igniteInstanceName = cfg.getIgniteInstanceName();
    this.cfg = cfg;
    log = (GridLoggerProxy) cfg.getGridLogger().getLogger(getClass().getName() + (igniteInstanceName != null ? '%' + igniteInstanceName : ""));
    RuntimeMXBean rtBean = ManagementFactory.getRuntimeMXBean();
    // Ack various information.
    ackAsciiLogo();
    ackConfigUrl();
    ackConfiguration(cfg);
    ackDaemon();
    ackOsInfo();
    ackLanguageRuntime();
    ackRemoteManagement();
    ackLogger();
    ackVmArguments(rtBean);
    ackClassPaths(rtBean);
    ackSystemProperties();
    ackEnvironmentVariables();
    ackMemoryConfiguration();
    ackCacheConfiguration();
    ackP2pConfiguration();
    ackRebalanceConfiguration();
    // Run background network diagnostics.
    GridDiagnostic.runBackgroundCheck(igniteInstanceName, execSvc, log);
    // Ack 3-rd party licenses location.
    if (log.isInfoEnabled() && cfg.getIgniteHome() != null)
        log.info("3-rd party licenses can be found at: " + cfg.getIgniteHome() + File.separatorChar + "libs" + File.separatorChar + "licenses");
    // with internally reserved names.
    for (String name : cfg.getUserAttributes().keySet()) if (name.startsWith(ATTR_PREFIX))
        throw new IgniteCheckedException("User attribute has illegal name: '" + name + "'. Note that all names " + "starting with '" + ATTR_PREFIX + "' are reserved for internal use.");
    // Ack local node user attributes.
    logNodeUserAttributes();
    // Ack configuration.
    ackSpis();
    List<PluginProvider> plugins = U.allPluginProviders();
    // Spin out SPIs & managers.
    try {
        ctx = new GridKernalContextImpl(log, this, cfg, gw, utilityCachePool, execSvc, svcExecSvc, sysExecSvc, stripedExecSvc, p2pExecSvc, mgmtExecSvc, igfsExecSvc, dataStreamExecSvc, restExecSvc, affExecSvc, idxExecSvc, callbackExecSvc, qryExecSvc, schemaExecSvc, customExecSvcs, plugins, classNameFilter());
        cfg.getMarshaller().setContext(ctx.marshallerContext());
        GridInternalSubscriptionProcessor subscriptionProc = new GridInternalSubscriptionProcessor(ctx);
        startProcessor(subscriptionProc);
        ClusterProcessor clusterProc = new ClusterProcessor(ctx);
        startProcessor(clusterProc);
        U.onGridStart();
        // Start and configure resource processor first as it contains resources used
        // by all other managers and processors.
        GridResourceProcessor rsrcProc = new GridResourceProcessor(ctx);
        rsrcProc.setSpringContext(rsrcCtx);
        scheduler = new IgniteSchedulerImpl(ctx);
        startProcessor(rsrcProc);
        // Inject resources into lifecycle beans.
        if (!cfg.isDaemon() && cfg.getLifecycleBeans() != null) {
            for (LifecycleBean bean : cfg.getLifecycleBeans()) {
                if (bean != null)
                    rsrcProc.inject(bean);
            }
        }
        // Lifecycle notification.
        notifyLifecycleBeans(BEFORE_NODE_START);
        // Starts lifecycle aware components.
        U.startLifecycleAware(lifecycleAwares(cfg));
        addHelper(IGFS_HELPER.create(F.isEmpty(cfg.getFileSystemConfiguration())));
        addHelper(HADOOP_HELPER.createIfInClassPath(ctx, false));
        startProcessor(new IgnitePluginProcessor(ctx, cfg, plugins));
        startProcessor(new PoolProcessor(ctx));
        // Closure processor should be started before all others
        // (except for resource processor), as many components can depend on it.
        startProcessor(new GridClosureProcessor(ctx));
        // Start some other processors (order & place is important).
        startProcessor(new GridPortProcessor(ctx));
        startProcessor(new GridJobMetricsProcessor(ctx));
        // Timeout processor needs to be started before managers,
        // as managers may depend on it.
        startProcessor(new GridTimeoutProcessor(ctx));
        // Start security processors.
        startProcessor(createComponent(GridSecurityProcessor.class, ctx));
        // Start SPI managers.
        // NOTE: that order matters as there are dependencies between managers.
        startManager(new GridIoManager(ctx));
        startManager(new GridCheckpointManager(ctx));
        startManager(new GridEventStorageManager(ctx));
        startManager(new GridDeploymentManager(ctx));
        startManager(new GridLoadBalancerManager(ctx));
        startManager(new GridFailoverManager(ctx));
        startManager(new GridCollisionManager(ctx));
        startManager(new GridIndexingManager(ctx));
        ackSecurity();
        // Assign discovery manager to context before other processors start so they
        // are able to register custom event listener.
        final GridManager discoMgr = new GridDiscoveryManager(ctx);
        ctx.add(discoMgr, false);
        // be able to start receiving messages once discovery completes.
        try {
            startProcessor(new PdsConsistentIdProcessor(ctx));
            startProcessor(createComponent(DiscoveryNodeValidationProcessor.class, ctx));
            startProcessor(new GridAffinityProcessor(ctx));
            startProcessor(createComponent(GridSegmentationProcessor.class, ctx));
            startProcessor(createComponent(IgniteCacheObjectProcessor.class, ctx));
            startProcessor(createComponent(IGridClusterStateProcessor.class, ctx));
            startProcessor(new IgniteAuthenticationProcessor(ctx));
            startProcessor(new GridCacheProcessor(ctx));
            startProcessor(new GridQueryProcessor(ctx));
            startProcessor(new ClientListenerProcessor(ctx));
            startProcessor(new GridServiceProcessor(ctx));
            startProcessor(new GridTaskSessionProcessor(ctx));
            startProcessor(new GridJobProcessor(ctx));
            startProcessor(new GridTaskProcessor(ctx));
            startProcessor((GridProcessor) SCHEDULE.createOptional(ctx));
            startProcessor(new GridRestProcessor(ctx));
            startProcessor(new DataStreamProcessor(ctx));
            startProcessor((GridProcessor) IGFS.create(ctx, F.isEmpty(cfg.getFileSystemConfiguration())));
            startProcessor(new GridContinuousProcessor(ctx));
            startProcessor(createHadoopComponent());
            startProcessor(new DataStructuresProcessor(ctx));
            startProcessor(createComponent(PlatformProcessor.class, ctx));
            startProcessor(new GridMarshallerMappingProcessor(ctx));
            // Start plugins.
            for (PluginProvider provider : ctx.plugins().allProviders()) {
                ctx.add(new GridPluginComponent(provider));
                provider.start(ctx.plugins().pluginContextForProvider(provider));
            }
            // Start platform plugins.
            if (ctx.config().getPlatformConfiguration() != null)
                startProcessor(new PlatformPluginProcessor(ctx));
            ctx.cluster().initDiagnosticListeners();
            fillNodeAttributes(clusterProc.updateNotifierEnabled());
        } catch (Throwable e) {
            U.error(log, "Exception during start processors, node will be stopped and close connections", e);
            // Stop discovery spi to close tcp socket.
            ctx.discovery().stop(true);
            throw e;
        }
        gw.writeLock();
        try {
            gw.setState(STARTED);
            // Start discovery manager last to make sure that grid is fully initialized.
            startManager(discoMgr);
        } finally {
            gw.writeUnlock();
        }
        // Check whether physical RAM is not exceeded.
        checkPhysicalRam();
        // Suggest configuration optimizations.
        suggestOptimizations(cfg);
        // Suggest JVM optimizations.
        ctx.performance().addAll(JvmConfigurationSuggestions.getSuggestions());
        // Suggest Operation System optimizations.
        ctx.performance().addAll(OsConfigurationSuggestions.getSuggestions());
        DiscoveryLocalJoinData joinData = ctx.discovery().localJoin();
        IgniteInternalFuture<Boolean> transitionWaitFut = joinData.transitionWaitFuture();
        boolean active;
        if (transitionWaitFut != null) {
            if (log.isInfoEnabled()) {
                log.info("Join cluster while cluster state transition is in progress, " + "waiting when transition finish.");
            }
            active = transitionWaitFut.get();
        } else
            active = joinData.active();
        // Notify discovery manager the first to make sure that topology is discovered.
        ctx.discovery().onKernalStart(active);
        // Notify IO manager the second so further components can send and receive messages.
        ctx.io().onKernalStart(active);
        boolean recon = false;
        // Callbacks.
        for (GridComponent comp : ctx) {
            // Skip discovery manager.
            if (comp instanceof GridDiscoveryManager)
                continue;
            // Skip IO manager.
            if (comp instanceof GridIoManager)
                continue;
            if (comp instanceof GridPluginComponent)
                continue;
            if (!skipDaemon(comp)) {
                try {
                    comp.onKernalStart(active);
                } catch (IgniteNeedReconnectException e) {
                    assert ctx.discovery().reconnectSupported();
                    if (log.isDebugEnabled())
                        log.debug("Failed to start node components on node start, will wait for reconnect: " + e);
                    recon = true;
                }
            }
        }
        // Start plugins.
        for (PluginProvider provider : ctx.plugins().allProviders()) provider.onIgniteStart();
        if (recon)
            reconnectState.waitFirstReconnect();
        // Register MBeans.
        mBeansMgr.registerAllMBeans(utilityCachePool, execSvc, svcExecSvc, sysExecSvc, stripedExecSvc, p2pExecSvc, mgmtExecSvc, igfsExecSvc, dataStreamExecSvc, restExecSvc, affExecSvc, idxExecSvc, callbackExecSvc, qryExecSvc, schemaExecSvc, customExecSvcs);
        // Lifecycle bean notifications.
        notifyLifecycleBeans(AFTER_NODE_START);
    } catch (Throwable e) {
        IgniteSpiVersionCheckException verCheckErr = X.cause(e, IgniteSpiVersionCheckException.class);
        if (verCheckErr != null)
            U.error(log, verCheckErr.getMessage());
        else if (X.hasCause(e, InterruptedException.class, IgniteInterruptedCheckedException.class))
            U.warn(log, "Grid startup routine has been interrupted (will rollback).");
        else
            U.error(log, "Got exception while starting (will rollback startup routine).", e);
        errHnd.apply();
        stop(true);
        if (e instanceof Error)
            throw e;
        else if (e instanceof IgniteCheckedException)
            throw (IgniteCheckedException) e;
        else
            throw new IgniteCheckedException(e);
    }
    // Mark start timestamp.
    startTime = U.currentTimeMillis();
    String intervalStr = IgniteSystemProperties.getString(IGNITE_STARVATION_CHECK_INTERVAL);
    // Start starvation checker if enabled.
    boolean starveCheck = !isDaemon() && !"0".equals(intervalStr);
    if (starveCheck) {
        final long interval = F.isEmpty(intervalStr) ? PERIODIC_STARVATION_CHECK_FREQ : Long.parseLong(intervalStr);
        starveTask = ctx.timeout().schedule(new Runnable() {

            /**
             * Last completed task count.
             */
            private long lastCompletedCntPub;

            /**
             * Last completed task count.
             */
            private long lastCompletedCntSys;

            @Override
            public void run() {
                if (execSvc instanceof ThreadPoolExecutor) {
                    ThreadPoolExecutor exec = (ThreadPoolExecutor) execSvc;
                    lastCompletedCntPub = checkPoolStarvation(exec, lastCompletedCntPub, "public");
                }
                if (sysExecSvc instanceof ThreadPoolExecutor) {
                    ThreadPoolExecutor exec = (ThreadPoolExecutor) sysExecSvc;
                    lastCompletedCntSys = checkPoolStarvation(exec, lastCompletedCntSys, "system");
                }
                if (stripedExecSvc != null)
                    stripedExecSvc.checkStarvation();
            }

            /**
             * @param exec Thread pool executor to check.
             * @param lastCompletedCnt Last completed tasks count.
             * @param pool Pool name for message.
             * @return Current completed tasks count.
             */
            private long checkPoolStarvation(ThreadPoolExecutor exec, long lastCompletedCnt, String pool) {
                long completedCnt = exec.getCompletedTaskCount();
                // at least one waiting request, then it is possible starvation.
                if (exec.getPoolSize() == exec.getActiveCount() && completedCnt == lastCompletedCnt && !exec.getQueue().isEmpty())
                    LT.warn(log, "Possible thread pool starvation detected (no task completed in last " + interval + "ms, is " + pool + " thread pool size large enough?)");
                return completedCnt;
            }
        }, interval, interval);
    }
    long metricsLogFreq = cfg.getMetricsLogFrequency();
    if (metricsLogFreq > 0) {
        metricsLogTask = ctx.timeout().schedule(new Runnable() {

            private final DecimalFormat dblFmt = new DecimalFormat("#.##");

            @Override
            public void run() {
                if (log.isInfoEnabled()) {
                    try {
                        ClusterMetrics m = cluster().localNode().metrics();
                        double cpuLoadPct = m.getCurrentCpuLoad() * 100;
                        double avgCpuLoadPct = m.getAverageCpuLoad() * 100;
                        double gcPct = m.getCurrentGcCpuLoad() * 100;
                        // Heap params
                        long heapUsed = m.getHeapMemoryUsed();
                        long heapMax = m.getHeapMemoryMaximum();
                        long heapUsedInMBytes = heapUsed / 1024 / 1024;
                        long heapCommInMBytes = m.getHeapMemoryCommitted() / 1024 / 1024;
                        double freeHeapPct = heapMax > 0 ? ((double) ((heapMax - heapUsed) * 100)) / heapMax : -1;
                        // Non heap params
                        long nonHeapUsed = m.getNonHeapMemoryUsed();
                        long nonHeapMax = m.getNonHeapMemoryMaximum();
                        long nonHeapUsedInMBytes = nonHeapUsed / 1024 / 1024;
                        long nonHeapCommInMBytes = m.getNonHeapMemoryCommitted() / 1024 / 1024;
                        double freeNonHeapPct = nonHeapMax > 0 ? ((double) ((nonHeapMax - nonHeapUsed) * 100)) / nonHeapMax : -1;
                        int hosts = 0;
                        int nodes = 0;
                        int cpus = 0;
                        try {
                            ClusterMetrics metrics = cluster().metrics();
                            Collection<ClusterNode> nodes0 = cluster().nodes();
                            hosts = U.neighborhood(nodes0).size();
                            nodes = metrics.getTotalNodes();
                            cpus = metrics.getTotalCpus();
                        } catch (IgniteException ignore) {
                        // No-op.
                        }
                        int loadedPages = 0;
                        Collection<DataRegion> policies = ctx.cache().context().database().dataRegions();
                        if (!F.isEmpty(policies)) {
                            for (DataRegion memPlc : policies) loadedPages += memPlc.pageMemory().loadedPages();
                        }
                        String id = U.id8(localNode().id());
                        String msg = NL + "Metrics for local node (to disable set 'metricsLogFrequency' to 0)" + NL + "    ^-- Node [id=" + id + (name() != null ? ", name=" + name() : "") + ", uptime=" + getUpTimeFormatted() + "]" + NL + "    ^-- H/N/C [hosts=" + hosts + ", nodes=" + nodes + ", CPUs=" + cpus + "]" + NL + "    ^-- CPU [cur=" + dblFmt.format(cpuLoadPct) + "%, avg=" + dblFmt.format(avgCpuLoadPct) + "%, GC=" + dblFmt.format(gcPct) + "%]" + NL + "    ^-- PageMemory [pages=" + loadedPages + "]" + NL + "    ^-- Heap [used=" + dblFmt.format(heapUsedInMBytes) + "MB, free=" + dblFmt.format(freeHeapPct) + "%, comm=" + dblFmt.format(heapCommInMBytes) + "MB]" + NL + "    ^-- Non heap [used=" + dblFmt.format(nonHeapUsedInMBytes) + "MB, free=" + dblFmt.format(freeNonHeapPct) + "%, comm=" + dblFmt.format(nonHeapCommInMBytes) + "MB]" + NL + "    ^-- Outbound messages queue [size=" + m.getOutboundMessagesQueueSize() + "]" + NL + "    ^-- " + createExecutorDescription("Public thread pool", execSvc) + NL + "    ^-- " + createExecutorDescription("System thread pool", sysExecSvc);
                        if (customExecSvcs != null) {
                            StringBuilder customSvcsMsg = new StringBuilder();
                            for (Map.Entry<String, ? extends ExecutorService> entry : customExecSvcs.entrySet()) {
                                customSvcsMsg.append(NL).append("    ^-- ").append(createExecutorDescription(entry.getKey(), entry.getValue()));
                            }
                            msg = msg + customSvcsMsg;
                        }
                        if (log.isInfoEnabled())
                            log.info(msg);
                        ctx.cache().context().database().dumpStatistics(log);
                    } catch (IgniteClientDisconnectedException ignore) {
                    // No-op.
                    }
                }
            }
        }, metricsLogFreq, metricsLogFreq);
    }
    final long longOpDumpTimeout = IgniteSystemProperties.getLong(IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, 60_000);
    if (longOpDumpTimeout > 0) {
        longOpDumpTask = ctx.timeout().schedule(new Runnable() {

            @Override
            public void run() {
                GridKernalContext ctx = IgniteKernal.this.ctx;
                if (ctx != null)
                    ctx.cache().context().exchange().dumpLongRunningOperations(longOpDumpTimeout);
            }
        }, longOpDumpTimeout, longOpDumpTimeout);
    }
    ctx.performance().add("Disable assertions (remove '-ea' from JVM options)", !U.assertionsEnabled());
    ctx.performance().logSuggestions(log, igniteInstanceName);
    U.quietAndInfo(log, "To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}");
    ackStart(rtBean);
    if (!isDaemon())
        ctx.discovery().ackTopology(localNode().order());
}
Also used : DataStructuresProcessor(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridServiceProcessor(org.apache.ignite.internal.processors.service.GridServiceProcessor) IgniteException(org.apache.ignite.IgniteException) DiscoveryLocalJoinData(org.apache.ignite.internal.managers.discovery.DiscoveryLocalJoinData) IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridSecurityProcessor(org.apache.ignite.internal.processors.security.GridSecurityProcessor) GridCheckpointManager(org.apache.ignite.internal.managers.checkpoint.GridCheckpointManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridIndexingManager(org.apache.ignite.internal.managers.indexing.GridIndexingManager) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridMarshallerMappingProcessor(org.apache.ignite.internal.processors.marshaller.GridMarshallerMappingProcessor) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) GridTaskSessionProcessor(org.apache.ignite.internal.processors.session.GridTaskSessionProcessor) PlatformPluginProcessor(org.apache.ignite.internal.processors.platform.plugin.PlatformPluginProcessor) PluginProvider(org.apache.ignite.plugin.PluginProvider) IgniteAuthenticationProcessor(org.apache.ignite.internal.processors.authentication.IgniteAuthenticationProcessor) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) GridRestProcessor(org.apache.ignite.internal.processors.rest.GridRestProcessor) GridPortProcessor(org.apache.ignite.internal.processors.port.GridPortProcessor) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridAffinityProcessor(org.apache.ignite.internal.processors.affinity.GridAffinityProcessor) GridJobMetricsProcessor(org.apache.ignite.internal.processors.jobmetrics.GridJobMetricsProcessor) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) IgniteSpiVersionCheckException(org.apache.ignite.spi.IgniteSpiVersionCheckException) Map(java.util.Map) HashMap(java.util.HashMap) GridLoadBalancerManager(org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager) DataStreamProcessor(org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) PdsConsistentIdProcessor(org.apache.ignite.internal.processors.cache.persistence.filename.PdsConsistentIdProcessor) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) DecimalFormat(java.text.DecimalFormat) GridDeploymentManager(org.apache.ignite.internal.managers.deployment.GridDeploymentManager) GridManager(org.apache.ignite.internal.managers.GridManager) ClusterProcessor(org.apache.ignite.internal.processors.cluster.ClusterProcessor) OsDiscoveryNodeValidationProcessor(org.apache.ignite.internal.processors.nodevalidation.OsDiscoveryNodeValidationProcessor) DiscoveryNodeValidationProcessor(org.apache.ignite.internal.processors.nodevalidation.DiscoveryNodeValidationProcessor) ClientListenerProcessor(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) IGridClusterStateProcessor(org.apache.ignite.internal.processors.cluster.IGridClusterStateProcessor) GridSegmentationProcessor(org.apache.ignite.internal.processors.segmentation.GridSegmentationProcessor) GridCollisionManager(org.apache.ignite.internal.managers.collision.GridCollisionManager) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) GridTaskProcessor(org.apache.ignite.internal.processors.task.GridTaskProcessor) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor) RuntimeMXBean(java.lang.management.RuntimeMXBean) GridClosureProcessor(org.apache.ignite.internal.processors.closure.GridClosureProcessor) GridFailoverManager(org.apache.ignite.internal.managers.failover.GridFailoverManager) PlatformProcessor(org.apache.ignite.internal.processors.platform.PlatformProcessor) ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridResourceProcessor(org.apache.ignite.internal.processors.resource.GridResourceProcessor) PoolProcessor(org.apache.ignite.internal.processors.pool.PoolProcessor) GridJobProcessor(org.apache.ignite.internal.processors.job.GridJobProcessor) IgniteStripedThreadPoolExecutor(org.apache.ignite.thread.IgniteStripedThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with GridManager

use of org.apache.ignite.internal.managers.GridManager in project ignite by apache.

the class GridNioServerWrapper method resetNioServer.

/**
 * Recreates tpcSrvr socket instance.
 *
 * @return Server instance.
 * @throws IgniteCheckedException Thrown if it's not possible to create server.
 */
public GridNioServer<Message> resetNioServer() throws IgniteCheckedException {
    if (cfg.boundTcpPort() >= 0)
        throw new IgniteCheckedException("Tcp NIO server was already created on port " + cfg.boundTcpPort());
    IgniteCheckedException lastEx = null;
    // If configured TCP port is busy, find first available in range.
    int lastPort = cfg.localPort() == -1 ? -1 : cfg.localPortRange() == 0 ? cfg.localPort() : cfg.localPort() + cfg.localPortRange() - 1;
    for (int port = cfg.localPort(); port <= lastPort; port++) {
        try {
            MessageFactory msgFactory = new MessageFactory() {

                private MessageFactory impl;

                @Nullable
                @Override
                public Message create(short type) {
                    if (impl == null)
                        impl = stateProvider.getSpiContext().messageFactory();
                    assert impl != null;
                    return impl.create(type);
                }
            };
            GridNioMessageReaderFactory readerFactory = new GridNioMessageReaderFactory() {

                private IgniteSpiContext context;

                private MessageFormatter formatter;

                @Override
                public MessageReader reader(GridNioSession ses, MessageFactory msgFactory) throws IgniteCheckedException {
                    final IgniteSpiContext ctx = stateProvider.getSpiContextWithoutInitialLatch();
                    if (formatter == null || context != ctx) {
                        context = ctx;
                        formatter = context.messageFormatter();
                    }
                    assert formatter != null;
                    ConnectionKey key = ses.meta(CONN_IDX_META);
                    return key != null ? formatter.reader(key.nodeId(), msgFactory) : null;
                }
            };
            GridNioMessageWriterFactory writerFactory = new GridNioMessageWriterFactory() {

                private IgniteSpiContext context;

                private MessageFormatter formatter;

                @Override
                public MessageWriter writer(GridNioSession ses) throws IgniteCheckedException {
                    final IgniteSpiContext ctx = stateProvider.getSpiContextWithoutInitialLatch();
                    if (formatter == null || context != ctx) {
                        context = ctx;
                        formatter = context.messageFormatter();
                    }
                    assert formatter != null;
                    ConnectionKey key = ses.meta(CONN_IDX_META);
                    return key != null ? formatter.writer(key.nodeId()) : null;
                }
            };
            GridDirectParser parser = new GridDirectParser(log.getLogger(GridDirectParser.class), msgFactory, readerFactory);
            IgnitePredicate<Message> skipRecoveryPred = msg -> msg instanceof RecoveryLastReceivedMessage;
            boolean clientMode = Boolean.TRUE.equals(igniteCfg.isClientMode());
            IgniteBiInClosure<GridNioSession, Integer> queueSizeMonitor = !clientMode && cfg.slowClientQueueLimit() > 0 ? this::checkClientQueueSize : null;
            List<GridNioFilter> filters = new ArrayList<>();
            if (tracing instanceof GridTracingManager && ((GridManager) tracing).enabled())
                filters.add(new GridNioTracerFilter(log, tracing));
            filters.add(new GridNioCodecFilter(parser, log, true));
            filters.add(new GridConnectionBytesVerifyFilter(log));
            if (stateProvider.isSslEnabled()) {
                GridNioSslFilter sslFilter = new GridNioSslFilter(igniteCfg.getSslContextFactory().create(), true, ByteOrder.LITTLE_ENDIAN, log, metricMgr == null ? null : metricMgr.registry(COMMUNICATION_METRICS_GROUP_NAME));
                sslFilter.directMode(true);
                sslFilter.wantClientAuth(true);
                sslFilter.needClientAuth(true);
                filters.add(sslFilter);
            }
            GridNioServer.Builder<Message> builder = GridNioServer.<Message>builder().address(cfg.localHost()).port(port).listener(srvLsnr).logger(log).selectorCount(cfg.selectorsCount()).igniteInstanceName(igniteInstanceName).serverName("tcp-comm").tcpNoDelay(cfg.tcpNoDelay()).directBuffer(cfg.directBuffer()).byteOrder(ByteOrder.LITTLE_ENDIAN).socketSendBufferSize(cfg.socketSendBuffer()).socketReceiveBufferSize(cfg.socketReceiveBuffer()).sendQueueLimit(cfg.messageQueueLimit()).directMode(true).writeTimeout(cfg.socketWriteTimeout()).selectorSpins(cfg.selectorSpins()).filters(filters.toArray(new GridNioFilter[filters.size()])).writerFactory(writerFactory).skipRecoveryPredicate(skipRecoveryPred).messageQueueSizeListener(queueSizeMonitor).tracing(tracing).readWriteSelectorsAssign(cfg.usePairedConnections());
            if (metricMgr != null) {
                builder.workerListener(workersRegistry).metricRegistry(metricMgr.registry(COMMUNICATION_METRICS_GROUP_NAME));
            }
            GridNioServer<Message> srvr = builder.build();
            cfg.boundTcpPort(port);
            // Ack Port the TCP server was bound to.
            if (log.isInfoEnabled()) {
                log.info("Successfully bound communication NIO server to TCP port " + "[port=" + cfg.boundTcpPort() + ", locHost=" + cfg.localHost() + ", selectorsCnt=" + cfg.selectorsCount() + ", selectorSpins=" + srvr.selectorSpins() + ", pairedConn=" + cfg.usePairedConnections() + ']');
            }
            srvr.idleTimeout(cfg.idleConnectionTimeout());
            return srvr;
        } catch (IgniteCheckedException e) {
            if (X.hasCause(e, SSLException.class))
                throw new IgniteSpiException("Failed to create SSL context. SSL factory: " + igniteCfg.getSslContextFactory() + '.', e);
            lastEx = e;
            if (log.isDebugEnabled())
                log.debug("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + cfg.localHost() + ']');
            eRegistrySupplier.get().onException("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + cfg.localHost() + ']', e);
        }
    }
    // If free port wasn't found.
    throw new IgniteCheckedException("Failed to bind to any port within range [startPort=" + cfg.localPort() + ", portRange=" + cfg.localPortRange() + ", locHost=" + cfg.localHost() + ']', lastEx);
}
Also used : CommunicationTcpUtils.usePairedConnections(org.apache.ignite.spi.communication.tcp.internal.CommunicationTcpUtils.usePairedConnections) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridConnectionBytesVerifyFilter(org.apache.ignite.internal.util.nio.GridConnectionBytesVerifyFilter) NEED_WAIT(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage.NEED_WAIT) ThrowableSupplier(org.apache.ignite.internal.util.function.ThrowableSupplier) GridNioSessionMetaKey(org.apache.ignite.internal.util.nio.GridNioSessionMetaKey) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Map(java.util.Map) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) Channel(java.nio.channels.Channel) CommunicationTcpUtils.handshakeTimeoutException(org.apache.ignite.spi.communication.tcp.internal.CommunicationTcpUtils.handshakeTimeoutException) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) RecoveryLastReceivedMessage(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage) COMMUNICATION_METRICS_GROUP_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.COMMUNICATION_METRICS_GROUP_NAME) ByteOrder(java.nio.ByteOrder) ExponentialBackoffTimeoutStrategy(org.apache.ignite.spi.ExponentialBackoffTimeoutStrategy) SSLException(javax.net.ssl.SSLException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) GridNioSslFilter(org.apache.ignite.internal.util.nio.ssl.GridNioSslFilter) Message(org.apache.ignite.plugin.extensions.communication.Message) ALREADY_CONNECTED(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage.ALREADY_CONNECTED) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridSelectorNioSessionImpl(org.apache.ignite.internal.util.nio.GridSelectorNioSessionImpl) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) GridDirectParser(org.apache.ignite.internal.util.nio.GridDirectParser) Supplier(java.util.function.Supplier) GridNioMessageWriterFactory(org.apache.ignite.internal.util.nio.GridNioMessageWriterFactory) ArrayList(java.util.ArrayList) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) SocketException(java.net.SocketException) ClusterNode(org.apache.ignite.cluster.ClusterNode) SocketTimeoutException(java.net.SocketTimeoutException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CONN_IDX_META(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.CONN_IDX_META) IgniteExceptionRegistry(org.apache.ignite.internal.util.IgniteExceptionRegistry) IOException(java.io.IOException) CommunicationTcpUtils.isRecoverableException(org.apache.ignite.spi.communication.tcp.internal.CommunicationTcpUtils.isRecoverableException) HandshakeMessage(org.apache.ignite.spi.communication.tcp.messages.HandshakeMessage) GridTracingManager(org.apache.ignite.internal.managers.tracing.GridTracingManager) CHANNEL_COMMUNICATION(org.apache.ignite.internal.IgniteFeatures.CHANNEL_COMMUNICATION) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CommunicationTcpUtils.nodeAddresses(org.apache.ignite.spi.communication.tcp.internal.CommunicationTcpUtils.nodeAddresses) SocketAddress(java.net.SocketAddress) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) IgniteFeatures.nodeSupports(org.apache.ignite.internal.IgniteFeatures.nodeSupports) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SocketChannel(java.nio.channels.SocketChannel) GridNioTracerFilter(org.apache.ignite.internal.util.nio.GridNioTracerFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) X(org.apache.ignite.internal.util.typedef.X) CONSISTENT_ID_META(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.CONSISTENT_ID_META) GridConcurrentFactory(org.apache.ignite.internal.util.GridConcurrentFactory) GridSslMeta(org.apache.ignite.internal.util.nio.ssl.GridSslMeta) WorkersRegistry(org.apache.ignite.internal.worker.WorkersRegistry) MessageFormatter(org.apache.ignite.plugin.extensions.communication.MessageFormatter) IgniteThreadFactory(org.apache.ignite.thread.IgniteThreadFactory) NodeIdMessage(org.apache.ignite.spi.communication.tcp.messages.NodeIdMessage) IgniteDiscoveryThread(org.apache.ignite.spi.discovery.IgniteDiscoveryThread) SSL_META(org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.SSL_META) Collection(java.util.Collection) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) AttributeNames(org.apache.ignite.spi.communication.tcp.AttributeNames) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) TimeoutStrategy(org.apache.ignite.spi.TimeoutStrategy) NODE_STOPPING(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage.NODE_STOPPING) CommunicationListener(org.apache.ignite.spi.communication.CommunicationListener) Tracing(org.apache.ignite.internal.processors.tracing.Tracing) IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) HashMap(java.util.HashMap) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) SSLEngine(javax.net.ssl.SSLEngine) GridNioMessageReaderFactory(org.apache.ignite.internal.util.nio.GridNioMessageReaderFactory) HashSet(java.util.HashSet) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MessageWriter(org.apache.ignite.plugin.extensions.communication.MessageWriter) ThrowableBiFunction(org.apache.ignite.internal.util.function.ThrowableBiFunction) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) IgniteTooManyOpenFilesException(org.apache.ignite.internal.IgniteTooManyOpenFilesException) GridManager(org.apache.ignite.internal.managers.GridManager) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) MessageReader(org.apache.ignite.plugin.extensions.communication.MessageReader) TimeUnit(java.util.concurrent.TimeUnit) GridNioServerListener(org.apache.ignite.internal.util.nio.GridNioServerListener) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) UNKNOWN_NODE(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage.UNKNOWN_NODE) HandshakeMessage2(org.apache.ignite.spi.communication.tcp.messages.HandshakeMessage2) GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) RecoveryLastReceivedMessage(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HandshakeMessage(org.apache.ignite.spi.communication.tcp.messages.HandshakeMessage) NodeIdMessage(org.apache.ignite.spi.communication.tcp.messages.NodeIdMessage) ArrayList(java.util.ArrayList) MessageFormatter(org.apache.ignite.plugin.extensions.communication.MessageFormatter) GridNioSslFilter(org.apache.ignite.internal.util.nio.ssl.GridNioSslFilter) SSLException(javax.net.ssl.SSLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDirectParser(org.apache.ignite.internal.util.nio.GridDirectParser) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridNioMessageWriterFactory(org.apache.ignite.internal.util.nio.GridNioMessageWriterFactory) RecoveryLastReceivedMessage(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridNioTracerFilter(org.apache.ignite.internal.util.nio.GridNioTracerFilter) GridConnectionBytesVerifyFilter(org.apache.ignite.internal.util.nio.GridConnectionBytesVerifyFilter) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridTracingManager(org.apache.ignite.internal.managers.tracing.GridTracingManager) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) GridNioMessageReaderFactory(org.apache.ignite.internal.util.nio.GridNioMessageReaderFactory)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 GridManager (org.apache.ignite.internal.managers.GridManager)2 IOException (java.io.IOException)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ByteOrder (java.nio.ByteOrder)1 Channel (java.nio.channels.Channel)1 SocketChannel (java.nio.channels.SocketChannel)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1