datanode启动源码分析

This commit is contained in:
LingZhaoHui 2023-11-06 23:33:31 +08:00
parent 68d6e12c3b
commit c902466842
Signed by: zeekling
GPG Key ID: D96E4E75267CA2CC

View File

@ -126,6 +126,7 @@ private void doRefreshNamenodes(
// Step 1. For each of the new nameservices, figure out whether
// it's an update of the set of NNs for an existing NS,
// or an entirely new nameservice.
// 判断当前DN中的nameservice是否已经存在如果已经存在则需要刷新否则需要添加。
for (String nameserviceId : addrMap.keySet()) {
if (bpByNameserviceId.containsKey(nameserviceId)) {
toRefresh.add(nameserviceId);
@ -136,20 +137,12 @@ private void doRefreshNamenodes(
// Step 2. Any nameservices we currently have but are no longer present
// need to be removed.
// 计算当前DN需要删除的nameservice
toRemove = Sets.newHashSet(Sets.difference(
bpByNameserviceId.keySet(), addrMap.keySet()));
assert toRefresh.size() + toAdd.size() ==
addrMap.size() :
"toAdd: " + Joiner.on(",").useForNull("<default>").join(toAdd) +
" toRemove: " + Joiner.on(",").useForNull("<default>").join(toRemove) +
" toRefresh: " + Joiner.on(",").useForNull("<default>").join(toRefresh);
// Step 3. Start new nameservices
// Step 3. 启动新的nameservice
if (!toAdd.isEmpty()) {
LOG.info("Starting BPOfferServices for nameservices: " +
Joiner.on(",").useForNull("<default>").join(toAdd));
for (String nsToAdd : toAdd) {
Map<String, InetSocketAddress> nnIdToAddr = addrMap.get(nsToAdd);
@ -176,12 +169,10 @@ private void doRefreshNamenodes(
startAll();
}
// Step 4. Shut down old nameservices. This happens outside
// Step 4. 停止掉老的nameservice. This happens outside
// of the synchronized(this) lock since they need to call
// back to .remove() from another thread
if (!toRemove.isEmpty()) {
LOG.info("Stopping BPOfferServices for nameservices: " +
Joiner.on(",").useForNull("<default>").join(toRemove));
for (String nsToRemove : toRemove) {
BPOfferService bpos = bpByNameserviceId.get(nsToRemove);
@ -192,9 +183,8 @@ private void doRefreshNamenodes(
}
// Step 5. Update nameservices whose NN list has changed
// 更新nameservices
if (!toRefresh.isEmpty()) {
LOG.info("Refreshing list of NNs for nameservices: " +
Joiner.on(",").useForNull("<default>").join(toRefresh));
for (String nsToRefresh : toRefresh) {
BPOfferService bpos = bpByNameserviceId.get(nsToRefresh);
@ -218,6 +208,7 @@ private void doRefreshNamenodes(
.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
// 刷新NNList 核心实现.
bpos.refreshNNList(nsToRefresh, nnIds, addrs, lifelineAddrs);
return null;
}