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


Java DatanodeInfo.setDecommissioned方法代码示例

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


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

示例1: testWhenSomeNodesAreNotGood

import org.apache.hadoop.hdfs.protocol.DatanodeInfo; //导入方法依赖的package包/类
@Test(timeout=180000)
public void testWhenSomeNodesAreNotGood() throws Exception {
  // 4 favored nodes
  final InetSocketAddress addrs[] = new InetSocketAddress[4];
  final String[] hosts = new String[addrs.length];
  for (int i = 0; i < addrs.length; i++) {
    addrs[i] = datanodes.get(i).getXferAddress();
    hosts[i] = addrs[i].getAddress().getHostAddress() + ":" + addrs[i].getPort();
  }

  //make some datanode not "good" so that even if the client prefers it,
  //the namenode would not give it as a replica to write to
  DatanodeInfo d = cluster.getNameNode().getNamesystem().getBlockManager()
         .getDatanodeManager().getDatanodeByXferAddr(
             addrs[0].getAddress().getHostAddress(), addrs[0].getPort());
  //set the decommission status to true so that 
  //BlockPlacementPolicyDefault.isGoodTarget returns false for this dn
  d.setDecommissioned();
  Path p = new Path("/filename-foo-bar-baz");
  final short replication = (short)3;
  FSDataOutputStream out = dfs.create(p, FsPermission.getDefault(), true,
      4096, replication, 4096L, null, addrs);
  out.write(SOME_BYTES);
  out.close();
  //reset the state
  d.stopDecommission();

  BlockLocation[] locations = getBlockLocations(p);
  Assert.assertEquals(replication, locations[0].getNames().length);;
  //also make sure that the datanode[0] is not in the list of hosts
  for (int i = 0; i < replication; i++) {
    final String loc = locations[0].getNames()[i];
    int j = 0;
    for(; j < hosts.length && !loc.equals(hosts[j]); j++);
    Assert.assertTrue("j=" + j, j > 0);
    Assert.assertTrue("loc=" + loc + " not in host list "
        + Arrays.asList(hosts) + ", j=" + j, j < hosts.length);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:TestFavoredNodesEndToEnd.java


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