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


Java DistributedFileSystem.listLocatedStatus方法代码示例

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


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

示例1: testDecommissionStatusAfterDNRestart

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
/**
 * Verify a DN remains in DECOMMISSION_INPROGRESS state if it is marked
 * as dead before decommission has completed. That will allow DN to resume
 * the replication process after it rejoins the cluster.
 */
@Test(timeout=120000)
public void testDecommissionStatusAfterDNRestart() throws Exception {
  DistributedFileSystem fileSys =
      (DistributedFileSystem)cluster.getFileSystem();

  // Create a file with one block. That block has one replica.
  Path f = new Path("decommission.dat");
  DFSTestUtil.createFile(fileSys, f, fileSize, fileSize, fileSize,
      (short)1, seed);

  // Find the DN that owns the only replica.
  RemoteIterator<LocatedFileStatus> fileList = fileSys.listLocatedStatus(f);
  BlockLocation[] blockLocations = fileList.next().getBlockLocations();
  String dnName = blockLocations[0].getNames()[0];

  // Decommission the DN.
  FSNamesystem fsn = cluster.getNamesystem();
  final DatanodeManager dm = fsn.getBlockManager().getDatanodeManager();
  decommissionNode(fsn, localFileSys, dnName);
  dm.refreshNodes(conf);

  // Stop the DN when decommission is in progress.
  // Given DFS_DATANODE_BALANCE_BANDWIDTHPERSEC_KEY is to 1 and the size of
  // the block, it will take much longer time that test timeout value for
  // the decommission to complete. So when stopDataNode is called,
  // decommission should be in progress.
  DataNodeProperties dataNodeProperties = cluster.stopDataNode(dnName);
  final List<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>();
  while (true) {
    dm.fetchDatanodes(null, dead, false);
    if (dead.size() == 1) {
      break;
    }
    Thread.sleep(1000);
  }

  // Force removal of the dead node's blocks.
  BlockManagerTestUtil.checkHeartbeat(fsn.getBlockManager());

  // Force DatanodeManager to check decommission state.
  BlockManagerTestUtil.recheckDecommissionState(dm);

  // Verify that the DN remains in DECOMMISSION_INPROGRESS state.
  assertTrue("the node should be DECOMMISSION_IN_PROGRESSS",
      dead.get(0).isDecommissionInProgress());

  // Check DatanodeManager#getDecommissionNodes, make sure it returns
  // the node as decommissioning, even if it's dead
  List<DatanodeDescriptor> decomlist = dm.getDecommissioningNodes();
  assertTrue("The node should be be decommissioning", decomlist.size() == 1);
  
  // Delete the under-replicated file, which should let the 
  // DECOMMISSION_IN_PROGRESS node become DECOMMISSIONED
  cleanupFile(fileSys, f);
  BlockManagerTestUtil.recheckDecommissionState(dm);
  assertTrue("the node should be decommissioned",
      dead.get(0).isDecommissioned());

  // Add the node back
  cluster.restartDataNode(dataNodeProperties, true);
  cluster.waitActive();

  // Call refreshNodes on FSNamesystem with empty exclude file.
  // This will remove the datanodes from decommissioning list and
  // make them available again.
  writeConfigFile(localFileSys, excludeFile, null);
  dm.refreshNodes(conf);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:74,代码来源:TestDecommissioningStatus.java


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