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