Cassandra source code analysis series startup module

Based on 3.11.4

The Cassandra startup process starts from the Cassandra script under bin. It involves some parameter settings of cassandra-env.sh for process startup, such as heap memory allocation, log parameter configuration, basic environment settings, etc. we can directly see the startup process, that is, the launch_service function, Then you can see the JAVA execution process of exec in it, that is, class (the classname passed in by the launch service parameter is org. Apache. Cassandra. Service. Cassandradamon class). The approximate process is as follows:

cassandra -> lauch_service -> JAVA start-up org.apache.cassandra.service.CassandraDaemon´╝Ť

The next step is to see the org.apache.cassandra.service.CassandraDaemon class, where you can directly find the starting entry through the main function:

  public static void main(String[] args)
    {
        instance.activate();
    }
    

There are three main functions to see in the active function:

        // Do not put any references to DatabaseDescriptor above the forceStaticInitialization call.
        try
        {
            applyConfig();

            MBeanWrapper.instance.registerMBean(new StandardMBean(new NativeAccess(), NativeAccessMBean.class), MBEAN_NAME, MBeanWrapper.OnException.LOG);

            if (FBUtilities.isWindows)
            {
                // We need to adjust the system timer on windows from the default 15ms down to the minimum of 1ms as this
                // impacts timer intervals, thread scheduling, driver interrupts, etc.
                WindowsTimer.startTimerPeriod(DatabaseDescriptor.getWindowsTimerInterval());
            }

            setup();

            String pidFile = System.getProperty("cassandra-pidfile");

            if (pidFile != null)
            {
                new File(pidFile).deleteOnExit();
            }

            start();

        }
        catch (Throwable e)
        {
            boolean logStackTrace =
            e instanceof ConfigurationException ? ((ConfigurationException)e).logStackTrace : true;

            System.out.println("Exception (" + e.getClass().getName() + ") encountered during startup: " + e.getMessage());

            if (logStackTrace)
            {
                if (runManaged)
                    logger.error("Exception encountered during startup", e);
                // try to warn user on stdout too, if we haven't already detached
                e.printStackTrace();
                exitOrFail(3, "Exception encountered during startup", e);
            }
            else
            {
                if (runManaged)
                    logger.error("Exception encountered during startup: {}", e.getMessage());
                // try to warn user on stdout too, if we haven't already detached
                System.err.println(e.getMessage());
                exitOrFail(3, "Exception encountered during startup: " + e.getMessage());
            }
        }
    

applyConfig(); It is mainly used to initialize the basic configuration in the cassandra.yaml configuration file. setup is mainly used to do some initialization work when a single node is initialized, such as load ing local sstable meta information to memory, clearing useless sstable files, starting without commit transaction execution or rollback, commitlog Start and playback of cluster meta information, validation of cluster meta information, startup of complex, launch of 7000 port internal communication server, etc;

The start function starts the 9042 client listening port, mainly the netty server. Of course, if it is thrift, it also starts the 9160 port service;

Tags: Operation & Maintenance Apache Java Windows Netty

Posted on Mon, 23 Mar 2020 11:46:37 -0400 by Kondie