force non leader NN to call safeMode.leave
import static io.hops.transaction.lock.LockFactory.getInstance;
import io.hops.transaction.lock.TransactionLockTypes;
import io.hops.util.Slicer;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries;
@@ -439,6 +440,8 @@ private void logAuditEvent(boolean succeeded, UserGroupInformation ugi,
private final boolean supportAppends;
private final ReplaceDatanodeOnFailure dtpReplaceDatanodeOnFailure;
+ private AtomicBoolean inSafeMode = new AtomicBoolean(false); // safe mode information
+
private final long maxFsObjects; // maximum number of fs objects
private final long minBlockSize; // minimum block size
@@ -843,6 +846,7 @@ void startCommonServices(Configuration conf) throws IOException {
RootINodeCache.start();
if (isLeader()) {
HdfsVariables.setSafeModeInfo(new SafeModeInfo(conf), -1);
+ inSafeMode.set(true);
assert safeMode() != null && !isPopulatingReplQueues();
StartupProgress prog = NameNode.getStartupProgress();
prog.beginPhase(Phase.SAFEMODE);
@@ -5033,6 +5037,8 @@ private SafeModeInfo(double threshold, int datanodeThreshold, int extension, int
this.resourcesLow = resourcesLow;
}
+ private SafeModeInfo(){};
+
public double getThreshold() {
return threshold;
}
@@ -5092,6 +5098,9 @@ private void enter() throws IOException {
* startup.
*/
private void leave() throws IOException {
+ if(!inSafeMode.getAndSet(false)){
+ return;
+ }
// if not done yet, initialize replication queues.
// In the standby, do not populate replication queues
if (!isPopulatingReplQueues() && shouldPopulateReplicationQueues()) {
@@ -5644,11 +5653,15 @@ public boolean isInSafeMode() throws IOException {
// safeMode is volatile, and may be set to null at any time
SafeModeInfo safeMode = safeMode();
if (safeMode == null) {
+ if(inSafeMode.get()){
+ new SafeModeInfo().leave();
+ }
return false;
}
if(safeMode.isOn() && !isLeader()){
safeMode.tryToHelpToGetOut();
}
+ inSafeMode.set(safeMode.isOn());
return safeMode.isOn();
}
@@ -5847,13 +5860,14 @@ public Object performTask() throws IOException {
* @throws IOException
*/
void enterSafeMode(boolean resourcesLow) throws IOException {
+ stopSecretManager();
+ shouldPopulateReplicationQueue = true;
+ inSafeMode.set(true);
+
if(!isLeader()){
return;
}
- // Stop the secret manager, since rolling the master key would
- // try to write to the edit log
- stopSecretManager();
- shouldPopulateReplicationQueue = true;
+
SafeModeInfo safeMode = safeMode();
if (safeMode != null) {
if (resourcesLow) {
