Search in sources :

Example 1 with TxnLogProcessor

use of com.actiontech.dble.log.transaction.TxnLogProcessor in project dble by actiontech.

the class DbleServer method startup.

public void startup() throws IOException {
    SystemConfig system = config.getSystem();
    // server startup
    LOGGER.info("===============================================");
    LOGGER.info(NAME + "Server is ready to startup ...");
    String inf = "Startup processors ...,total processors:" + system.getProcessors() + ",aio thread pool size:" + system.getProcessorExecutor() + "    \r\n each process allocated socket buffer pool " + " bytes ,a page size:" + system.getBufferPoolPageSize() + "  a page's chunk number(PageSize/ChunkSize) is:" + (system.getBufferPoolPageSize() / system.getBufferPoolChunkSize()) + "  buffer page's number is:" + system.getBufferPoolPageNumber();
    LOGGER.info(inf);
    LOGGER.info("sysconfig params:" + system.toString());
    backupLocked = new AtomicBoolean(false);
    // startup manager
    ManagerConnectionFactory mf = new ManagerConnectionFactory();
    ServerConnectionFactory sf = new ServerConnectionFactory();
    SocketAcceptor manager;
    SocketAcceptor server;
    aio = (system.getUsingAIO() == 1);
    // startup processors
    int frontProcessorCount = system.getProcessors();
    int backendProcessorCount = system.getBackendProcessors();
    frontProcessors = new NIOProcessor[frontProcessorCount];
    backendProcessors = new NIOProcessor[backendProcessorCount];
    // a page size
    int bufferPoolPageSize = system.getBufferPoolPageSize();
    // total page number
    short bufferPoolPageNumber = system.getBufferPoolPageNumber();
    // minimum allocation unit
    short bufferPoolChunkSize = system.getBufferPoolChunkSize();
    totalNetWorkBufferSize = bufferPoolPageSize * bufferPoolPageNumber;
    if (totalNetWorkBufferSize > Platform.getMaxDirectMemory()) {
        throw new IOException("Direct BufferPool size lager than MaxDirectMemory");
    }
    bufferPool = new DirectByteBufferPool(bufferPoolPageSize, bufferPoolChunkSize, bufferPoolPageNumber);
    businessExecutor = ExecutorUtil.createFixed("BusinessExecutor", system.getProcessorExecutor());
    backendBusinessExecutor = ExecutorUtil.createFixed("backendBusinessExecutor", system.getBackendProcessorExecutor());
    complexQueryExecutor = ExecutorUtil.createCached("complexQueryExecutor", system.getComplexExecutor());
    timerExecutor = ExecutorUtil.createFixed("Timer", 1);
    if (system.getUsePerformanceMode() == 1) {
        concurrentFrontHandlerQueue = new ConcurrentLinkedQueue<>();
        for (int i = 0; i < system.getProcessorExecutor(); i++) {
            businessExecutor.execute(new ConcurrentFrontEndHandlerRunnable(concurrentFrontHandlerQueue));
        }
        concurrentBackHandlerQueue = new ConcurrentLinkedQueue<>();
        for (int i = 0; i < system.getBackendProcessorExecutor(); i++) {
            backendBusinessExecutor.execute(new ConcurrentBackEndHandlerRunnable(concurrentBackHandlerQueue));
        }
    } else {
        frontHandlerQueue = new LinkedBlockingQueue<>();
        for (int i = 0; i < system.getProcessorExecutor(); i++) {
            businessExecutor.execute(new FrontEndHandlerRunnable(frontHandlerQueue));
        }
    }
    for (int i = 0; i < frontProcessorCount; i++) {
        frontProcessors[i] = new NIOProcessor("frontProcessor" + i, bufferPool);
    }
    for (int i = 0; i < backendProcessorCount; i++) {
        backendProcessors[i] = new NIOProcessor("backendProcessor" + i, bufferPool);
    }
    if (aio) {
        int processorCount = frontProcessorCount + backendProcessorCount;
        LOGGER.info("using aio network handler ");
        asyncChannelGroups = new AsynchronousChannelGroup[processorCount];
        // startup connector
        connector = new AIOConnector();
        for (int i = 0; i < processorCount; i++) {
            asyncChannelGroups[i] = AsynchronousChannelGroup.withFixedThreadPool(processorCount, new ThreadFactory() {

                private int inx = 1;

                @Override
                public Thread newThread(Runnable r) {
                    Thread th = new Thread(r);
                    // TODO
                    th.setName(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + "AIO" + (inx++));
                    LOGGER.info("created new AIO thread " + th.getName());
                    return th;
                }
            });
        }
        manager = new AIOAcceptor(NAME + "Manager", system.getBindIp(), system.getManagerPort(), 100, mf, this.asyncChannelGroups[0]);
        // startup server
        server = new AIOAcceptor(NAME + "Server", system.getBindIp(), system.getServerPort(), system.getServerBacklog(), sf, this.asyncChannelGroups[0]);
    } else {
        LOGGER.info("using nio network handler ");
        NIOReactorPool frontReactorPool = new NIOReactorPool(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + "NIO_REACTOR_FRONT", frontProcessorCount);
        NIOReactorPool backendReactorPool = new NIOReactorPool(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + "NIO_REACTOR_BACKEND", backendProcessorCount);
        connector = new NIOConnector(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + "NIOConnector", backendReactorPool);
        ((NIOConnector) connector).start();
        manager = new NIOAcceptor(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + NAME + "Manager", system.getBindIp(), system.getManagerPort(), 100, mf, frontReactorPool);
        server = new NIOAcceptor(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + NAME + "Server", system.getBindIp(), system.getServerPort(), system.getServerBacklog(), sf, frontReactorPool);
    }
    // start transaction SQL log
    if (config.getSystem().getRecordTxn() == 1) {
        txnLogProcessor = new TxnLogProcessor(bufferPool);
        txnLogProcessor.setName("TxnLogProcessor");
        txnLogProcessor.start();
    }
    pullVarAndMeta();
    // initialized the cache service
    cacheService = new CacheService(this.systemVariables.isLowerCaseTableNames());
    // initialized the router cache and primary cache
    routerService = new RouteService(cacheService);
    sequenceHandler = initSequenceHandler(config.getSystem().getSequnceHandlerType());
    // XA Init recovery Log
    LOGGER.info("===============================================");
    LOGGER.info("Perform XA recovery log ...");
    performXARecoveryLog();
    // manager start
    manager.start();
    LOGGER.info(manager.getName() + " is started and listening on " + manager.getPort());
    server.start();
    // server started
    LOGGER.info(server.getName() + " is started and listening on " + server.getPort());
    LOGGER.info("===============================================");
    long dataNodeIdleCheckPeriod = system.getDataNodeIdleCheckPeriod();
    scheduler.scheduleAtFixedRate(updateTime(), 0L, TIME_UPDATE_PERIOD, TimeUnit.MILLISECONDS);
    scheduler.scheduleWithFixedDelay(processorCheck(), 0L, system.getProcessorCheckPeriod(), TimeUnit.MILLISECONDS);
    scheduler.scheduleAtFixedRate(dataNodeConHeartBeatCheck(dataNodeIdleCheckPeriod), 0L, dataNodeIdleCheckPeriod, TimeUnit.MILLISECONDS);
    // dataHost heartBeat  will be influence by dataHostWithoutWR
    scheduler.scheduleAtFixedRate(dataNodeHeartbeat(), 0L, system.getDataNodeHeartbeatPeriod(), TimeUnit.MILLISECONDS);
    scheduler.scheduleAtFixedRate(dataSourceOldConsClear(), 0L, DEFAULT_OLD_CONNECTION_CLEAR_PERIOD, TimeUnit.MILLISECONDS);
    scheduler.scheduleWithFixedDelay(xaSessionCheck(), 0L, system.getXaSessionCheckPeriod(), TimeUnit.MILLISECONDS);
    scheduler.scheduleWithFixedDelay(xaLogClean(), 0L, system.getXaLogCleanPeriod(), TimeUnit.MILLISECONDS);
    scheduler.scheduleWithFixedDelay(resultSetMapClear(), 0L, system.getClearBigSqLResultSetMapMs(), TimeUnit.MILLISECONDS);
    if (system.getUseSqlStat() == 1) {
        // sql record detail timing clean
        scheduler.scheduleWithFixedDelay(recycleSqlStat(), 0L, DEFAULT_SQL_STAT_RECYCLE_PERIOD, TimeUnit.MILLISECONDS);
    }
    if (system.getUseGlobleTableCheck() == 1) {
        // will be influence by dataHostWithoutWR
        scheduler.scheduleWithFixedDelay(globalTableConsistencyCheck(), 0L, system.getGlableTableCheckPeriod(), TimeUnit.MILLISECONDS);
    }
    scheduler.scheduleAtFixedRate(threadStatRenew(), 0L, 1, TimeUnit.SECONDS);
    if (isUseZkSwitch()) {
        initZkDnindex();
    }
}
Also used : SystemConfig(com.actiontech.dble.config.model.SystemConfig) ManagerConnectionFactory(com.actiontech.dble.manager.ManagerConnectionFactory) ServerConnectionFactory(com.actiontech.dble.server.ServerConnectionFactory) CacheService(com.actiontech.dble.cache.CacheService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DirectByteBufferPool(com.actiontech.dble.buffer.DirectByteBufferPool) RouteService(com.actiontech.dble.route.RouteService) TxnLogProcessor(com.actiontech.dble.log.transaction.TxnLogProcessor)

Aggregations

DirectByteBufferPool (com.actiontech.dble.buffer.DirectByteBufferPool)1 CacheService (com.actiontech.dble.cache.CacheService)1 SystemConfig (com.actiontech.dble.config.model.SystemConfig)1 TxnLogProcessor (com.actiontech.dble.log.transaction.TxnLogProcessor)1 ManagerConnectionFactory (com.actiontech.dble.manager.ManagerConnectionFactory)1 RouteService (com.actiontech.dble.route.RouteService)1 ServerConnectionFactory (com.actiontech.dble.server.ServerConnectionFactory)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1