NameNode启动流程分析
public staticvoid main(Stringargv[]) throws Exception {
if (DFSUtil.parseHelpArgument(argv, NameNode.USAGE, System.out,true)) {
System.exit(0);
}
try {
StringUtils.startupShutdownMessage(NameNode.class,argv, LOG);
//创建NameNode实例
NameNodenamenode = createNameNode(argv,null);
if (namenode !=null) {
namenode.join();
}
} catch (Throwable e) {
LOG.error("Failed to start namenode.",e);
terminate(1, e);
}
}
调用NameNode方法:
publicstatic NameNode createNameNode(Stringargv[], Configuration conf)
throws IOException {
LOG.info("createNameNode " + Arrays.asList(argv));
//加载HDFS配置文件
if (conf ==null)
conf = new HdfsConfiguration();
//解析传递的参数
StartupOptionstartOpt =parseArguments(argv);
if (startOpt ==null) {
printUsage(System.err);
return null;
}
setStartupOption(conf, startOpt);
//对参数进行判断,然后进行不同处理
switch (startOpt) {
case FORMAT: {
boolean aborted = format(conf, startOpt.getForceFormat(),
startOpt.getInteractiveFormat());
terminate(aborted ? 1 : 0);
return null;// avoidjavac warning
}
case GENCLUSTERID: {
System.err.println("Generating new cluster id:");
System.out.println(NNStorage.newClusterID());
terminate(0);
return null;
}
case FINALIZE: {
System.err.println("Use of the argument '" + StartupOption.FINALIZE +
"' is no longer supported. To finalizean upgrade, start the NN " +
" and then run `hdfs dfsadmin-finalizeUpgrade'");
terminate(1);
return null;// avoidjavac warning
}
case ROLLBACK: {
boolean aborted = doRollback(conf, true);
terminate(aborted ? 1 : 0);
return null;// avoidwarning
}
case BOOTSTRAPSTANDBY: {
StringtoolArgs[] = Arrays.copyOfRange(argv, 1,argv.length);
int rc = BootstrapStandby.run(toolArgs,conf);
terminate(rc);
return null;// avoidwarning
}
case INITIALIZESHAREDEDITS: {
boolean aborted = initializeSharedEdits(conf,
startOpt.getForceFormat(),
startOpt.getInteractiveFormat());
terminate(aborted ? 1 : 0);
return null;// avoidwarning
}
case BACKUP:
case CHECKPOINT: {
NamenodeRolerole = startOpt.toNodeRole();
DefaultMetricsSystem.initialize(role.toString().replace(" ",""));
return new BackupNode(conf,role);
}
case RECOVER: {
NameNode.doRecovery(startOpt,conf);
return null;
}
case METADATAVERSION: {
printMetadataVersion(conf);
terminate(0);
return null;// avoidjavac warning
}
case UPGRADEONLY: {
DefaultMetricsSystem.initialize("NameNode");
new NameNode(conf);
terminate(0);
return null;
}
default: {
DefaultMetricsSystem.initialize("NameNode");
return new NameNode(conf);
}
}
项目启动会流程。 }
参数是format:
从配置文件获取NameNodeNameServicesId
启动会启动仪式,获取所有的NameNode的id
进行初始化工作
>>登陆使用dfs.namenode.kerberos.principal作为用户名,否则使用当前linux的user作为用户。
>>如果当前NameNode角色是NameNode,则启动HttpServer,如果NameNode是backup NameNode或者是CheckPoint NameNode则略过这个步骤
privatevoid startHttpServer(final Configurationconf) throws IOException {
//创建NameNode HttpServer
httpServer =new NameNodeHttpServer(conf,this, getHttpServerBindAddress(conf));
//启动http server
httpServer.start();
httpServer.setStartupProgress(startupProgress);
公司年度启动会流程、 }
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态