Java Code Examples for org.apache.hadoop.hdfs.server.namenode.NameNode#setSafeMode()

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.NameNode#setSafeMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAbandonBlockEditLog.java    From RDFS with Apache License 2.0 6 votes vote down vote up
@Test
public void testEditLog() throws Exception {
  String src = "/testEditLog";
  String src1 = "/testEditLog1";
  NameNode nn = cluster.getNameNode();
  String clientName = ((DistributedFileSystem) fs).getClient().clientName;
  fs.create(new Path(src));
  for (int i = 0; i < 10; i++) {
    Block b = nn.addBlock(src, clientName).getBlock();
    nn.abandonBlock(b, src, clientName);
  }
  fs.create(new Path(src1));
  nn.addBlock(src1, clientName);
  cluster.restartNameNode(0, new String[] {}, false);
  nn = cluster.getNameNode();
  assertTrue(nn.isInSafeMode());
  nn.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
}
 
Example 2
Source File: TestSafeMode.java    From RDFS with Apache License 2.0 4 votes vote down vote up
public void testManualSafeMode() throws IOException {
  MiniDFSCluster cluster = null;
  FileSystem fs = null;
  try {
    Configuration conf = new Configuration();
    // disable safemode extension to make the test run faster.
    conf.set("dfs.safemode.extension", "1");
    cluster = new MiniDFSCluster(conf, 1, true, null);
    cluster.waitActive();
    
    fs = cluster.getFileSystem();
    Path file1 = new Path("/tmp/testManualSafeMode/file1");
    Path file2 = new Path("/tmp/testManualSafeMode/file2");
    
    LOG.info("Created file1 and file2.");
    
    // create two files with one block each.
    DFSTestUtil.createFile(fs, file1, 1000, (short)1, 0);
    DFSTestUtil.createFile(fs, file2, 2000, (short)1, 0);    
    cluster.shutdown();
    
    // now bring up just the NameNode.
    cluster = new MiniDFSCluster(conf, 0, false, null);
    cluster.waitActive();
    
    LOG.info("Restarted cluster with just the NameNode");
    
    NameNode namenode = cluster.getNameNode();
    
    assertTrue("No datanode is started. Should be in SafeMode", 
               namenode.isInSafeMode());
    
    // manually set safemode.
    namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    
    // now bring up the datanode and wait for it to be active.
    cluster.startDataNodes(conf, 1, true, null, null);
    cluster.waitActive();
    
    LOG.info("Datanode is started.");
    
    try {
      Thread.sleep(2000);
    } catch (InterruptedException ignored) {}
    
    assertTrue("should still be in SafeMode", namenode.isInSafeMode());
    
    namenode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
    assertFalse("should not be in SafeMode", namenode.isInSafeMode());
  } finally {
    if(fs != null) fs.close();
    if(cluster!= null) cluster.shutdown();
  }
}
 
Example 3
Source File: TestBlockReportProcessingTime.java    From RDFS with Apache License 2.0 4 votes vote down vote up
/** Test the case when a block report processing at namenode
 * startup time is fast.
 */
public void testFasterBlockReports() throws Exception {
  MiniDFSCluster cluster = null;
  try {
    Configuration conf = new Configuration();
    cluster = new MiniDFSCluster(conf, 40, true, null);
    cluster.waitActive();
    FileSystem fs = cluster.getFileSystem();
    NameNode namenode = cluster.getNameNode();
    LOG.info("Cluster Alive."); 

    // create a single file with one block.
    Path file1 = new Path("/filestatus.dat");
    final long FILE_LEN = 1L;
    DFSTestUtil.createFile(fs, file1, FILE_LEN, (short)2, 1L);
    LocatedBlocks locations = namenode.getBlockLocations(
                                file1.toString(), 0, Long.MAX_VALUE);
    assertTrue(locations.locatedBlockCount() == 1);
    Block block = locations.get(0).getBlock();
    long blkid = block.getBlockId();
    long genstamp = block.getGenerationStamp();
    long length = block.getNumBytes();
    
    // put namenode in safemode
    namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    DatanodeInfo[] dinfo = namenode.getDatanodeReport(DatanodeReportType.ALL);
    LOG.info("Found " + dinfo.length + " number of datanodes.");

    // create artificial block replicas on each datanode
    final int NUMBLOCKS = 1000;
    final int LONGS_PER_BLOCK = 3;
    long tmpblocks[] = new long[NUMBLOCKS * LONGS_PER_BLOCK];
    for (int i = 0; i < NUMBLOCKS; i++) {
      tmpblocks[i * LONGS_PER_BLOCK] = blkid;
      tmpblocks[i * LONGS_PER_BLOCK + 1] = length;
      tmpblocks[i * LONGS_PER_BLOCK + 2] = genstamp;
    }
    BlockListAsLongs blkList = new BlockListAsLongs(tmpblocks);

    // process block report from all machines
    long total = 0;
    for (int i = 0; i < dinfo.length; i++) {
      long start = now();
      namenode.namesystem.processReport(dinfo[i], blkList);
      total += now() - start;
      LOG.info("Processed block report from " + dinfo[i]);
    }
    LOG.info("Average of all block report processing time " +
             " from " + dinfo.length + " datanodes is " +
             (total/dinfo.length) + " milliseconds.");
    
  } finally {
    if (cluster != null) { cluster.shutdown(); }
  }
}
 
Example 4
Source File: TestSafeMode.java    From hadoop-gpu with Apache License 2.0 4 votes vote down vote up
public void testManualSafeMode() throws IOException {
  MiniDFSCluster cluster = null;
  FileSystem fs = null;
  try {
    Configuration conf = new Configuration();
    // disable safemode extension to make the test run faster.
    conf.set("dfs.safemode.extension", "1");
    cluster = new MiniDFSCluster(conf, 1, true, null);
    cluster.waitActive();
    
    fs = cluster.getFileSystem();
    Path file1 = new Path("/tmp/testManualSafeMode/file1");
    Path file2 = new Path("/tmp/testManualSafeMode/file2");
    
    LOG.info("Created file1 and file2.");
    
    // create two files with one block each.
    DFSTestUtil.createFile(fs, file1, 1000, (short)1, 0);
    DFSTestUtil.createFile(fs, file2, 2000, (short)1, 0);    
    cluster.shutdown();
    
    // now bring up just the NameNode.
    cluster = new MiniDFSCluster(conf, 0, false, null);
    cluster.waitActive();
    
    LOG.info("Restarted cluster with just the NameNode");
    
    NameNode namenode = cluster.getNameNode();
    
    assertTrue("No datanode is started. Should be in SafeMode", 
               namenode.isInSafeMode());
    
    // manually set safemode.
    namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    
    // now bring up the datanode and wait for it to be active.
    cluster.startDataNodes(conf, 1, true, null, null);
    cluster.waitActive();
    
    LOG.info("Datanode is started.");
    
    try {
      Thread.sleep(2000);
    } catch (InterruptedException ignored) {}
    
    assertTrue("should still be in SafeMode", namenode.isInSafeMode());
    
    namenode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
    assertFalse("should not be in SafeMode", namenode.isInSafeMode());
  } finally {
    if(fs != null) fs.close();
    if(cluster!= null) cluster.shutdown();
  }
}