Skip to content

Commit 0b50aa2

Browse files
Hexiaoqiaojojochuang
authored andcommitted
HDFS-14952. Skip safemode if blockTotal is 0 in new NN. Contributed by Xiaoqiao He.
Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org> Reviewed-by: Mukul Kumar Singh <msingh@apache.org>
1 parent dfdc6d6 commit 0b50aa2

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void checkSafeMode() {
210210
switch (status) {
211211
case PENDING_THRESHOLD:
212212
if (areThresholdsMet()) {
213-
if (extension > 0) {
213+
if (blockTotal > 0 && extension > 0) {
214214
// PENDING_THRESHOLD -> EXTENSION
215215
status = BMSafeModeStatus.EXTENSION;
216216
reachedTime.set(monotonicNow());
@@ -532,11 +532,13 @@ void close() {
532532

533533
/**
534534
* Get time (counting in milliseconds) left to leave extension period.
535+
* It should leave safemode at once if blockTotal = 0 rather than wait
536+
* extension time (30s by default).
535537
*
536538
* Negative value indicates the extension period has passed.
537539
*/
538540
private long timeToLeaveExtension() {
539-
return reachedTime.get() + extension - monotonicNow();
541+
return blockTotal > 0 ? reachedTime.get() + extension - monotonicNow() : 0;
540542
}
541543

542544
/**

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ public Boolean get() {
221221
}, 100, 10000);
222222
}
223223

224+
@Test
225+
public void testCheckSafeMode8() throws Exception {
226+
bmSafeMode.activate(0);
227+
setBlockSafe(0);
228+
setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
229+
bmSafeMode.checkSafeMode();
230+
assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus());
231+
}
232+
224233
/**
225234
* Test that the block safe increases up to block threshold.
226235
*

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,15 @@ public void testBlocksDeletedInEditLog() throws Exception {
497497
private static void assertSafeMode(NameNode nn, int safe, int total,
498498
int numNodes, int nodeThresh) {
499499
String status = nn.getNamesystem().getSafemode();
500-
if (safe == total) {
500+
if (total == 0 && nodeThresh == 0) {
501+
assertTrue("Bad safemode status: '" + status + "'",
502+
status.isEmpty()
503+
|| status.startsWith("Safe mode is ON. The reported blocks 0 " +
504+
"has reached the threshold 0.9990 of total blocks 0. The " +
505+
"minimum number of live datanodes is not required. In safe " +
506+
"mode extension. Safe mode will be turned off automatically " +
507+
"in 0 seconds."));
508+
} else if (safe == total) {
501509
if (nodeThresh == 0) {
502510
assertTrue("Bad safemode status: '" + status + "'",
503511
status.startsWith("Safe mode is ON. The reported blocks " + safe

0 commit comments

Comments
 (0)