this.snapshotManager = new SnapshotManager(dir); this.cacheManager = new CacheManager(this, conf, blockManager); this.safeMode = new SafeModeInfo(conf); this.topConf = new TopConf(conf); this.auditLoggers = initAuditLoggers(conf);
/** * Enter safe mode manually. * @throws IOException */ synchronized void enterSafeMode() throws IOException { if (!isInSafeMode()) { safeMode = new SafeModeInfo(); return; } safeMode.setManual(); NameNode.stateChangeLog.info("STATE* Safe mode is ON. " + safeMode.getTurnOffTip()); }
if(!isOn()) { return "Safe mode is OFF."; if (areResourcesLow()) { adminMsg = "Resources are low on NN. Please add or free up more " + "resources then turn off safe mode manually. NOTE: If you turn off" + "the NN will immediately return to safe mode. "; if (isManual() || areResourcesLow()) { return adminMsg + "Use \"hdfs dfsadmin -safemode leave\" to turn safe mode off.";
this.snapshotManager = new SnapshotManager(dir); this.cacheManager = new CacheManager(this, conf, blockManager); this.safeMode = new SafeModeInfo(conf); this.topConf = new TopConf(conf); this.auditLoggers = initAuditLoggers(conf);
NameNode.getNameNodeMetrics().fsImageLoadTime.set( (int) timeTakenToLoadFSImage); this.safeMode = new SafeModeInfo(conf); setBlockTotal(); pendingReplications = new PendingReplicationBlocks(
if(!isOn()) { return "Safe mode is OFF."; if (areResourcesLow()) { adminMsg = "Resources are low on NN. Please add or free up more " + "resources then turn off safe mode manually. NOTE: If you turn off" + "the NN will immediately return to safe mode. "; if (isManual() || areResourcesLow()) { return adminMsg + "Use \"hdfs dfsadmin -safemode leave\" to turn safe mode off.";
if (smmthread == null && needEnter()) { enter(); if (canInitializeReplQueues() && !isPopulatingReplQueues() && !haEnabled) { initializeReplQueues(); reportStatus("STATE* Safe mode ON.", false); return; if (!isOn() || // safe mode is off extension <= 0 || threshold <= 0) { // don't need to wait this.leave(); // leave safe mode return; reportStatus("STATE* Safe mode ON.", false); return; smmthread = new Daemon(new SafeModeMonitor()); smmthread.start(); reportStatus("STATE* Safe mode extension entered.", true); if (canInitializeReplQueues() && !isPopulatingReplQueues() && !haEnabled) { initializeReplQueues();
if (smmthread == null && needEnter()) { enter(); if (canInitializeReplQueues() && !isPopulatingReplQueues() && !haEnabled) { initializeReplQueues(); reportStatus("STATE* Safe mode ON.", false); return; if (!isOn() || // safe mode is off extension <= 0 || threshold <= 0) { // don't need to wait this.leave(); // leave safe mode return; reportStatus("STATE* Safe mode ON.", false); return; smmthread = new Daemon(new SafeModeMonitor()); smmthread.start(); reportStatus("STATE* Safe mode extension entered.", true); if (canInitializeReplQueues() && !isPopulatingReplQueues() && !haEnabled) { initializeReplQueues();
safeMode = new SafeModeInfo(); return;
safeMode = new SafeModeInfo(resourcesLow); return; + safeMode.getTurnOffTip()); } finally { writeUnlock("enterSafeMode");
safeMode = new SafeModeInfo(resourcesLow); return; + safeMode.getTurnOffTip()); } finally { writeUnlock("enterSafeMode");
/** * A tip on how safe mode is to be turned off: manually or automatically. */ String getTurnOffTip() { String leaveMsg = "Safe mode will be turned off automatically"; if(reached < 0) return "Safe mode is OFF."; if(isManual()) { if(getDistributedUpgradeState()) return leaveMsg + " upon completion of " + "the distributed upgrade: upgrade progress = " + getDistributedUpgradeStatus() + "%"; leaveMsg = "Use \"hadoop dfs -safemode leave\" to turn safe mode off"; } if(blockTotal < 0) return leaveMsg + "."; String safeBlockRatioMsg = String.format("The ratio of reported blocks %.4f has " + (reached == 0 ? "not " : "") + "reached the threshold %.4f. ", getSafeBlockRatio(), threshold) + leaveMsg; if(reached == 0 || isManual()) // threshold is not reached or manual return safeBlockRatioMsg + "."; // extension period is in progress return safeBlockRatioMsg + " in " + Math.abs(reached + extension - now())/1000 + " seconds."; }
/** * Check and trigger safe mode if needed. */ private void checkMode() { if (needEnter()) { enter(); reportStatus("STATE* Safe mode ON.", false); return; } // the threshold is reached if (!isOn() || // safe mode is off extension <= 0 || threshold <= 0) { // don't need to wait this.leave(true); // leave safe mode return; } if (reached > 0) { // threshold has already been reached before reportStatus("STATE* Safe mode ON.", false); return; } // start monitor reached = now(); smmthread = new Daemon(new SafeModeMonitor()); smmthread.start(); reportStatus("STATE* Safe mode extension entered.", true); }
/** * Creates SafeModeInfo when safe mode is entered manually, or because * available resources are low. * * The {@link #threshold} is set to 1.5 so that it could never be reached. * {@link #blockTotal} is set to -1 to indicate that safe mode is manual. * * @see SafeModeInfo */ private SafeModeInfo(boolean resourcesLow) { this.threshold = 1.5f; // this threshold can never be reached this.datanodeThreshold = Integer.MAX_VALUE; this.extension = Integer.MAX_VALUE; this.safeReplication = Short.MAX_VALUE + 1; // more than maxReplication this.replQueueThreshold = 1.5f; // can never be reached this.blockTotal = -1; this.blockSafe = -1; this.resourcesLow = resourcesLow; enter(); reportStatus("STATE* Safe mode is ON.", true); }
/** * Creates SafeModeInfo when safe mode is entered manually, or because * available resources are low. * * The {@link #threshold} is set to 1.5 so that it could never be reached. * {@link #blockTotal} is set to -1 to indicate that safe mode is manual. * * @see SafeModeInfo */ private SafeModeInfo(boolean resourcesLow) { this.threshold = 1.5f; // this threshold can never be reached this.datanodeThreshold = Integer.MAX_VALUE; this.extension = Integer.MAX_VALUE; this.safeReplication = Short.MAX_VALUE + 1; // more than maxReplication this.replQueueThreshold = 1.5f; // can never be reached this.blockTotal = -1; this.blockSafe = -1; this.resourcesLow = resourcesLow; enter(); reportStatus("STATE* Safe mode is ON.", true); }
/** * Increment number of safe blocks if current block has * reached minimal replication. * @param replication current replication */ private synchronized void incrementSafeBlockCount(short replication) { if (replication == safeReplication) { this.blockSafe++; // Report startup progress only if we haven't completed startup yet. StartupProgress prog = NameNode.getStartupProgress(); if (prog.getStatus(Phase.SAFEMODE) != Status.COMPLETE) { if (this.awaitingReportedBlocksCounter == null) { this.awaitingReportedBlocksCounter = prog.getCounter(Phase.SAFEMODE, STEP_AWAITING_REPORTED_BLOCKS); } this.awaitingReportedBlocksCounter.increment(); } checkMode(); } }
/** * Increment number of safe blocks if current block has * reached minimal replication. * @param replication current replication */ private synchronized void incrementSafeBlockCount(short replication) { if (replication == safeReplication) { this.blockSafe++; // Report startup progress only if we haven't completed startup yet. StartupProgress prog = NameNode.getStartupProgress(); if (prog.getStatus(Phase.SAFEMODE) != Status.COMPLETE) { if (this.awaitingReportedBlocksCounter == null) { this.awaitingReportedBlocksCounter = prog.getCounter(Phase.SAFEMODE, STEP_AWAITING_REPORTED_BLOCKS); } this.awaitingReportedBlocksCounter.increment(); } checkMode(); } }
/** * Safe mode can be turned off iff * the threshold is reached and * the extension time have passed. * @return true if can leave or false otherwise. */ private synchronized boolean canLeave() { if (reached == 0) { return false; } if (monotonicNow() - reached < extension) { reportStatus("STATE* Safe mode ON, in safe mode extension.", false); return false; } if (needEnter()) { reportStatus("STATE* Safe mode ON, thresholds not met.", false); return false; } return true; }
/** * Safe mode can be turned off iff * the threshold is reached and * the extension time have passed. * @return true if can leave or false otherwise. */ private synchronized boolean canLeave() { if (reached == 0) { return false; } if (monotonicNow() - reached < extension) { reportStatus("STATE* Safe mode ON, in safe mode extension.", false); return false; } if (needEnter()) { reportStatus("STATE* Safe mode ON, thresholds not met.", false); return false; } return true; }
/** * Set total number of blocks. */ private synchronized void setBlockTotal(int total) { this.blockTotal = total; this.blockThreshold = (int) (blockTotal * threshold); this.blockReplQueueThreshold = (int) (blockTotal * replQueueThreshold); if (haEnabled) { // After we initialize the block count, any further namespace // modifications done while in safe mode need to keep track // of the number of total blocks in the system. this.shouldIncrementallyTrackBlocks = true; } if(blockSafe < 0) this.blockSafe = 0; checkMode(); }