当前位置: 首页>>代码示例>>Java>>正文


Java NameNodeAdapter.getSafeModeSafeBlocks方法代码示例

本文整理汇总了Java中org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter.getSafeModeSafeBlocks方法的典型用法代码示例。如果您正苦于以下问题:Java NameNodeAdapter.getSafeModeSafeBlocks方法的具体用法?Java NameNodeAdapter.getSafeModeSafeBlocks怎么用?Java NameNodeAdapter.getSafeModeSafeBlocks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter的用法示例。


在下文中一共展示了NameNodeAdapter.getSafeModeSafeBlocks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInitializeReplQueuesEarly

import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; //导入方法依赖的package包/类
/**
 * Test that the NN initializes its under-replicated blocks queue
 * before it is ready to exit safemode (HDFS-1476)
 */
@Test(timeout=45000)
public void testInitializeReplQueuesEarly() throws Exception {
  LOG.info("Starting testInitializeReplQueuesEarly");
  // Spray the blocks around the cluster when we add DNs instead of
  // concentrating all blocks on the first node.
  BlockManagerTestUtil.setWritingPrefersLocalNode(
      cluster.getNamesystem().getBlockManager(), false);
  
  cluster.startDataNodes(conf, 2, true, StartupOption.REGULAR, null);
  cluster.waitActive();

  LOG.info("Creating files");
  DFSTestUtil.createFile(fs, TEST_PATH, 15*BLOCK_SIZE, (short)1, 1L);
  
  LOG.info("Stopping all DataNodes");
  List<DataNodeProperties> dnprops = Lists.newLinkedList();
  dnprops.add(cluster.stopDataNode(0));
  dnprops.add(cluster.stopDataNode(0));
  dnprops.add(cluster.stopDataNode(0));
  
  cluster.getConfiguration(0).setFloat(
      DFSConfigKeys.DFS_NAMENODE_REPL_QUEUE_THRESHOLD_PCT_KEY, 1f/15f);
  
  LOG.info("Restarting NameNode");
  cluster.restartNameNode();
  final NameNode nn = cluster.getNameNode();
  
  String status = nn.getNamesystem().getSafemode();
  assertEquals("Safe mode is ON. The reported blocks 0 needs additional " +
      "15 blocks to reach the threshold 0.9990 of total blocks 15." + NEWLINE +
      "The number of live datanodes 0 has reached the minimum number 0. " +
      "Safe mode will be turned off automatically once the thresholds " +
      "have been reached.", status);
  assertFalse("Mis-replicated block queues should not be initialized " +
      "until threshold is crossed",
      NameNodeAdapter.safeModeInitializedReplQueues(nn));
  
  LOG.info("Restarting one DataNode");
  cluster.restartDataNode(dnprops.remove(0));

  // Wait for block reports from all attached storages of
  // the restarted DN to come in.
  GenericTestUtils.waitFor(new Supplier<Boolean>() {
    @Override
    public Boolean get() {
      return getLongCounter("StorageBlockReportOps", getMetrics(NN_METRICS)) ==
          cluster.getStoragesPerDatanode();
    }
  }, 10, 10000);

  final int safe = NameNodeAdapter.getSafeModeSafeBlocks(nn);
  assertTrue("Expected first block report to make some blocks safe.", safe > 0);
  assertTrue("Did not expect first block report to make all blocks safe.", safe < 15);

  assertTrue(NameNodeAdapter.safeModeInitializedReplQueues(nn));

  // Ensure that UnderReplicatedBlocks goes up to 15 - safe. Misreplicated
  // blocks are processed asynchronously so this may take a few seconds.
  // Failure here will manifest as a test timeout.
  BlockManagerTestUtil.updateState(nn.getNamesystem().getBlockManager());
  long underReplicatedBlocks = nn.getNamesystem().getUnderReplicatedBlocks();
  while (underReplicatedBlocks != (15 - safe)) {
    LOG.info("UnderReplicatedBlocks expected=" + (15 - safe) +
             ", actual=" + underReplicatedBlocks);
    Thread.sleep(100);
    BlockManagerTestUtil.updateState(nn.getNamesystem().getBlockManager());
    underReplicatedBlocks = nn.getNamesystem().getUnderReplicatedBlocks();
  }
  
  cluster.restartDataNodes();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:76,代码来源:TestSafeMode.java

示例2: testInitializeReplQueuesEarly

import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; //导入方法依赖的package包/类
/**
 * Test that the NN initializes its under-replicated blocks queue
 * before it is ready to exit safemode (HDFS-1476)
 */
@Test(timeout=45000)
public void testInitializeReplQueuesEarly() throws Exception {
  LOG.info("Starting testInitializeReplQueuesEarly");
  // Spray the blocks around the cluster when we add DNs instead of
  // concentrating all blocks on the first node.
  BlockManagerTestUtil.setWritingPrefersLocalNode(
      cluster.getNamesystem().getBlockManager(), false);
  
  cluster.startDataNodes(conf, 2, true, StartupOption.REGULAR, null);
  cluster.waitActive();

  LOG.info("Creating files");
  DFSTestUtil.createFile(fs, TEST_PATH, 15*BLOCK_SIZE, (short)1, 1L);
  
  LOG.info("Stopping all DataNodes");
  List<DataNodeProperties> dnprops = Lists.newLinkedList();
  dnprops.add(cluster.stopDataNode(0));
  dnprops.add(cluster.stopDataNode(0));
  dnprops.add(cluster.stopDataNode(0));
  
  cluster.getConfiguration(0).setFloat(
      DFSConfigKeys.DFS_NAMENODE_REPL_QUEUE_THRESHOLD_PCT_KEY, 1f/15f);
  
  LOG.info("Restarting NameNode");
  cluster.restartNameNode();
  final NameNode nn = cluster.getNameNode();
  
  String status = nn.getNamesystem().getSafemode();
  assertEquals("Safe mode is ON. The reported blocks 0 needs additional " +
      "14 blocks to reach the threshold 0.9990 of total blocks 15." + NEWLINE +
      "The number of live datanodes 0 has reached the minimum number 0. " +
      "Safe mode will be turned off automatically once the thresholds " +
      "have been reached.", status);
  assertFalse("Mis-replicated block queues should not be initialized " +
      "until threshold is crossed",
      NameNodeAdapter.safeModeInitializedReplQueues(nn));
  
  LOG.info("Restarting one DataNode");
  cluster.restartDataNode(dnprops.remove(0));

  // Wait for block reports from all attached storages of
  // the restarted DN to come in.
  GenericTestUtils.waitFor(new Supplier<Boolean>() {
    @Override
    public Boolean get() {
      return getLongCounter("StorageBlockReportOps", getMetrics(NN_METRICS)) ==
          cluster.getStoragesPerDatanode();
    }
  }, 10, 10000);

  final long safe = NameNodeAdapter.getSafeModeSafeBlocks(nn);
  assertTrue("Expected first block report to make some blocks safe.", safe > 0);
  assertTrue("Did not expect first block report to make all blocks safe.", safe < 15);

  assertTrue(NameNodeAdapter.safeModeInitializedReplQueues(nn));

  // Ensure that UnderReplicatedBlocks goes up to 15 - safe. Misreplicated
  // blocks are processed asynchronously so this may take a few seconds.
  // Failure here will manifest as a test timeout.
  BlockManagerTestUtil.updateState(nn.getNamesystem().getBlockManager());
  long underReplicatedBlocks = nn.getNamesystem().getUnderReplicatedBlocks();
  while (underReplicatedBlocks != (15 - safe)) {
    LOG.info("UnderReplicatedBlocks expected=" + (15 - safe) +
             ", actual=" + underReplicatedBlocks);
    Thread.sleep(100);
    BlockManagerTestUtil.updateState(nn.getNamesystem().getBlockManager());
    underReplicatedBlocks = nn.getNamesystem().getUnderReplicatedBlocks();
  }
  
  cluster.restartDataNodes();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:76,代码来源:TestSafeMode.java


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