BlockManagerSafeMode { void checkSafeMode() { assert namesystem.hasWriteLock(); if (namesystem.inTransitionToActive()) { return; } switch (status) { case PENDING_THRESHOLD: if (areThresholdsMet()) { if (extension > 0) { status = BMSafeModeStatus.EXTENSION; reachedTime.set(monotonicNow()); smmthread.start(); initializeReplQueuesIfNecessary(); reportStatus("STATE* Safe mode extension entered.", true); } else { leaveSafeMode(false); } } else { initializeReplQueuesIfNecessary(); reportStatus("STATE* Safe mode ON.", false); } break; case EXTENSION: reportStatus("STATE* Safe mode ON.", false); break; case OFF: break; default: assert false : "Non-recognized block manager safe mode status: " + status; } } BlockManagerSafeMode(BlockManager blockManager, Namesystem namesystem,
      Configuration conf);   }
@Test(timeout = 30000) public void testCheckSafeMode() { bmSafeMode.activate(BLOCK_TOTAL); setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD); for (long i = 0; i < BLOCK_THRESHOLD; i++) { setBlockSafe(i); bmSafeMode.checkSafeMode(); assertEquals(BMSafeModeStatus.PENDING_THRESHOLD, getSafeModeStatus()); } setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD); setBlockSafe(BLOCK_THRESHOLD); bmSafeMode.checkSafeMode(); assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus()); Whitebox.setInternalState(bmSafeMode, "smmthread", null); setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD); setBlockSafe(BLOCK_THRESHOLD); Whitebox.setInternalState(bmSafeMode, "extension", 0); bmSafeMode.checkSafeMode(); assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus()); setSafeModeStatus(BMSafeModeStatus.EXTENSION); setBlockSafe(0); Whitebox.setInternalState(bmSafeMode, "extension", 0); bmSafeMode.checkSafeMode(); assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus()); setSafeModeStatus(BMSafeModeStatus.EXTENSION); setBlockSafe(BLOCK_THRESHOLD); Whitebox.setInternalState(bmSafeMode, "extension", Integer.MAX_VALUE); bmSafeMode.checkSafeMode(); assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus()); }