/** * Returns printable state of the class. */ public String toString() { String resText = "Current safe block ratio = " + getSafeBlockRatio() + ". Target threshold = " + threshold + ". Minimal replication = " + safeReplication + "."; if (reached > 0) resText += " Threshold was reached " + new Date(reached) + "."; return resText; }
/** * 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."; }
/** * There is no need to enter safe mode * if DFS is empty or {@link #threshold} == 0 */ boolean needEnter() { return getSafeBlockRatio() < threshold; }