本章我们先来看看单机服务端处理流程,最后再去学习集群模式
1、服务启动
服务端入口类为QuorumPeerMain,下面为启动流程
1、main.initializeAndRun(args);
2、initializeAndRun(){
if (args.length == 1 && config.isDistributed()) {
runFromConfig(config);
} else {
LOG.warn("Either no config or no quorum defined in config, running in standalone mode");
// there is only server in the quorum -- run as standalone
ZooKeeperServerMain.main(args);
}
}
3、zookeeperserverMain.runFromConfig{
//log与快照类
txnLog = new FileTxnSnapLog(config.dataLogDir, config.dataDir);
//zkserver配置
ZooKeeperServer zkServer = new ZooKeeperServer();
//NIO服务器
cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(),