HDFS-9849. DiskBalancer: reduce lock path in shutdown code. Contributed by Yuanbo Liu.
This commit is contained in:
parent
35c5943b8b
commit
baab48922a
@ -121,17 +121,23 @@ public DiskBalancer(String dataNodeUUID,
|
|||||||
*/
|
*/
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
boolean needShutdown = false;
|
||||||
try {
|
try {
|
||||||
this.isDiskBalancerEnabled = false;
|
this.isDiskBalancerEnabled = false;
|
||||||
this.currentResult = Result.NO_PLAN;
|
this.currentResult = Result.NO_PLAN;
|
||||||
if ((this.future != null) && (!this.future.isDone())) {
|
if ((this.future != null) && (!this.future.isDone())) {
|
||||||
this.currentResult = Result.PLAN_CANCELLED;
|
this.currentResult = Result.PLAN_CANCELLED;
|
||||||
this.blockMover.setExitFlag();
|
this.blockMover.setExitFlag();
|
||||||
shutdownExecutor();
|
scheduler.shutdown();
|
||||||
|
needShutdown = true;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
// no need to hold lock while shutting down executor.
|
||||||
|
if (needShutdown) {
|
||||||
|
shutdownExecutor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +145,6 @@ public void shutdown() {
|
|||||||
*/
|
*/
|
||||||
private void shutdownExecutor() {
|
private void shutdownExecutor() {
|
||||||
final int secondsTowait = 10;
|
final int secondsTowait = 10;
|
||||||
scheduler.shutdown();
|
|
||||||
try {
|
try {
|
||||||
if (!scheduler.awaitTermination(secondsTowait, TimeUnit.SECONDS)) {
|
if (!scheduler.awaitTermination(secondsTowait, TimeUnit.SECONDS)) {
|
||||||
scheduler.shutdownNow();
|
scheduler.shutdownNow();
|
||||||
@ -228,6 +233,7 @@ public DiskBalancerWorkStatus queryWorkStatus() throws DiskBalancerException {
|
|||||||
*/
|
*/
|
||||||
public void cancelPlan(String planID) throws DiskBalancerException {
|
public void cancelPlan(String planID) throws DiskBalancerException {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
boolean needShutdown = false;
|
||||||
try {
|
try {
|
||||||
checkDiskBalancerEnabled();
|
checkDiskBalancerEnabled();
|
||||||
if (this.planID == null ||
|
if (this.planID == null ||
|
||||||
@ -239,13 +245,18 @@ public void cancelPlan(String planID) throws DiskBalancerException {
|
|||||||
DiskBalancerException.Result.NO_SUCH_PLAN);
|
DiskBalancerException.Result.NO_SUCH_PLAN);
|
||||||
}
|
}
|
||||||
if (!this.future.isDone()) {
|
if (!this.future.isDone()) {
|
||||||
this.blockMover.setExitFlag();
|
|
||||||
shutdownExecutor();
|
|
||||||
this.currentResult = Result.PLAN_CANCELLED;
|
this.currentResult = Result.PLAN_CANCELLED;
|
||||||
|
this.blockMover.setExitFlag();
|
||||||
|
scheduler.shutdown();
|
||||||
|
needShutdown = true;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
// no need to hold lock while shutting down executor.
|
||||||
|
if (needShutdown) {
|
||||||
|
shutdownExecutor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user