當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。