hdfs datanode 启动流程中关于拉取namenode信
2021-08-31 本文已影响0人
邵红晓
hfds datanode 启动组件
hfds datanode 启动流程注册心跳
image.pngBPOfferService.java
/**
* Called by the BPServiceActors when they handshake to a NN.
* If this is the first NN connection, this sets the namespace info
* for this BPOfferService. If it's a connection to a new NN, it
* verifies that this namespace matches (eg to prevent a misconfiguration
* where a StandbyNode from a different cluster is specified)
*
* 两个namenode:
* hadoop1 -> actor1 => bpnsInfo
* hadoop2 -> actor2 => bpnsInfo
*
*/
void verifyAndSetNamespaceInfo(NamespaceInfo nsInfo) throws IOException {
writeLock();
try {
//actor1
//actor2
if (this.bpNSInfo == null) {
//赋值
this.bpNSInfo = nsInfo;
boolean success = false;
// Now that we know the namespace ID, etc, we can pass this to the DN.
// The DN can now initialize its local storage if we are the
// first BP to handshake, etc.
try {
dn.initBlockPool(this);
success = true;
} finally {
if (!success) {
// The datanode failed to initialize the BP. We need to reset
// the namespace info so that other BPService actors still have
// a chance to set it, and re-initialize the datanode.
this.bpNSInfo = null;
}
}
} else {
/**
* datanode注册的时候 就会通过namenode获取集群的一些信息
*/
//所以如果代码能走到这儿说明,我们的BlockPoolId肯定已经获取到了
checkNSEquality(bpNSInfo.getBlockPoolID(), nsInfo.getBlockPoolID(),
"Blockpool ID");
checkNSEquality(bpNSInfo.getNamespaceID(), nsInfo.getNamespaceID(),
"Namespace ID");
checkNSEquality(bpNSInfo.getClusterID(), nsInfo.getClusterID(),
"Cluster ID");
// //如果代码执行到这儿,说明不仅两个namenode上都获取到了信息,而且两个namenode的信息都对上了。
// if(blockPoolID == null){
// this.blockPoolID = bpNSInfo.getBlockPoolID();
// }
}
} finally {
writeUnlock();
}
}
总结
可以发现,datanode通过BPServiceActors和namenode建立连接,并初始化过程中会校验Blockpool ID,Namespace ID,Cluster ID,这几个至关重要,为下文恢复集群做准备。