[1/2] hadoop git commit: HDFS-9390. Block management for maintenance states.
Repository: hadoop Updated Branches: refs/heads/branch-2 a5a56c356 -> d55a7f893 http://git-wip-us.apache.org/repos/asf/hadoop/blob/d55a7f89/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java index 63617ad..c125f45 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java @@ -18,13 +18,19 @@ package org.apache.hadoop.hdfs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.client.HdfsDataInputStream; @@ -32,6 +38,8 @@ import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo.AdminStates; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.LocatedBlock; +import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager; +import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.util.Time; import org.junit.Test; @@ -40,13 +48,23 @@ import org.junit.Test; * This class tests node maintenance. */ public class TestMaintenanceState extends AdminStatesBaseTest { - public static final Log LOG = LogFactory.getLog(TestMaintenanceState.class); - static private final long EXPIRATION_IN_MS = 500; + public static final Logger LOG = + LoggerFactory.getLogger(TestMaintenanceState.class); + static private final long EXPIRATION_IN_MS = 50; + private int minMaintenanceR = + DFSConfigKeys.DFS_NAMENODE_MAINTENANCE_REPLICATION_MIN_DEFAULT; public TestMaintenanceState() { setUseCombinedHostFileManager(); } + void setMinMaintenanceR(int minMaintenanceR) { +this.minMaintenanceR = minMaintenanceR; +getConf().setInt( +DFSConfigKeys.DFS_NAMENODE_MAINTENANCE_REPLICATION_MIN_KEY, +minMaintenanceR); + } + /** * Verify a node can transition from AdminStates.ENTERING_MAINTENANCE to * AdminStates.NORMAL. @@ -55,21 +73,25 @@ public class TestMaintenanceState extends AdminStatesBaseTest { public void testTakeNodeOutOfEnteringMaintenance() throws Exception { LOG.info("Starting testTakeNodeOutOfEnteringMaintenance"); final int replicas = 1; -final int numNamenodes = 1; -final int numDatanodes = 1; -final Path file1 = new Path("/testTakeNodeOutOfEnteringMaintenance.dat"); +final Path file = new Path("/testTakeNodeOutOfEnteringMaintenance.dat"); -startCluster(numNamenodes, numDatanodes); +startCluster(1, 1); -FileSystem fileSys = getCluster().getFileSystem(0); -writeFile(fileSys, file1, replicas, 1); +final FileSystem fileSys = getCluster().getFileSystem(0); +final FSNamesystem ns = getCluster().getNamesystem(0); +writeFile(fileSys, file, replicas, 1); -DatanodeInfo nodeOutofService = takeNodeOutofService(0, +final DatanodeInfo nodeOutofService = takeNodeOutofService(0, null, Long.MAX_VALUE, null, AdminStates.ENTERING_MAINTENANCE); +// When node is in ENTERING_MAINTENANCE state, it can still serve read +// requests +assertNull(checkWithRetry(ns, fileSys, file, replicas, null, +nodeOutofService)); + putNodeInService(0, nodeOutofService.getDatanodeUuid()); -cleanupFile(fileSys, file1); +cleanupFile(fileSys, file); } /** @@ -80,23 +102,21 @@ public class TestMaintenanceState extends AdminStatesBaseTest { public void testEnteringMaintenanceExpiration() throws Exception { LOG.info("Starting testEnteringMaintenanceExpiration"); final int replicas = 1; -final int numNamenodes = 1; -final int numDatanodes = 1; -final Path file1 = new Path("/testTakeNodeOutOfEnteringMaintenance.dat"); +final Path file = new Path("/testEnteringMaintenanceExpiration.dat"); -startCluster(numNamenodes, numDatanodes); +startCluster(1, 1); -FileSystem fileSys = getCluster().getFileSystem(0); -writeFile(fileSys, file1, replicas, 1); +final FileSystem fileSys = getCluster().getFileSystem(0); +writeFile(fileSys, file, replicas,
[1/2] hadoop git commit: HDFS-9390. Block management for maintenance states.
Repository: hadoop Updated Branches: refs/heads/trunk f5d923591 -> b61fb267b http://git-wip-us.apache.org/repos/asf/hadoop/blob/b61fb267/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java index 63617ad..c125f45 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java @@ -18,13 +18,19 @@ package org.apache.hadoop.hdfs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.client.HdfsDataInputStream; @@ -32,6 +38,8 @@ import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo.AdminStates; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.LocatedBlock; +import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager; +import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.util.Time; import org.junit.Test; @@ -40,13 +48,23 @@ import org.junit.Test; * This class tests node maintenance. */ public class TestMaintenanceState extends AdminStatesBaseTest { - public static final Log LOG = LogFactory.getLog(TestMaintenanceState.class); - static private final long EXPIRATION_IN_MS = 500; + public static final Logger LOG = + LoggerFactory.getLogger(TestMaintenanceState.class); + static private final long EXPIRATION_IN_MS = 50; + private int minMaintenanceR = + DFSConfigKeys.DFS_NAMENODE_MAINTENANCE_REPLICATION_MIN_DEFAULT; public TestMaintenanceState() { setUseCombinedHostFileManager(); } + void setMinMaintenanceR(int minMaintenanceR) { +this.minMaintenanceR = minMaintenanceR; +getConf().setInt( +DFSConfigKeys.DFS_NAMENODE_MAINTENANCE_REPLICATION_MIN_KEY, +minMaintenanceR); + } + /** * Verify a node can transition from AdminStates.ENTERING_MAINTENANCE to * AdminStates.NORMAL. @@ -55,21 +73,25 @@ public class TestMaintenanceState extends AdminStatesBaseTest { public void testTakeNodeOutOfEnteringMaintenance() throws Exception { LOG.info("Starting testTakeNodeOutOfEnteringMaintenance"); final int replicas = 1; -final int numNamenodes = 1; -final int numDatanodes = 1; -final Path file1 = new Path("/testTakeNodeOutOfEnteringMaintenance.dat"); +final Path file = new Path("/testTakeNodeOutOfEnteringMaintenance.dat"); -startCluster(numNamenodes, numDatanodes); +startCluster(1, 1); -FileSystem fileSys = getCluster().getFileSystem(0); -writeFile(fileSys, file1, replicas, 1); +final FileSystem fileSys = getCluster().getFileSystem(0); +final FSNamesystem ns = getCluster().getNamesystem(0); +writeFile(fileSys, file, replicas, 1); -DatanodeInfo nodeOutofService = takeNodeOutofService(0, +final DatanodeInfo nodeOutofService = takeNodeOutofService(0, null, Long.MAX_VALUE, null, AdminStates.ENTERING_MAINTENANCE); +// When node is in ENTERING_MAINTENANCE state, it can still serve read +// requests +assertNull(checkWithRetry(ns, fileSys, file, replicas, null, +nodeOutofService)); + putNodeInService(0, nodeOutofService.getDatanodeUuid()); -cleanupFile(fileSys, file1); +cleanupFile(fileSys, file); } /** @@ -80,23 +102,21 @@ public class TestMaintenanceState extends AdminStatesBaseTest { public void testEnteringMaintenanceExpiration() throws Exception { LOG.info("Starting testEnteringMaintenanceExpiration"); final int replicas = 1; -final int numNamenodes = 1; -final int numDatanodes = 1; -final Path file1 = new Path("/testTakeNodeOutOfEnteringMaintenance.dat"); +final Path file = new Path("/testEnteringMaintenanceExpiration.dat"); -startCluster(numNamenodes, numDatanodes); +startCluster(1, 1); -FileSystem fileSys = getCluster().getFileSystem(0); -writeFile(fileSys, file1, replicas, 1); +final FileSystem fileSys = getCluster().getFileSystem(0); +writeFile(fileSys, file, replicas, 1)