HDFS-16082. Atomic operations on exceptionsSinceLastBalance and failedTimesSinceLastSuccessfulBalance in Balancer (#3127)
This commit is contained in:
parent
10b79a26fe
commit
d9fbb3c508
|
@ -37,6 +37,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting;
|
import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -211,8 +212,10 @@ public class Balancer {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
private static volatile boolean serviceRunning = false;
|
private static volatile boolean serviceRunning = false;
|
||||||
|
|
||||||
private static volatile int exceptionsSinceLastBalance = 0;
|
private static final AtomicInteger EXCEPTIONS_SINCE_LAST_BALANCE =
|
||||||
private static volatile int failedTimesSinceLastSuccessfulBalance = 0;
|
new AtomicInteger(0);
|
||||||
|
private static final AtomicInteger
|
||||||
|
FAILED_TIMES_SINCE_LAST_SUCCESSFUL_BALANCE = new AtomicInteger(0);
|
||||||
|
|
||||||
private final Dispatcher dispatcher;
|
private final Dispatcher dispatcher;
|
||||||
private final NameNodeConnector nnc;
|
private final NameNodeConnector nnc;
|
||||||
|
@ -274,11 +277,11 @@ public class Balancer {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getExceptionsSinceLastBalance() {
|
static int getExceptionsSinceLastBalance() {
|
||||||
return exceptionsSinceLastBalance;
|
return EXCEPTIONS_SINCE_LAST_BALANCE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getFailedTimesSinceLastSuccessfulBalance() {
|
static int getFailedTimesSinceLastSuccessfulBalance() {
|
||||||
return failedTimesSinceLastSuccessfulBalance;
|
return FAILED_TIMES_SINCE_LAST_SUCCESSFUL_BALANCE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -866,20 +869,21 @@ public class Balancer {
|
||||||
int retCode = doBalance(namenodes, nsIds, p, conf);
|
int retCode = doBalance(namenodes, nsIds, p, conf);
|
||||||
if (retCode < 0) {
|
if (retCode < 0) {
|
||||||
LOG.info("Balance failed, error code: " + retCode);
|
LOG.info("Balance failed, error code: " + retCode);
|
||||||
failedTimesSinceLastSuccessfulBalance++;
|
FAILED_TIMES_SINCE_LAST_SUCCESSFUL_BALANCE.incrementAndGet();
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Balance succeed!");
|
LOG.info("Balance succeed!");
|
||||||
failedTimesSinceLastSuccessfulBalance = 0;
|
FAILED_TIMES_SINCE_LAST_SUCCESSFUL_BALANCE.set(0);
|
||||||
}
|
}
|
||||||
exceptionsSinceLastBalance = 0;
|
EXCEPTIONS_SINCE_LAST_BALANCE.set(0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (++exceptionsSinceLastBalance > retryOnException) {
|
if (EXCEPTIONS_SINCE_LAST_BALANCE.incrementAndGet()
|
||||||
|
> retryOnException) {
|
||||||
// The caller will process and log the exception
|
// The caller will process and log the exception
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
LOG.warn(
|
LOG.warn(
|
||||||
"Encounter exception while do balance work. Already tried {} times",
|
"Encounter exception while do balance work. Already tried {} times",
|
||||||
exceptionsSinceLastBalance, e);
|
EXCEPTIONS_SINCE_LAST_BALANCE, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sleep for next round, will retry for next round when it's interrupted
|
// sleep for next round, will retry for next round when it's interrupted
|
||||||
|
|
Loading…
Reference in New Issue