hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject [1/2] hadoop git commit: HDFS-9129. Move the safemode block count into BlockManager. Contributed by Mingliang Liu.
Date Wed, 02 Dec 2015 00:12:18 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 58f6f54ee -> a49cc74b4


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
index 64d80bd..a828e64 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.DFSTestUtil;
 import org.apache.hadoop.hdfs.protocol.Block;
+import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerSafeMode.BMSafeModeStatus;
 import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
@@ -35,6 +36,7 @@ import org.apache.hadoop.util.Daemon;
 import org.junit.Assert;
 
 import com.google.common.base.Preconditions;
+import org.mockito.internal.util.reflection.Whitebox;
 
 public class BlockManagerTestUtil {
   public static void setNodeReplicationLimit(final BlockManager blockManager,
@@ -314,4 +316,11 @@ public class BlockManagerTestUtil {
       Block block, DatanodeStorageInfo[] targets) {
     node.addBlockToBeReplicated(block, targets);
   }
+
+  public static void setStartupSafeModeForTest(BlockManager bm) {
+    BlockManagerSafeMode bmSafeMode = (BlockManagerSafeMode)Whitebox
+        .getInternalState(bm, "bmSafeMode");
+    Whitebox.setInternalState(bmSafeMode, "extension", Integer.MAX_VALUE);
+    Whitebox.setInternalState(bmSafeMode, "status", BMSafeModeStatus.EXTENSION);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
new file mode 100644
index 0000000..606b282
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
@@ -0,0 +1,420 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.blockmanagement;
+
+import com.google.common.base.Supplier;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.protocol.Block;
+import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerSafeMode.BMSafeModeStatus;
+import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.test.GenericTestUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+/**
+ * This test is for testing {@link BlockManagerSafeMode} package local APIs.
+ *
+ * They use heavily mocked objects, treating the {@link BlockManagerSafeMode}
+ * as white-box. Tests are light-weight thus no multi-thread scenario or real
+ * mini-cluster is tested.
+ *
+ * @see org.apache.hadoop.hdfs.TestSafeMode
+ * @see org.apache.hadoop.hdfs.server.namenode.ha.TestHASafeMode
+ * @see org.apache.hadoop.hdfs.TestSafeModeWithStripedFile
+ */
+public class TestBlockManagerSafeMode {
+  private static final int DATANODE_NUM = 3;
+  private static final long BLOCK_TOTAL = 10;
+  private static final double THRESHOLD = 0.99;
+  private static final long BLOCK_THRESHOLD = (long)(BLOCK_TOTAL * THRESHOLD);
+  private static final int EXTENSION = 1000; // 1 second
+
+  private BlockManager bm;
+  private DatanodeManager dn;
+  private BlockManagerSafeMode bmSafeMode;
+
+  /**
+   * Set up the mock context.
+   *
+   * - extension is always needed (default period is {@link #EXTENSION} ms
+   * - datanode threshold is always reached via mock
+   * - safe block is 0 and it needs {@link #BLOCK_THRESHOLD} to reach threshold
+   * - write/read lock is always held by current thread
+   *
+   * @throws IOException
+   */
+  @Before
+  public void setupMockCluster() throws IOException {
+    Configuration conf = new HdfsConfiguration();
+    conf.setDouble(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_THRESHOLD_PCT_KEY,
+        THRESHOLD);
+    conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY,
+        EXTENSION);
+    conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY,
+        DATANODE_NUM);
+
+    FSNamesystem fsn = mock(FSNamesystem.class);
+    Mockito.doReturn(true).when(fsn).hasWriteLock();
+    Mockito.doReturn(true).when(fsn).hasReadLock();
+    Mockito.doReturn(true).when(fsn).isRunning();
+    NameNode.initMetrics(conf, NamenodeRole.NAMENODE);
+
+    bm = spy(new BlockManager(fsn, conf));
+    dn = spy(bm.getDatanodeManager());
+    Whitebox.setInternalState(bm, "datanodeManager", dn);
+    // the datanode threshold is always met
+    when(dn.getNumLiveDataNodes()).thenReturn(DATANODE_NUM);
+
+    bmSafeMode = new BlockManagerSafeMode(bm, fsn, conf);
+  }
+
+  /**
+   * Test set block total.
+   *
+   * The block total is set which will call checkSafeMode for the first time
+   * and bmSafeMode transfers from INITIALIZED to PENDING_THRESHOLD status
+   */
+  @Test(timeout = 30000)
+  public void testInitialize() {
+    assertFalse("Block manager should not be in safe mode at beginning.",
+        bmSafeMode.isInSafeMode());
+    bmSafeMode.activate(BLOCK_TOTAL);
+    assertEquals(BMSafeModeStatus.PENDING_THRESHOLD, getSafeModeStatus());
+    assertTrue(bmSafeMode.isInSafeMode());
+  }
+
+  /**
+   * Test the state machine transition.
+   */
+  @Test(timeout = 30000)
+  public void testCheckSafeMode() {
+    bmSafeMode.activate(BLOCK_TOTAL);
+
+    // stays in PENDING_THRESHOLD: pending block threshold
+    setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
+    for (long i = 0; i < BLOCK_THRESHOLD; i++) {
+      setBlockSafe(i);
+      bmSafeMode.checkSafeMode();
+      assertEquals(BMSafeModeStatus.PENDING_THRESHOLD, getSafeModeStatus());
+    }
+
+    // PENDING_THRESHOLD -> EXTENSION
+    setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
+    setBlockSafe(BLOCK_THRESHOLD);
+    bmSafeMode.checkSafeMode();
+    assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+    Whitebox.setInternalState(bmSafeMode, "smmthread", null);
+
+    // PENDING_THRESHOLD -> OFF
+    setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD);
+    setBlockSafe(BLOCK_THRESHOLD);
+    Whitebox.setInternalState(bmSafeMode, "extension", 0);
+    bmSafeMode.checkSafeMode();
+    assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus());
+
+    // stays in EXTENSION
+    setSafeModeStatus(BMSafeModeStatus.EXTENSION);
+    setBlockSafe(0);
+    Whitebox.setInternalState(bmSafeMode, "extension", 0);
+    bmSafeMode.checkSafeMode();
+    assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+
+    // stays in EXTENSION: pending extension period
+    setSafeModeStatus(BMSafeModeStatus.EXTENSION);
+    setBlockSafe(BLOCK_THRESHOLD);
+    Whitebox.setInternalState(bmSafeMode, "extension", Integer.MAX_VALUE);
+    bmSafeMode.checkSafeMode();
+    assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+  }
+
+  /**
+   * Test that the block safe increases up to block threshold.
+   *
+   * Once the block threshold is reached, the block manger leaves safe mode and
+   * increment will be a no-op.
+   * The safe mode status lifecycle: INITIALIZED -> PENDING_THRESHOLD -> OFF
+   */
+  @Test(timeout = 30000)
+  public void testIncrementSafeBlockCount() {
+    bmSafeMode.activate(BLOCK_TOTAL);
+    Whitebox.setInternalState(bmSafeMode, "extension", 0);
+
+    for (long i = 1; i <= BLOCK_TOTAL; i++) {
+      BlockInfo blockInfo = mock(BlockInfo.class);
+      doReturn(false).when(blockInfo).isStriped();
+      bmSafeMode.incrementSafeBlockCount(1, blockInfo);
+      if (i < BLOCK_THRESHOLD) {
+        assertEquals(i, getblockSafe());
+        assertTrue(bmSafeMode.isInSafeMode());
+      } else {
+        // block manager leaves safe mode if block threshold is met
+        assertFalse(bmSafeMode.isInSafeMode());
+        // the increment will be a no-op if safe mode is OFF
+        assertEquals(BLOCK_THRESHOLD, getblockSafe());
+      }
+    }
+  }
+
+  /**
+   * Test that the block safe increases up to block threshold.
+   *
+   * Once the block threshold is reached, the block manger leaves safe mode and
+   * increment will be a no-op.
+   * The safe mode status lifecycle: INITIALIZED -> PENDING_THRESHOLD -> EXTENSION->
OFF
+   */
+  @Test(timeout = 30000)
+  public void testIncrementSafeBlockCountWithExtension() throws Exception {
+    bmSafeMode.activate(BLOCK_TOTAL);
+
+    for (long i = 1; i <= BLOCK_TOTAL; i++) {
+      BlockInfo blockInfo = mock(BlockInfo.class);
+      doReturn(false).when(blockInfo).isStriped();
+      bmSafeMode.incrementSafeBlockCount(1, blockInfo);
+      if (i < BLOCK_THRESHOLD) {
+        assertTrue(bmSafeMode.isInSafeMode());
+      }
+    }
+    waitForExtensionPeriod();
+    assertFalse(bmSafeMode.isInSafeMode());
+  }
+
+  /**
+   * Test that the block safe decreases the block safe.
+   *
+   * The block manager stays in safe mode.
+   * The safe mode status lifecycle: INITIALIZED -> PENDING_THRESHOLD
+   */
+  @Test(timeout = 30000)
+  public void testDecrementSafeBlockCount() {
+    bmSafeMode.activate(BLOCK_TOTAL);
+    Whitebox.setInternalState(bmSafeMode, "extension", 0);
+
+    mockBlockManagerForBlockSafeDecrement();
+    setBlockSafe(BLOCK_THRESHOLD);
+    for (long i = BLOCK_THRESHOLD; i > 0; i--) {
+      BlockInfo blockInfo = mock(BlockInfo.class);
+      bmSafeMode.decrementSafeBlockCount(blockInfo);
+
+      assertEquals(i - 1, getblockSafe());
+      assertTrue(bmSafeMode.isInSafeMode());
+    }
+  }
+
+  /**
+   * Test when the block safe increment and decrement interleave.
+   *
+   * Both the increment and decrement will be a no-op if the safe mode is OFF.
+   * The safe mode status lifecycle: INITIALIZED -> PENDING_THRESHOLD -> OFF
+   */
+  @Test(timeout = 30000)
+  public void testIncrementAndDecrementSafeBlockCount() {
+    bmSafeMode.activate(BLOCK_TOTAL);
+    Whitebox.setInternalState(bmSafeMode, "extension", 0);
+
+    mockBlockManagerForBlockSafeDecrement();
+    for (long i = 1; i <= BLOCK_TOTAL; i++) {
+      BlockInfo blockInfo = mock(BlockInfo.class);
+      doReturn(false).when(blockInfo).isStriped();
+
+      bmSafeMode.incrementSafeBlockCount(1, blockInfo);
+      bmSafeMode.decrementSafeBlockCount(blockInfo);
+      bmSafeMode.incrementSafeBlockCount(1, blockInfo);
+
+      if (i < BLOCK_THRESHOLD) {
+        assertEquals(i, getblockSafe());
+        assertTrue(bmSafeMode.isInSafeMode());
+      } else {
+        // block manager leaves safe mode if block threshold is met
+        assertEquals(BLOCK_THRESHOLD, getblockSafe());
+        assertFalse(bmSafeMode.isInSafeMode());
+      }
+    }
+  }
+
+  /**
+   * Test the safe mode monitor.
+   *
+   * The monitor will make block manager leave the safe mode after  extension
+   * period.
+   */
+  @Test(timeout = 30000)
+  public void testSafeModeMonitor() throws Exception {
+    bmSafeMode.activate(BLOCK_TOTAL);
+
+    setBlockSafe(BLOCK_THRESHOLD);
+    // PENDING_THRESHOLD -> EXTENSION
+    bmSafeMode.checkSafeMode();
+
+    assertTrue(bmSafeMode.isInSafeMode());
+    waitForExtensionPeriod();
+    assertFalse(bmSafeMode.isInSafeMode());
+  }
+
+  /**
+   * Test block manager won't leave safe mode if datanode threshold is not met.
+   */
+  @Test(timeout = 30000)
+  public void testDatanodeThreshodShouldBeMet() throws Exception {
+    bmSafeMode.activate(BLOCK_TOTAL);
+
+    // All datanode have not registered yet.
+    when(dn.getNumLiveDataNodes()).thenReturn(1);
+    setBlockSafe(BLOCK_THRESHOLD);
+    bmSafeMode.checkSafeMode();
+    assertTrue(bmSafeMode.isInSafeMode());
+
+    // The datanode number reaches threshold after all data nodes register
+    when(dn.getNumLiveDataNodes()).thenReturn(DATANODE_NUM);
+    bmSafeMode.checkSafeMode();
+    waitForExtensionPeriod();
+    assertFalse(bmSafeMode.isInSafeMode());
+  }
+
+  /**
+   * Test block manager won't leave safe mode if there are orphan blocks.
+   */
+  @Test(timeout = 30000)
+  public void testStayInSafeModeWhenBytesInFuture() throws Exception {
+    bmSafeMode.activate(BLOCK_TOTAL);
+
+    when(bm.getBytesInFuture()).thenReturn(1L);
+    // safe blocks are enough
+   setBlockSafe(BLOCK_THRESHOLD);
+
+    // PENDING_THRESHOLD -> EXTENSION
+    bmSafeMode.checkSafeMode();
+    try {
+      waitForExtensionPeriod();
+      fail("Safe mode should not leave extension period with orphan blocks!");
+    } catch (TimeoutException e) {
+      assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+    }
+  }
+
+  /**
+   * Test get safe mode tip.
+   */
+  @Test(timeout = 30000)
+  public void testGetSafeModeTip() throws Exception {
+    bmSafeMode.activate(BLOCK_TOTAL);
+    String tip = bmSafeMode.getSafeModeTip();
+    assertTrue(tip.contains(
+        String.format(
+            "The reported blocks %d needs additional %d blocks to reach the " +
+                "threshold %.4f of total blocks %d.%n",
+            0, BLOCK_THRESHOLD, THRESHOLD, BLOCK_TOTAL)));
+    assertTrue(tip.contains(
+        String.format("The number of live datanodes %d has reached the " +
+            "minimum number %d. ", dn.getNumLiveDataNodes(), DATANODE_NUM)));
+    assertTrue(tip.contains("Safe mode will be turned off automatically once " +
+        "the thresholds have been reached."));
+
+    // safe blocks are enough
+    setBlockSafe(BLOCK_THRESHOLD);
+    bmSafeMode.checkSafeMode();
+    tip = bmSafeMode.getSafeModeTip();
+    assertTrue(tip.contains(
+        String.format("The reported blocks %d has reached the threshold"
+            + " %.4f of total blocks %d. ",
+            getblockSafe(), THRESHOLD, BLOCK_TOTAL)));
+    assertTrue(tip.contains(
+        String.format("The number of live datanodes %d has reached the " +
+            "minimum number %d. ", dn.getNumLiveDataNodes(), DATANODE_NUM)));
+    assertTrue(tip.contains("In safe mode extension. Safe mode will be turned" +
+        " off automatically in"));
+
+    waitForExtensionPeriod();
+    tip = bmSafeMode.getSafeModeTip();
+    System.out.println(tip);
+    assertTrue(tip.contains(
+        String.format("The reported blocks %d has reached the threshold"
+                + " %.4f of total blocks %d. ",
+            getblockSafe(), THRESHOLD, BLOCK_TOTAL)));
+    assertTrue(tip.contains(
+        String.format("The number of live datanodes %d has reached the " +
+            "minimum number %d. ", dn.getNumLiveDataNodes(), DATANODE_NUM)));
+    assertTrue(tip.contains("Safe mode will be turned off automatically soon"));
+  }
+
+  /**
+   * Mock block manager internal state for decrement safe block
+   */
+  private void mockBlockManagerForBlockSafeDecrement() {
+    BlockInfo storedBlock = mock(BlockInfo.class);
+    when(storedBlock.isComplete()).thenReturn(true);
+    doReturn(storedBlock).when(bm).getStoredBlock(any(Block.class));
+    NumberReplicas numberReplicas = mock(NumberReplicas.class);
+    when(numberReplicas.liveReplicas()).thenReturn(0);
+    doReturn(numberReplicas).when(bm).countNodes(any(Block.class));
+  }
+
+  /**
+   * Wait the bmSafeMode monitor for the extension period.
+   * @throws InterruptedIOException
+   * @throws TimeoutException
+   */
+  private void waitForExtensionPeriod() throws Exception{
+    assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus());
+
+    GenericTestUtils.waitFor(new Supplier<Boolean>() {
+        @Override
+        public Boolean get() {
+          return getSafeModeStatus() != BMSafeModeStatus.EXTENSION;
+        }
+    }, EXTENSION / 10, EXTENSION * 2);
+  }
+
+  private void setSafeModeStatus(BMSafeModeStatus status) {
+    Whitebox.setInternalState(bmSafeMode, "status", status);
+  }
+
+  private BMSafeModeStatus getSafeModeStatus() {
+    return (BMSafeModeStatus)Whitebox.getInternalState(bmSafeMode, "status");
+  }
+
+  private void setBlockSafe(long blockSafe) {
+    Whitebox.setInternalState(bmSafeMode, "blockSafe", blockSafe);
+  }
+
+  private long getblockSafe() {
+    return (long)Whitebox.getInternalState(bmSafeMode, "blockSafe");
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
index 22b6697..1a8a088 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
@@ -1359,7 +1359,7 @@ public class TestReplicationPolicy extends BaseReplicationPolicyTest
{
       testConvertLastBlockToUnderConstructionDoesNotCauseSkippedReplication()
           throws IOException {
     Namesystem mockNS = mock(Namesystem.class);
-    when(mockNS.hasReadLock()).thenReturn(true);
+    when(mockNS.hasWriteLock()).thenReturn(true);
 
     BlockManager bm = new BlockManager(mockNS, new HdfsConfiguration());
     UnderReplicatedBlocks underReplicatedBlocks = bm.neededReplications;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
index fd11cc0..69980db 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
@@ -35,7 +35,6 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
 import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
 import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
 import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.MkdirOp;
-import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.SafeModeInfo;
 import org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease;
 import org.apache.hadoop.hdfs.server.namenode.ha.EditLogTailer;
 import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
@@ -236,12 +235,13 @@ public class NameNodeAdapter {
    * @return the number of blocks marked safe by safemode, or -1
    * if safemode is not running.
    */
-  public static int getSafeModeSafeBlocks(NameNode nn) {
-    SafeModeInfo smi = nn.getNamesystem().getSafeModeInfoForTests();
-    if (smi == null) {
+  public static long getSafeModeSafeBlocks(NameNode nn) {
+    if (!nn.getNamesystem().isInSafeMode()) {
       return -1;
     }
-    return smi.blockSafe;
+    Object bmSafeMode = Whitebox.getInternalState(
+        nn.getNamesystem().getBlockManager(), "bmSafeMode");
+    return (long)Whitebox.getInternalState(bmSafeMode, "blockSafe");
   }
   
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
index 15fc40e..be72192 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
@@ -35,7 +35,6 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
 import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
-import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.SafeModeInfo;
 import org.apache.hadoop.hdfs.server.namenode.ha.HAContext;
 import org.apache.hadoop.hdfs.server.namenode.ha.HAState;
 import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
@@ -332,7 +331,11 @@ public class TestFSNamesystem {
     Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog);
     conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_MIN_KEY, 2);
     FSNamesystem fsn = new FSNamesystem(conf, fsImage);
-    SafeModeInfo safemodeInfo = fsn.getSafeModeInfoForTests();
-    assertTrue(safemodeInfo.toString().contains("Minimal replication = 2"));
+
+    Object bmSafeMode = Whitebox.getInternalState(fsn.getBlockManager(),
+        "bmSafeMode");
+    int safeReplication = (int)Whitebox.getInternalState(bmSafeMode,
+        "safeReplication");
+    assertEquals(2, safeReplication);
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
index 2d36bc1..9171194 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
@@ -103,8 +103,6 @@ public class TestNameNodeMetadataConsistency {
 
     // we also need to tell block manager that we are in the startup path
     FSNamesystem spyNameSystem = spy(cluster.getNameNode().getNamesystem());
-    spyNameSystem.enableSafeModeForTesting(conf);
-
     Whitebox.setInternalState(cluster.getNameNode()
             .getNamesystem().getBlockManager(),
         "namesystem", spyNameSystem);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a49cc74b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java
index 9ded0ed..21de9606 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHASafeMode.java
@@ -32,7 +32,6 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.impl.Log4JLogger;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FSDataOutputStream;
@@ -56,7 +55,6 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
 import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
 import org.apache.hadoop.hdfs.server.namenode.FSImage;
 import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
-import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.SafeModeInfo;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
 import org.apache.hadoop.io.IOUtils;
@@ -126,10 +124,13 @@ public class TestHASafeMode {
         .synchronizedMap(new HashMap<Path, Boolean>());
     final Path test = new Path("/test");
     // let nn0 enter safemode
+    cluster.getConfiguration(0).setInt(
+        DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY, 3);
     NameNodeAdapter.enterSafeMode(nn0, false);
-    SafeModeInfo safeMode = (SafeModeInfo) Whitebox.getInternalState(
-        nn0.getNamesystem(), "safeMode");
-    Whitebox.setInternalState(safeMode, "extension", Integer.valueOf(30000));
+    Whitebox.setInternalState(nn0.getNamesystem(), "manualSafeMode", false);
+    BlockManagerTestUtil.setStartupSafeModeForTest(nn0.getNamesystem()
+        .getBlockManager());
+    assertTrue(nn0.getNamesystem().isInStartupSafeMode());
     LOG.info("enter safemode");
     new Thread() {
       @Override


Mime
View raw message