• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SafeModeAction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction的典型用法代码示例。如果您正苦于以下问题:Java SafeModeAction类的具体用法?Java SafeModeAction怎么用?Java SafeModeAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SafeModeAction类属于org.apache.hadoop.hdfs.protocol.FSConstants包,在下文中一共展示了SafeModeAction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testEditLog

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@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);
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:19,代码来源:TestAbandonBlockEditLog.java


示例2: testSaveNamespaceWithRenamedLease

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
/**
 * Test for save namespace should succeed when parent directory renamed with
 * open lease and destination directory exist. 
 * This test is a regression for HDFS-2827
 */
@Test
public void testSaveNamespaceWithRenamedLease() throws Exception {
  MiniDFSCluster cluster = new MiniDFSCluster(new Configuration(), 1, true, (String[]) null);
  cluster.waitActive();
  DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
  OutputStream out = null;
  try {
    fs.mkdirs(new Path("/test-target"));
    out = fs.create(new Path("/test-source/foo")); // don't close
    fs.rename(new Path("/test-source/"), new Path("/test-target/"));

    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    cluster.getNameNode().saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  } finally {
    IOUtils.cleanup(LOG, out, fs);
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:27,代码来源:TestSaveNamespace.java


示例3: testAvatarShellLeaveSafeMode

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Test
public void testAvatarShellLeaveSafeMode() throws Exception {
  setUp(false, "testAvatarShellLeaveSafeMode");
  int blocksBefore = blocksInFile();

  AvatarShell shell = new AvatarShell(conf);
  AvatarNode primaryAvatar = cluster.getPrimaryAvatar(0).avatar;
  primaryAvatar.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
  assertTrue(primaryAvatar.isInSafeMode());
  assertEquals(0, shell.run(new String[] { "-zero", "-safemode", "leave" }));
  assertFalse(primaryAvatar.isInSafeMode());
  assertFalse(cluster.getPrimaryAvatar(0).avatar.isInSafeMode());
  int blocksAfter = blocksInFile();
  assertTrue(blocksBefore == blocksAfter);

}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:17,代码来源:TestAvatarShell.java


示例4: testAvatarShellLeaveSafeMode1

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Test
public void testAvatarShellLeaveSafeMode1() throws Exception {
  setUp(false, "testAvatarShellLeaveSafeMode1");
  int blocksBefore = blocksInFile();
  cluster.failOver();
  cluster.restartStandby();

  AvatarShell shell = new AvatarShell(conf);
  AvatarNode primaryAvatar = cluster.getPrimaryAvatar(0).avatar;
  primaryAvatar.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
  assertTrue(primaryAvatar.isInSafeMode());
  assertEquals(0, shell.run(new String[] { "-one", "-safemode", "leave" }));
  assertFalse(primaryAvatar.isInSafeMode());
  assertFalse(cluster.getPrimaryAvatar(0).avatar.isInSafeMode());
  int blocksAfter = blocksInFile();
  assertTrue(blocksBefore == blocksAfter);
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:18,代码来源:TestAvatarShell.java


示例5: testAvatarShellLeaveSafeMode

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Test
public void testAvatarShellLeaveSafeMode() throws Exception {
  setUp(false);
  int blocksBefore = blocksInFile();

  AvatarShell shell = new AvatarShell(conf);
  AvatarNode primaryAvatar = cluster.getPrimaryAvatar(0).avatar;
  primaryAvatar.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
  assertTrue(primaryAvatar.isInSafeMode());
  assertEquals(0, shell.run(new String[] { "-zero", "-leaveSafeMode" }));
  assertFalse(primaryAvatar.isInSafeMode());
  assertFalse(cluster.getPrimaryAvatar(0).avatar.isInSafeMode());
  int blocksAfter = blocksInFile();
  assertTrue(blocksBefore == blocksAfter);

}
 
开发者ID:iVCE,项目名称:RDFS,代码行数:17,代码来源:TestAvatarShell.java


示例6: testAvatarShellLeaveSafeMode1

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Test
public void testAvatarShellLeaveSafeMode1() throws Exception {
  setUp(false);
  int blocksBefore = blocksInFile();
  cluster.failOver();
  cluster.restartStandby();

  AvatarShell shell = new AvatarShell(conf);
  AvatarNode primaryAvatar = cluster.getPrimaryAvatar(0).avatar;
  primaryAvatar.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
  assertTrue(primaryAvatar.isInSafeMode());
  assertEquals(0, shell.run(new String[] { "-one", "-leaveSafeMode" }));
  assertFalse(primaryAvatar.isInSafeMode());
  assertFalse(cluster.getPrimaryAvatar(0).avatar.isInSafeMode());
  int blocksAfter = blocksInFile();
  assertTrue(blocksBefore == blocksAfter);
}
 
开发者ID:iVCE,项目名称:RDFS,代码行数:18,代码来源:TestAvatarShell.java


示例7: testMismatchedBlockGS

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
public void testMismatchedBlockGS() throws IOException {
  Configuration conf = new Configuration();
  final short REPLICATION_FACTOR = 1;
  MiniDFSCluster cluster = new MiniDFSCluster(
      conf, REPLICATION_FACTOR, true, null);
  try {
    cluster.waitActive();

    FileSystem fs = cluster.getFileSystem();
    Path file1 = new Path("/tmp/file1");

    // create a file
    DFSTestUtil.createFile(fs, file1, 10, REPLICATION_FACTOR, 0);

    // corrupt its generation stamp
    Block block = DFSTestUtil.getFirstBlock(fs, file1);
    corruptReplicaGS(block, 0, cluster);
    
    // stop and start the cluster
    cluster.shutdown();
    cluster = new MiniDFSCluster(
        conf, REPLICATION_FACTOR, false, null, false);
    cluster.waitActive();
    assertTrue(cluster.getNameNode().setSafeMode(SafeModeAction.SAFEMODE_GET));
    cluster.getNameNode().setSafeMode(SafeModeAction.SAFEMODE_LEAVE);

    // Verify that there is a missing block
    assertEquals(1, 
        cluster.getNameNode().getNamesystem().getMissingBlocksCount());
  } finally {
    cluster.shutdown();
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:34,代码来源:TestCorruptBlocks.java


示例8: testRestartNameNode

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
public void testRestartNameNode(boolean waitSafeMode) throws Exception {
  String file = "/testRestartNameNode" + waitSafeMode;

  // Create a file and write data.
  FSDataOutputStream out = fs.create(new Path(file));
  String clientName = ((DistributedFileSystem) fs).getClient().getClientName();
  byte[] buffer = new byte[FILE_LEN];
  random.nextBytes(buffer);
  out.write(buffer);
  ((DFSOutputStream) out.getWrappedStream()).sync();

  // Now shutdown the namenode and try to close the file.
  cluster.shutdownNameNode(0);
  Thread closeThread = new CloseThread(out, file, clientName);
  closeThread.start();
  Thread.sleep(CLOSE_FILE_TIMEOUT / 4);

  // Restart the namenode and verify the close file worked.
  if (!waitSafeMode) {
    cluster.restartNameNode(0, new String[]{}, false);
    cluster.getNameNode().setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  } else {
    cluster.restartNameNode(0);
  }
  closeThread.join(5000);
  assertTrue(pass);
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:28,代码来源:TestCloseFile.java


示例9: setUpBeforeClass

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf = new Configuration();
  conf.setInt("dfs.block.size", 1024);
  conf.setFloat("dfs.safemode.threshold.pct", 1.5f);
  cluster = new MiniDFSCluster(conf, 1, true, null, false);
  cluster.getNameNode().setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  fs = cluster.getFileSystem();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:10,代码来源:TestRbwReportSafeMode.java


示例10: testTxIdPersistence

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Test
public void testTxIdPersistence() throws Exception {
  Configuration conf = getConf();
  MiniDFSCluster cluster = new MiniDFSCluster(conf, 0, true, null);
  cluster.waitActive();
  FSNamesystem fsn = cluster.getNameNode().getNamesystem();

  try {
    // We have a BEGIN_LOG_SEGMENT txn to start
    assertEquals(0, fsn.getEditLog().getLastWrittenTxId());
    doAnEdit(fsn, 1);
    assertEquals(1, fsn.getEditLog().getLastWrittenTxId());
    
    fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fsn.saveNamespace(false, false);

    // 2 more txns: END the first segment, BEGIN a new one
    assertEquals(3, fsn.getEditLog().getLastWrittenTxId());
    
    // Shut down and restart
    fsn.getFSImage().close();
    fsn.close();
    
    // 1 more txn to END that segment
    assertEquals(4, fsn.getEditLog().getLastWrittenTxId());
    fsn = null;
    
    cluster = new MiniDFSCluster(conf, 0, false, null);
    cluster.waitActive();
    fsn = cluster.getNameNode().getNamesystem();
    
    // 1 more txn to start new segment on restart
    assertEquals(5, fsn.getEditLog().getLastWrittenTxId());
    
  } finally {
    if (fsn != null) {
      fsn.close();
    }
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:41,代码来源:TestSaveNamespace.java


示例11: checkNameSpace

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
private void checkNameSpace(Configuration conf) throws IOException {
  NameNode namenode = new NameNode(conf);
  assertTrue(namenode.getFileInfo("/test").isDir());
  namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
  namenode.saveNamespace(false, false);
  namenode.stop();
  namenode.join();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:9,代码来源:TestStartup.java


示例12: setSafeMode

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Override
public boolean setSafeMode(final SafeModeAction action) throws IOException {
  return (failoverHandler.new MutableFSCaller<Boolean>() {
    public Boolean call(int r) throws IOException {
      return namenode.setSafeMode(action);
    }
  }).callFS();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:9,代码来源:FailoverClientProtocol.java


示例13: testDatanodeThreshold

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
/**
 * Verify that the NameNode stays in safemode when dfs.safemode.datanode.min
 * is set to a number greater than the number of live datanodes.
 */
@Test
public void testDatanodeThreshold() throws IOException {
  MiniDFSCluster cluster = null;
  DistributedFileSystem fs = null;
  try {
    Configuration conf = new Configuration();
    conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 0);
    conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY, 1);

    // bring up a cluster with no datanodes
    cluster = new MiniDFSCluster(conf, 0, true, null);
    cluster.waitActive();
    fs = (DistributedFileSystem)cluster.getFileSystem();

    assertTrue("No datanode started, but we require one - safemode expected",
               fs.setSafeMode(SafeModeAction.SAFEMODE_GET));

    String tipMsg = cluster.getNameNode().getNamesystem().getSafeModeTip();
    assertTrue("Safemode tip message looks right",
               tipMsg.contains("The number of live datanodes 0 needs an " +
                               "additional 1 live"));

    // Start a datanode
    cluster.startDataNodes(conf, 1, true, null, null);

    // Wait long enough for safemode check to refire
    try {
      Thread.sleep(1000);
    } catch (InterruptedException ignored) {}

    // We now should be out of safe mode.
    assertFalse(
      "Out of safe mode after starting datanode.",
      fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
  } finally {
    if (fs != null) fs.close();
    if (cluster != null) cluster.shutdown();
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:44,代码来源:TestSafeMode.java


示例14: testDNShouldNotSendBBWReportIfAppendOff

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Test
public void testDNShouldNotSendBBWReportIfAppendOff() throws Exception {
  FileSystem fileSystem = null;
  FSDataOutputStream outStream = null;
  // disable the append support
  conf.setBoolean("dfs.support.append", false);
  MiniDFSCluster cluster = new MiniDFSCluster(conf, 1, true, null);
  cluster.waitActive();
  try {
    fileSystem = cluster.getFileSystem();
    // Keep open stream
    outStream = writeFileAndSync(fileSystem, src, fileContent);
    cluster.restartNameNode(false);
    Thread.sleep(2000);
    assertEquals(
        "Able to read the synced block content after NameNode restart (without append support",
        0, getFileContentFromDFS(fileSystem).length());
  } finally {
    // NN will not come out of safe mode. So exited the safemode forcibly to
    // clean the resources.
    cluster.getNameNode().setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
    if (null != fileSystem)
      fileSystem.close();
    if (null != outStream)
      outStream.close();
    cluster.shutdown();
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:29,代码来源:TestBBWBlockReport.java


示例15: testSaveWhileEditsRolled

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
public void testSaveWhileEditsRolled() throws Exception {
  Configuration conf = getConf();
  NameNode.format(conf);
  NameNode nn = new NameNode(conf);
  FSNamesystem fsn = nn.getNamesystem();

  // Replace the FSImage with a spy
  final FSImage originalImage = fsn.dir.fsImage;
  FSImage spyImage = spy(originalImage);
  fsn.dir.fsImage = spyImage;

  try {
    doAnEdit(fsn, 1);
    CheckpointSignature sig = fsn.rollEditLog();
    LOG.warn("Checkpoint signature: " + sig);
    // Do another edit
    doAnEdit(fsn, 2);

    // Save namespace
    fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fsn.saveNamespace();

    // Now shut down and restart the NN
    nn.stop();
    nn = null;

    // Start a new namesystem, which should be able to recover
    // the namespace from the previous incarnation.
    nn = new NameNode(conf);
    fsn = nn.getNamesystem();

    // Make sure the image loaded including our edits.
    checkEditExists(fsn, 1);
    checkEditExists(fsn, 2);
  } finally {
    if (nn != null) {
      nn.stop();
    }
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:41,代码来源:TestSaveNamespace.java


示例16: isHealthy

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
/**
 * Is the HDFS healthy?
 * HDFS is considered as healthy if it is up and not in safemode.
 *
 * @param uri the HDFS URI.  Note that the URI path is ignored.
 * @return true if HDFS is healthy; false, otherwise.
 */
public static boolean isHealthy(URI uri) {
  //check scheme
  final String scheme = uri.getScheme();
  if (!"hdfs".equalsIgnoreCase(scheme)) {
    throw new IllegalArgumentException("This scheme is not hdfs, uri=" + uri);
  }
  
  final Configuration conf = new Configuration();
  //disable FileSystem cache
  conf.setBoolean(String.format("fs.%s.impl.disable.cache", scheme), true);
  //disable client retry for rpc connection and rpc calls
  conf.setBoolean(DFSConfigKeys.DFS_CLIENT_RETRY_POLICY_ENABLED_KEY, false);
  conf.setInt(Client.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);

  DistributedFileSystem fs = null;
  try {
    fs = (DistributedFileSystem)FileSystem.get(uri, conf);
    final boolean safemode = fs.setSafeMode(SafeModeAction.SAFEMODE_GET);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Is namenode in safemode? " + safemode + "; uri=" + uri);
    }

    fs.close();
    fs = null;
    return !safemode;
  } catch(IOException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Got an exception for uri=" + uri, e);
    }
    return false;
  } finally {
    IOUtils.cleanup(LOG, fs);
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:42,代码来源:DistributedFileSystem.java


示例17: testManualSafeMode

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
/**
 * This test verifies that if SafeMode is manually entered, name-node does not
 * come out of safe mode even after the startup safe mode conditions are met.
 * <ol>
 * <li>Start cluster with 1 data-node.</li>
 * <li>Create 2 files with replication 1.</li>
 * <li>Re-start cluster with 0 data-nodes. 
 * Name-node should stay in automatic safe-mode.</li>
 * <li>Enter safe mode manually.</li>
 * <li>Start the data-node.</li>
 * <li>Wait longer than <tt>dfs.safemode.extension</tt> and 
 * verify that the name-node is still in safe mode.</li>
 * </ol>
 *  
 * @throws IOException
 */
@Test
public void testManualSafeMode() throws IOException {      
  fs = (DistributedFileSystem)cluster.getFileSystem();
  Path file1 = new Path("/tmp/testManualSafeMode/file1");
  Path file2 = new Path("/tmp/testManualSafeMode/file2");
  
  // create two files with one block each.
  DFSTestUtil.createFile(fs, file1, 1000, (short)1, 0);
  DFSTestUtil.createFile(fs, file2, 2000, (short)1, 0);
  fs.close();
  cluster.shutdown();
  
  // now bring up just the NameNode.
  cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).format(false).build();
  cluster.waitActive();
  dfs = (DistributedFileSystem)cluster.getFileSystem();
  
  assertTrue("No datanode is started. Should be in SafeMode", 
             dfs.setSafeMode(SafeModeAction.SAFEMODE_GET));
  
  // manually set safemode.
  dfs.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();
  
  // wait longer than dfs.namenode.safemode.extension
  try {
    Thread.sleep(2000);
  } catch (InterruptedException ignored) {}

  assertTrue("should still be in SafeMode",
      dfs.setSafeMode(SafeModeAction.SAFEMODE_GET));
  assertFalse("should not be in SafeMode", 
      dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE));
}
 
开发者ID:cumulusyebl,项目名称:cumulus,代码行数:54,代码来源:TestSafeMode.java


示例18: checkNameSpace

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
private void checkNameSpace(Configuration conf) throws IOException {
  NameNode namenode = new NameNode(conf);
  assertTrue(namenode.getFileInfo("/test").isDir());
  namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
  namenode.saveNamespace();
  namenode.stop();
  namenode.join();
}
 
开发者ID:cumulusyebl,项目名称:cumulus,代码行数:9,代码来源:TestStartup.java


示例19: setSafeMode

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
@Override
public boolean setSafeMode(final SafeModeAction action) throws IOException {
  return (new MutableFSCaller<Boolean>() {
    Boolean call(int r) throws IOException {
      return namenode.setSafeMode(action);
    }
  }).callFS();
}
 
开发者ID:iVCE,项目名称:RDFS,代码行数:9,代码来源:DistributedAvatarFileSystem.java


示例20: replicationTest

import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; //导入依赖的package包/类
void replicationTest(int badDN) throws Exception {
  LOG.info("START");
  cluster = new MiniDFSCluster(conf, 3, true, null);
  FileSystem fs1 = cluster.getFileSystem();
  try {
    int halfBlock = (int)BLOCK_SIZE/2;
    short rep = 3; // replication
    assertTrue(BLOCK_SIZE%4 == 0);

    file1 = new Path("/appendWithReplication.dat");

    // write 1/2 block & sync
    stm = fs1.create(file1, true, (int)BLOCK_SIZE*2, rep, BLOCK_SIZE);
    AppendTestUtil.write(stm, 0, halfBlock);
    stm.sync();
    assertNumCurrentReplicas(rep);

    // close one of the datanodes
    cluster.stopDataNode(badDN);

    // write 1/4 block & sync
    AppendTestUtil.write(stm, halfBlock, (int)BLOCK_SIZE/4);
    stm.sync();
    assertNumCurrentReplicas((short)(rep - 1));

    // restart the cluster
    /*
     * we put the namenode in safe mode first so he doesn't process
     * recoverBlock() commands from the remaining DFSClient as datanodes
     * are serially shutdown
     */
    cluster.getNameNode().setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs1.close();
    cluster.shutdown();
    LOG.info("STOPPED first instance of the cluster");
    cluster = new MiniDFSCluster(conf, 3, false, null);
    cluster.getNameNode().getNamesystem().stallReplicationWork();
    cluster.waitActive();
    fs1 = cluster.getFileSystem();
    LOG.info("START second instance.");

    recoverFile(fs1);
    LOG.info("Recovered file");

    // the 2 DNs with the larger sequence number should win
    BlockLocation[] bl = fs1.getFileBlockLocations(
        fs1.getFileStatus(file1), 0, BLOCK_SIZE);
    LOG.info("Checking blocks");
    assertTrue("Should have one block", bl.length == 1);

    // Wait up to 1 second for block replication - we may have
    // only replication 1 for a brief moment after close, since
    // closing only waits for fs.replcation.min replicas, and
    // it may take some millis before the other DN reports block
    waitForBlockReplication(fs1, file1.toString(), 2, 1);

    assertFileSize(fs1, BLOCK_SIZE*3/4);
    checkFile(fs1, BLOCK_SIZE*3/4);

    LOG.info("Checking replication");
    // verify that, over time, the block has been replicated to 3 DN
    cluster.getNameNode().getNamesystem().restartReplicationWork();
    waitForBlockReplication(fs1, file1.toString(), 3, 20);
  } finally {
    fs1.close();
    cluster.shutdown();
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:69,代码来源:TestFileAppend4.java



注:本文中的org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WithSecurityContext类代码示例发布时间:2022-05-23
下一篇:
Java Dictionary类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap