Search in sources :

Example 6 with BlockLocalPathInfo

use of org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo in project hadoop by apache.

the class TestBlockReaderLocalLegacy method testBlockReaderLocalLegacyWithAppend.

@Test(timeout = 20000)
public void testBlockReaderLocalLegacyWithAppend() throws Exception {
    final short REPL_FACTOR = 1;
    final HdfsConfiguration conf = getConfiguration(null);
    conf.setBoolean(HdfsClientConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL, true);
    final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
    cluster.waitActive();
    final DistributedFileSystem dfs = cluster.getFileSystem();
    final Path path = new Path("/testBlockReaderLocalLegacy");
    DFSTestUtil.createFile(dfs, path, 10, REPL_FACTOR, 0);
    DFSTestUtil.waitReplication(dfs, path, REPL_FACTOR);
    final ClientDatanodeProtocol proxy;
    final Token<BlockTokenIdentifier> token;
    final ExtendedBlock originalBlock;
    final long originalGS;
    {
        final LocatedBlock lb = cluster.getNameNode().getRpcServer().getBlockLocations(path.toString(), 0, 1).get(0);
        proxy = DFSUtilClient.createClientDatanodeProtocolProxy(lb.getLocations()[0], conf, 60000, false);
        token = lb.getBlockToken();
        // get block and generation stamp
        final ExtendedBlock blk = new ExtendedBlock(lb.getBlock());
        originalBlock = new ExtendedBlock(blk);
        originalGS = originalBlock.getGenerationStamp();
        // test getBlockLocalPathInfo
        final BlockLocalPathInfo info = proxy.getBlockLocalPathInfo(blk, token);
        Assert.assertEquals(originalGS, info.getBlock().getGenerationStamp());
    }
    {
        // append one byte
        FSDataOutputStream out = dfs.append(path);
        out.write(1);
        out.close();
    }
    {
        // get new generation stamp
        final LocatedBlock lb = cluster.getNameNode().getRpcServer().getBlockLocations(path.toString(), 0, 1).get(0);
        final long newGS = lb.getBlock().getGenerationStamp();
        Assert.assertTrue(newGS > originalGS);
        // getBlockLocalPathInfo using the original block.
        Assert.assertEquals(originalGS, originalBlock.getGenerationStamp());
        final BlockLocalPathInfo info = proxy.getBlockLocalPathInfo(originalBlock, token);
        Assert.assertEquals(newGS, info.getBlock().getGenerationStamp());
    }
    cluster.shutdown();
}
Also used : Path(org.apache.hadoop.fs.Path) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) ExtendedBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) ClientDatanodeProtocol(org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol) BlockTokenIdentifier(org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier) BlockLocalPathInfo(org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Test(org.junit.Test)

Example 7 with BlockLocalPathInfo

use of org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo in project hadoop by apache.

the class TestDataNodeRollingUpgrade method getBlockForFile.

/** Test assumes that the file has a single block */
private File getBlockForFile(Path path, boolean exists) throws IOException {
    LocatedBlocks blocks = nn.getRpcServer().getBlockLocations(path.toString(), 0, Long.MAX_VALUE);
    assertEquals("The test helper functions assume that each file has a single block", 1, blocks.getLocatedBlocks().size());
    ExtendedBlock block = blocks.getLocatedBlocks().get(0).getBlock();
    BlockLocalPathInfo bInfo = dn0.getFSDataset().getBlockLocalPathInfo(block);
    File blockFile = new File(bInfo.getBlockPath());
    assertEquals(exists, blockFile.exists());
    return blockFile;
}
Also used : LocatedBlocks(org.apache.hadoop.hdfs.protocol.LocatedBlocks) ExtendedBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock) BlockLocalPathInfo(org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo) File(java.io.File)

Aggregations

BlockLocalPathInfo (org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo)7 File (java.io.File)3 IOException (java.io.IOException)3 ClientDatanodeProtocol (org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol)2 ExtendedBlock (org.apache.hadoop.hdfs.protocol.ExtendedBlock)2 ServiceException (com.google.protobuf.ServiceException)1 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 ShortCircuitConf (org.apache.hadoop.hdfs.client.impl.DfsClientConf.ShortCircuitConf)1 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)1 LocatedBlocks (org.apache.hadoop.hdfs.protocol.LocatedBlocks)1 GetBlockLocalPathInfoRequestProto (org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetBlockLocalPathInfoRequestProto)1 GetBlockLocalPathInfoResponseProto (org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetBlockLocalPathInfoResponseProto)1 BlockTokenIdentifier (org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier)1 Replica (org.apache.hadoop.hdfs.server.datanode.Replica)1