Search in sources :

Example 1 with CachedBlocksList

use of org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList in project hadoop by apache.

the class TestCachedBlocksList method testMultipleLists.

@Test(timeout = 60000)
public void testMultipleLists() {
    DatanodeDescriptor[] datanodes = new DatanodeDescriptor[] { new DatanodeDescriptor(new DatanodeID("127.0.0.1", "localhost", "abcd", 5000, 5001, 5002, 5003)), new DatanodeDescriptor(new DatanodeID("127.0.1.1", "localhost", "efgh", 6000, 6001, 6002, 6003)) };
    CachedBlocksList[] lists = new CachedBlocksList[] { datanodes[0].getPendingCached(), datanodes[0].getCached(), datanodes[1].getPendingCached(), datanodes[1].getCached(), datanodes[1].getPendingUncached() };
    final int NUM_BLOCKS = 8000;
    CachedBlock[] blocks = new CachedBlock[NUM_BLOCKS];
    for (int i = 0; i < NUM_BLOCKS; i++) {
        blocks[i] = new CachedBlock(i, (short) i, true);
    }
    Random r = new Random(654);
    for (CachedBlocksList list : lists) {
        testAddElementsToList(list, blocks);
    }
    for (CachedBlocksList list : lists) {
        testRemoveElementsFromList(r, list, blocks);
    }
}
Also used : DatanodeDescriptor(org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor) DatanodeID(org.apache.hadoop.hdfs.protocol.DatanodeID) CachedBlocksList(org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList) Random(java.util.Random) CachedBlock(org.apache.hadoop.hdfs.server.namenode.CachedBlock) Test(org.junit.Test)

Example 2 with CachedBlocksList

use of org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList in project hadoop by apache.

the class CacheManager method processCacheReportImpl.

private void processCacheReportImpl(final DatanodeDescriptor datanode, final List<Long> blockIds) {
    CachedBlocksList cached = datanode.getCached();
    cached.clear();
    CachedBlocksList cachedList = datanode.getCached();
    CachedBlocksList pendingCachedList = datanode.getPendingCached();
    for (Iterator<Long> iter = blockIds.iterator(); iter.hasNext(); ) {
        long blockId = iter.next();
        LOG.trace("Cache report from datanode {} has block {}", datanode, blockId);
        CachedBlock cachedBlock = new CachedBlock(blockId, (short) 0, false);
        CachedBlock prevCachedBlock = cachedBlocks.get(cachedBlock);
        // if it's not already there.
        if (prevCachedBlock != null) {
            cachedBlock = prevCachedBlock;
        } else {
            cachedBlocks.put(cachedBlock);
            LOG.trace("Added block {}  to cachedBlocks", cachedBlock);
        }
        // cached block list if it exists there.
        if (!cachedBlock.isPresent(cachedList)) {
            cachedList.add(cachedBlock);
            LOG.trace("Added block {} to CACHED list.", cachedBlock);
        }
        if (cachedBlock.isPresent(pendingCachedList)) {
            pendingCachedList.remove(cachedBlock);
            LOG.trace("Removed block {} from PENDING_CACHED list.", cachedBlock);
        }
    }
}
Also used : CachedBlocksList(org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList)

Aggregations

CachedBlocksList (org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList)2 Random (java.util.Random)1 DatanodeID (org.apache.hadoop.hdfs.protocol.DatanodeID)1 DatanodeDescriptor (org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor)1 CachedBlock (org.apache.hadoop.hdfs.server.namenode.CachedBlock)1 Test (org.junit.Test)1