// QuorumPeerMainprotectedvoidinitializeAndRun(String[] args)throwsConfigException,IOException,AdminServerException{
// 1. args[0]代表配置文件的路径,读取配置文件,加载到QuorumPeerConfig中QuorumPeerConfig config =newQuorumPeerConfig();if(args.length ==1){
config.parse(args[0]);}// Start and schedule the the purge task// 2. 启动清理任务DatadirCleanupManager purgeMgr =newDatadirCleanupManager(config
.getDataDir(), config.getDataLogDir(), config
.getSnapRetainCount(), config.getPurgeInterval());
purgeMgr.start();// 3. 判断是否是集群模式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// 当前只有一个节点,切换到standalone模式// 单机模式运行ZooKeeperServerMain.main(args);}}