Package org.apache.hadoop.hdfs.protocol

Examples of org.apache.hadoop.hdfs.protocol.LocatedBlockWithMetaInfo


    }
    long serverVersion = ClientProtocol.versionID;
    int serverFpFromNn = ProtocolSignature.getFingerprint(ProtocolSignature.getProtocolSignature(
        0, serverVersion, inter).getMethods());
   
    LocatedBlockWithMetaInfo loc = client.namenode.addBlockAndFetchMetaInfo("/testNameNodeFingerprintSent.txt",
        client.getClientName(), null, 0L);
   
    int serverFp = loc.getMethodFingerPrint();
    TestCase.assertEquals(serverFpFromNn, serverFp);   

    FileSystem fs = cluster.getFileSystem();
    Path f = new Path("/testNameNodeFingerprintSent1.txt");
    DataOutputStream a_out = fs.create(f);
View Full Code Here


      FakeBlockAndDatanodeResolver resolver = new FakeBlockAndDatanodeResolver();
      long blockId = 0;
      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (DatanodeInfo d : sourceLocations) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), new DatanodeInfo[]{d}, 0L,
            0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
        srcInfoList.add(info);
        resolver.addBlock(info, lb);
        resolver.addNode(d.getName(), d);
      }
      List<LocatedBlock> parityBlockList = new LinkedList<LocatedBlock>();
      List<BlockInfo> parityInfoList = new LinkedList<BlockInfo>();
      for (DatanodeInfo d : parityLocations) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), new DatanodeInfo[]{d}, 0L,
            0, 0, 0);
        parityBlockList.add(lb);
        BlockInfo info = createBlockInfo(parityStat, lb);
        parityInfoList.add(info);
View Full Code Here

      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (int i = 0; i < sourceLocations.length; i+=2) {
        DatanodeInfo d = sourceLocations[i];
        DatanodeInfo d1 = sourceLocations[i+1];
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId, 0, 0L), new DatanodeInfo[]{d, d1}, 0L,
            0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
        srcInfoList.add(info);
        resolver.addBlock(info, lb);
        resolver.addNode(d.getName(), d);
        resolver.addNode(d1.getName(), d1);
       
        List<DatanodeInfo> dnList = new ArrayList<DatanodeInfo>();
        dnList.add(d);
        dnList.add(d1);
        blockLocations.put(String.valueOf(blockId), dnList);
        ++ blockId;
      }
      List<LocatedBlock> parityBlockList = new LinkedList<LocatedBlock>();
      List<BlockInfo> parityInfoList = new LinkedList<BlockInfo>();
      for (int i = 0; i < parityLocations.length; i+=2) {
        DatanodeInfo d = parityLocations[i];
        DatanodeInfo d1 = parityLocations[i+1];
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId, 0, 0L), new DatanodeInfo[]{d, d1}, 0L,
            0, 0, 0);
        parityBlockList.add(lb);
        BlockInfo info = createBlockInfo(parityStat, lb);
        parityInfoList.add(info);
        resolver.addBlock(info, lb);
        resolver.addNode(d.getName(), d);
        resolver.addNode(d1.getName(), d1);
        List<DatanodeInfo> dnList = new ArrayList<DatanodeInfo>();
        dnList.add(d);
        dnList.add(d1);
        blockLocations.put(String.valueOf(blockId), dnList);
        ++ blockId;
      }
      fakeBlockMover.setBlockLocations(blockLocations);
      placementMonitor.checkBlockLocations(
          srcInfoList, parityInfoList, Codec.getCodec("xor"), xorPolicy,
          srcStat, resolver);
      for (BlockMover.BlockMoveAction action :
        fakeBlockMover.getSubmittedActions()) {
        LOG.info("Block move:" + action);
      }
      Set<Block> movedBlocks = new HashSet<Block>();
      for (BlockMover.BlockMoveAction action :
          fakeBlockMover.getSubmittedActions()) {
        movedBlocks.add(action.block.getBlock());
      }
      Map<Integer, Long> hist =
          placementMonitor.blockHistograms.get("xor");
      Assert.assertEquals(3, hist.size());
      Assert.assertEquals(3, hist.get(0).longValue());
      Assert.assertEquals(2, hist.get(1).longValue());
      Assert.assertEquals(3, hist.get(2).longValue());
     
      // since each node is on different rack, the rack histogram should
      // be the same the one for nodes.
      Map<Integer, Long> histRack =
          placementMonitor.blockHistogramsPerRack.get("xor");
      Assert.assertEquals(3, histRack.size());
      Assert.assertEquals(3, histRack.get(0).longValue());
      Assert.assertEquals(2, histRack.get(1).longValue());
      Assert.assertEquals(3, histRack.get(2).longValue());
     

      // Note that the first block will stay.
      Assert.assertEquals(8, fakeBlockMover.getSubmittedActions().size());
      Assert.assertEquals(6, movedBlocks.size());
      Assert.assertTrue(movedBlocks.contains(new Block(1L, 0, 0L)));
      Assert.assertTrue(movedBlocks.contains(new Block(2L, 0, 0L)));
      Assert.assertTrue(movedBlocks.contains(new Block(4L, 0, 0L)));
      Assert.assertTrue(movedBlocks.contains(new Block(5L, 0, 0L)));
      Assert.assertTrue(movedBlocks.contains(new Block(6L, 0, 0L)));
      Assert.assertTrue(movedBlocks.contains(new Block(7L, 0, 0L)));
     
      fakeBlockMover.clearActions();
      resolver = new FakeBlockAndDatanodeResolver();
      // rebuild the block infos
      srcInfoList = new LinkedList<BlockInfo>();
      for (LocatedBlock srcBlock : srcBlockList) {
        List<DatanodeInfo> replicaNodes = blockLocations.get(
            String.valueOf(srcBlock.getBlock().getBlockId()));
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(srcBlock.getBlock().getBlockId(), 0, 0L),
            replicaNodes.toArray(new DatanodeInfo[]{}),
            0L, 0, 0, 0);
       
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcInfoList.add(info);
        resolver.addBlock(info, lb);
        for (DatanodeInfo d : replicaNodes) {
          resolver.addNode(d.getName(), d);
        }
      }
     
      parityInfoList = new LinkedList<BlockInfo>();
      for (LocatedBlock parityBlock : parityBlockList) {
        List<DatanodeInfo> replicaNodes = blockLocations.get(
            String.valueOf(parityBlock.getBlock().getBlockId()));
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(parityBlock.getBlock().getBlockId(), 0, 0L),
            replicaNodes.toArray(new DatanodeInfo[]{}),
            0L, 0, 0, 0);
       
        BlockInfo info = createBlockInfo(srcStat, lb);
View Full Code Here

      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (int i = 0; i < sourceLocations.length; i+=2) {
        DatanodeInfo d = sourceLocations[i];
        DatanodeInfo d1 = sourceLocations[i+1];
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), new DatanodeInfo[]{d, d1}, 0L,
            0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
        srcInfoList.add(info);
        resolver.addBlock(info, lb);
        resolver.addNode(d.getName(), d);
        resolver.addNode(d1.getName(), d1);
      }
      List<LocatedBlock> parityBlockList = new LinkedList<LocatedBlock>();
      List<BlockInfo> parityInfoList = new LinkedList<BlockInfo>();
      for (int i = 0; i < parityLocations.length; i+=2) {
        DatanodeInfo d = parityLocations[i];
        DatanodeInfo d1 = parityLocations[i+1];
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), new DatanodeInfo[]{d, d1}, 0L,
            0, 0, 0);
        parityBlockList.add(lb);
        BlockInfo info = createBlockInfo(parityStat, lb);
        parityInfoList.add(info);
View Full Code Here

      FakeBlockAndDatanodeResolver resolver = new FakeBlockAndDatanodeResolver();
      long blockId = 0;
      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (DatanodeInfo[] datanodeInfos : sourceLocations) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), datanodeInfos, 0L,
            0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
        srcInfoList.add(info);
        resolver.addBlock(info, lb);
        for (DatanodeInfo d : datanodeInfos) {
          resolver.addNode(d.getName(), d);
        }
      }
      List<LocatedBlock> parityBlockList = new LinkedList<LocatedBlock>();
      List<BlockInfo> parityInfoList = new LinkedList<BlockInfo>();
      for (DatanodeInfo[] datanodeInfos : parityLocations) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), datanodeInfos, 0L,
            0, 0, 0);
        parityBlockList.add(lb);
        BlockInfo info = createBlockInfo(parityStat, lb);
        parityInfoList.add(info);
