HDFS-13721. NPE in DataNode due to uninitialized DiskBalancer.
This commit is contained in:
parent
ba6b48e19f
commit
7d1e2e1fbb
|
@ -3135,7 +3135,7 @@ public class DataNode extends ReconfigurableBase
|
||||||
@Override // DataNodeMXBean
|
@Override // DataNodeMXBean
|
||||||
public String getDiskBalancerStatus() {
|
public String getDiskBalancerStatus() {
|
||||||
try {
|
try {
|
||||||
return this.diskBalancer.queryWorkStatus().toJsonString();
|
return getDiskBalancer().queryWorkStatus().toJsonString();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.debug("Reading diskbalancer Status failed. ex:{}", ex);
|
LOG.debug("Reading diskbalancer Status failed. ex:{}", ex);
|
||||||
return "";
|
return "";
|
||||||
|
@ -3513,7 +3513,7 @@ public class DataNode extends ReconfigurableBase
|
||||||
DiskBalancerException.Result.DATANODE_STATUS_NOT_REGULAR);
|
DiskBalancerException.Result.DATANODE_STATUS_NOT_REGULAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.diskBalancer.submitPlan(planID, planVersion, planFile, planData,
|
getDiskBalancer().submitPlan(planID, planVersion, planFile, planData,
|
||||||
skipDateCheck);
|
skipDateCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3525,7 +3525,7 @@ public class DataNode extends ReconfigurableBase
|
||||||
public void cancelDiskBalancePlan(String planID) throws
|
public void cancelDiskBalancePlan(String planID) throws
|
||||||
IOException {
|
IOException {
|
||||||
checkSuperuserPrivilege();
|
checkSuperuserPrivilege();
|
||||||
this.diskBalancer.cancelPlan(planID);
|
getDiskBalancer().cancelPlan(planID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3536,7 +3536,7 @@ public class DataNode extends ReconfigurableBase
|
||||||
@Override
|
@Override
|
||||||
public DiskBalancerWorkStatus queryDiskBalancerPlan() throws IOException {
|
public DiskBalancerWorkStatus queryDiskBalancerPlan() throws IOException {
|
||||||
checkSuperuserPrivilege();
|
checkSuperuserPrivilege();
|
||||||
return this.diskBalancer.queryWorkStatus();
|
return getDiskBalancer().queryWorkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3553,9 +3553,9 @@ public class DataNode extends ReconfigurableBase
|
||||||
Preconditions.checkNotNull(key);
|
Preconditions.checkNotNull(key);
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case DiskBalancerConstants.DISKBALANCER_VOLUME_NAME:
|
case DiskBalancerConstants.DISKBALANCER_VOLUME_NAME:
|
||||||
return this.diskBalancer.getVolumeNames();
|
return getDiskBalancer().getVolumeNames();
|
||||||
case DiskBalancerConstants.DISKBALANCER_BANDWIDTH :
|
case DiskBalancerConstants.DISKBALANCER_BANDWIDTH :
|
||||||
return Long.toString(this.diskBalancer.getBandwidth());
|
return Long.toString(getDiskBalancer().getBandwidth());
|
||||||
default:
|
default:
|
||||||
LOG.error("Disk Balancer - Unknown key in get balancer setting. Key: {}",
|
LOG.error("Disk Balancer - Unknown key in get balancer setting. Key: {}",
|
||||||
key);
|
key);
|
||||||
|
@ -3609,4 +3609,11 @@ public class DataNode extends ReconfigurableBase
|
||||||
}
|
}
|
||||||
return volumeInfoList;
|
return volumeInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DiskBalancer getDiskBalancer() throws IOException {
|
||||||
|
if (this.diskBalancer == null) {
|
||||||
|
throw new IOException("DiskBalancer is not initialized");
|
||||||
|
}
|
||||||
|
return this.diskBalancer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,11 @@ public class TestDiskBalancer {
|
||||||
.getFsVolumeReferences()) {
|
.getFsVolumeReferences()) {
|
||||||
assertEquals(ref.size(), dbDnNode.getVolumeCount());
|
assertEquals(ref.size(), dbDnNode.getVolumeCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown the DN first, to verify that calling diskbalancer APIs on
|
||||||
|
// uninitialized DN doesn't NPE
|
||||||
|
dnNode.shutdown();
|
||||||
|
assertEquals("", dnNode.getDiskBalancerStatus());
|
||||||
} finally {
|
} finally {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue