|
@@ -482,7 +482,10 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
private HAContext haContext;
|
|
|
|
|
|
private final boolean haEnabled;
|
|
|
-
|
|
|
+
|
|
|
+ /** flag indicating whether replication queues have been initialized */
|
|
|
+ boolean initializedReplQueues = false;
|
|
|
+
|
|
|
/**
|
|
|
* Whether the namenode is in the middle of starting the active service
|
|
|
*/
|
|
@@ -914,8 +917,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
try {
|
|
|
nnResourceChecker = new NameNodeResourceChecker(conf);
|
|
|
checkAvailableResources();
|
|
|
- assert safeMode != null &&
|
|
|
- !safeMode.isPopulatingReplQueues();
|
|
|
+ assert safeMode != null && !isPopulatingReplQueues();
|
|
|
StartupProgress prog = NameNode.getStartupProgress();
|
|
|
prog.beginPhase(Phase.SAFEMODE);
|
|
|
prog.setTotal(Phase.SAFEMODE, STEP_AWAITING_REPORTED_BLOCKS,
|
|
@@ -971,12 +973,12 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
blockManager.clearQueues();
|
|
|
blockManager.processAllPendingDNMessages();
|
|
|
|
|
|
- if (!isInSafeMode() ||
|
|
|
- (isInSafeMode() && safeMode.isPopulatingReplQueues())) {
|
|
|
+ // Only need to re-process the queue, If not in SafeMode.
|
|
|
+ if (!isInSafeMode()) {
|
|
|
LOG.info("Reprocessing replication and invalidation queues");
|
|
|
- blockManager.processMisReplicatedBlocks();
|
|
|
+ initializeReplQueues();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.debug("NameNode metadata after re-processing " +
|
|
|
"replication and invalidation queues during failover:\n" +
|
|
@@ -1015,7 +1017,16 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
startingActiveService = false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initialize replication queues.
|
|
|
+ */
|
|
|
+ private void initializeReplQueues() {
|
|
|
+ LOG.info("initializing replication queues");
|
|
|
+ blockManager.processMisReplicatedBlocks();
|
|
|
+ initializedReplQueues = true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return Whether the namenode is transitioning to active state and is in the
|
|
|
* middle of the {@link #startActiveServices()}
|
|
@@ -1061,6 +1072,9 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
cacheManager.deactivate();
|
|
|
blockManager.getDatanodeManager().setShouldSendCachingCommands(false);
|
|
|
+ // Don't want to keep replication queues when not in Active.
|
|
|
+ blockManager.clearQueues();
|
|
|
+ initializedReplQueues = false;
|
|
|
} finally {
|
|
|
writeUnlock();
|
|
|
}
|
|
@@ -4548,7 +4562,6 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
private int safeReplication;
|
|
|
/** threshold for populating needed replication queues */
|
|
|
private double replQueueThreshold;
|
|
|
-
|
|
|
// internal fields
|
|
|
/** Time when threshold was reached.
|
|
|
* <br> -1 safe mode is off
|
|
@@ -4566,8 +4579,6 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
private int blockReplQueueThreshold;
|
|
|
/** time of the last status printout */
|
|
|
private long lastStatusReport = 0;
|
|
|
- /** flag indicating whether replication queues have been initialized */
|
|
|
- boolean initializedReplQueues = false;
|
|
|
/** Was safemode entered automatically because available resources were low. */
|
|
|
private boolean resourcesLow = false;
|
|
|
/** Should safemode adjust its block totals as blocks come in */
|
|
@@ -4627,7 +4638,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
*
|
|
|
* @see SafeModeInfo
|
|
|
*/
|
|
|
- private SafeModeInfo(boolean resourcesLow, boolean isReplQueuesInited) {
|
|
|
+ private SafeModeInfo(boolean resourcesLow) {
|
|
|
this.threshold = 1.5f; // this threshold can never be reached
|
|
|
this.datanodeThreshold = Integer.MAX_VALUE;
|
|
|
this.extension = Integer.MAX_VALUE;
|
|
@@ -4636,7 +4647,6 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
this.blockTotal = -1;
|
|
|
this.blockSafe = -1;
|
|
|
this.resourcesLow = resourcesLow;
|
|
|
- this.initializedReplQueues = isReplQueuesInited;
|
|
|
enter();
|
|
|
reportStatus("STATE* Safe mode is ON.", true);
|
|
|
}
|
|
@@ -4650,13 +4660,6 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
return this.reached >= 0;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Check if we are populating replication queues.
|
|
|
- */
|
|
|
- private synchronized boolean isPopulatingReplQueues() {
|
|
|
- return initializedReplQueues;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Enter safe mode.
|
|
|
*/
|
|
@@ -4703,21 +4706,6 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Initialize replication queues.
|
|
|
- */
|
|
|
- private synchronized void initializeReplQueues() {
|
|
|
- LOG.info("initializing replication queues");
|
|
|
- assert !isPopulatingReplQueues() : "Already initialized repl queues";
|
|
|
- long startTimeMisReplicatedScan = now();
|
|
|
- blockManager.processMisReplicatedBlocks();
|
|
|
- initializedReplQueues = true;
|
|
|
- NameNode.stateChangeLog.info("STATE* Replication Queue initialization "
|
|
|
- + "scan for invalid, over- and under-replicated blocks "
|
|
|
- + "completed in " + (now() - startTimeMisReplicatedScan)
|
|
|
- + " msec");
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Check whether we have reached the threshold for
|
|
|
* initializing replication queues.
|
|
@@ -4765,7 +4753,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (smmthread == null && needEnter()) {
|
|
|
enter();
|
|
|
// check if we are ready to initialize replication queues
|
|
|
- if (canInitializeReplQueues() && !isPopulatingReplQueues()) {
|
|
|
+ if (canInitializeReplQueues() && !isPopulatingReplQueues()
|
|
|
+ && !haEnabled) {
|
|
|
initializeReplQueues();
|
|
|
}
|
|
|
reportStatus("STATE* Safe mode ON.", false);
|
|
@@ -4790,7 +4779,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
|
|
|
// check if we are ready to initialize replication queues
|
|
|
- if (canInitializeReplQueues() && !isPopulatingReplQueues()) {
|
|
|
+ if (canInitializeReplQueues() && !isPopulatingReplQueues() && !haEnabled) {
|
|
|
initializeReplQueues();
|
|
|
}
|
|
|
}
|
|
@@ -5100,11 +5089,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (!shouldPopulateReplQueues()) {
|
|
|
return false;
|
|
|
}
|
|
|
- // safeMode is volatile, and may be set to null at any time
|
|
|
- SafeModeInfo safeMode = this.safeMode;
|
|
|
- if (safeMode == null)
|
|
|
- return true;
|
|
|
- return safeMode.isPopulatingReplQueues();
|
|
|
+ return initializedReplQueues;
|
|
|
}
|
|
|
|
|
|
private boolean shouldPopulateReplQueues() {
|
|
@@ -5224,7 +5209,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSyncAll();
|
|
|
}
|
|
|
if (!isInSafeMode()) {
|
|
|
- safeMode = new SafeModeInfo(resourcesLow, isPopulatingReplQueues());
|
|
|
+ safeMode = new SafeModeInfo(resourcesLow);
|
|
|
return;
|
|
|
}
|
|
|
if (resourcesLow) {
|