View Full Code Here

      FakeBlockAndDatanodeResolver resolver = new FakeBlockAndDatanodeResolver();
      long blockId = 0;
      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (int i = 0; i < srcLocations.length; i+=3) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L),
            new DatanodeInfo[] {srcLocations[i], srcLocations[i+1], srcLocations[i+2]},
            0L, 0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
View Full Code Here

      FakeBlockAndDatanodeResolver resolver = new FakeBlockAndDatanodeResolver();
      long blockId = 0;
      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (int i = 0; i < srcLocations.length; i+=3) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L),
            new DatanodeInfo[] {srcLocations[i], srcLocations[i+1], srcLocations[i+2]},
            0L, 0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
View Full Code Here

      FakeBlockAndDatanodeResolver resolver = new FakeBlockAndDatanodeResolver();
      long blockId = 0;
      List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
      List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
      for (DatanodeInfo d : sourceLocations) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), new DatanodeInfo[]{d}, 0L,
            0, 0, 0);
        BlockInfo info = createBlockInfo(srcStat, lb);
        srcBlockList.add(lb);
        srcInfoList.add(info);
        resolver.addBlock(info, lb);
        resolver.addNode(d.getName(), d);
      }
      List<LocatedBlock> parityBlockList = new LinkedList<LocatedBlock>();
      List<BlockInfo> parityInfoList = new LinkedList<BlockInfo>();
      for (DatanodeInfo d : parityLocations) {
        LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
            new Block(blockId++, 0, 0L), new DatanodeInfo[]{d}, 0L,
            0, 0, 0);
        parityBlockList.add(lb);
        BlockInfo info = createBlockInfo(parityStat, lb);
        parityInfoList.add(info);
View Full Code Here

      List<LocatedBlock> lb = locatedBlocks.getLocatedBlocks();
     
      for (LocatedBlock b : lb) {
        if (decomBlockHashes.get(b.getBlock().hashCode()) != null) {
          blocks.add(new LocatedBlockWithMetaInfo(b.getBlock(),
              b.getLocations(), b.getStartOffset(),
              dataTransferVersion, namespaceId, methodsFingerprint));
        }
      }
     
View Full Code Here

      // get data node
      DataNode datanode = cluster.getDataNode(nodes[0].getIpcPort());
      assertTrue(datanode != null);

      // verifies checksum file is of length 0
      LocatedBlockWithMetaInfo locatedblock = TestInterDatanodeProtocol
          .getLastLocatedBlock(dfs.dfs.namenode, filestr);
      Block lastblock = locatedblock.getBlock();
      DataNode.LOG.info("newblocks=" + lastblock);
      BlockPathInfo blockPathInfo = datanode.getBlockPathInfo(lastblock);
      String blockPath = blockPathInfo.getBlockPath();
      String metaPath = blockPathInfo.getMetaPath();

      File f = new File(blockPath);
      File meta = new File(metaPath);
      assertEquals(0, f.length());
      // set the checksum file to 0
      meta.delete();
      DataOutputStream outs = new DataOutputStream(new FileOutputStream(
          metaPath, false));
      outs.close();

      // issue recovery and makit e sure it succeeds.
      int numTries = 500;
      for (int idxTry = 0; idxTry < numTries; idxTry++) {
        boolean success = dfs.recoverLease(filepath);
        if (success) {
          break;
        } else if (idxTry == numTries - 1) {
          TestCase.fail("Recovery lease failed");
        } else {
          Thread.sleep(10);
        }
      }

      // make sure the meta file is still empty
      locatedblock = TestInterDatanodeProtocol.getLastLocatedBlock(
          dfs.dfs.namenode, filestr);
      Block newBlock = locatedblock.getBlock();
      blockPathInfo = datanode.getBlockPathInfo(newBlock);
      assertEquals(0, blockPathInfo.getNumBytes());
      metaPath = blockPathInfo.getMetaPath();
      meta = new File(metaPath);
      assertEquals(0, meta.length());
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.protocol.LocatedBlockWithMetaInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.