Iterator<CachedBlock> it = datanode.getPendingCached().iterator(); while (it.hasNext()) { CachedBlock cBlock = it.next(); it = datanode.getPendingUncached().iterator(); blockInfo.getBlockId(), datanode.getDatanodeUuid()); pendingCached.add(datanode); boolean added = datanode.getPendingCached().add(cachedBlock); assert added;
private void processCacheReportImpl(final DatanodeDescriptor datanode, final List<Long> blockIds) { CachedBlocksList cached = datanode.getCached(); cached.clear(); CachedBlocksList cachedList = datanode.getCached(); CachedBlocksList pendingCachedList = datanode.getPendingCached(); cachedList.add(cachedBlock); LOG.trace("Added block {} to CACHED list.", cachedBlock); pendingCachedList.remove(cachedBlock); LOG.trace("Removed block {} from PENDING_CACHED list.", cachedBlock);
/** * Get a list of the datanodes which this block is cached, * planned to be cached, or planned to be uncached on. * * @param type If null, this parameter is ignored. * If it is non-null, we match only datanodes which * have it on this list. * See {@link DatanodeDescriptor.CachedBlocksList.Type} * for a description of all the lists. * * @return The list of datanodes. Modifying this list does not * alter the state of the CachedBlock. */ public List<DatanodeDescriptor> getDatanodes(Type type) { List<DatanodeDescriptor> nodes = new LinkedList<DatanodeDescriptor>(); for (int i = 0; i < triplets.length; i += 3) { CachedBlocksList list = (CachedBlocksList)triplets[i]; if ((type == null) || (list.getType() == type)) { nodes.add(list.getDatanode()); } } return nodes; }
+ "because the DataNode uncached it.", cblock.getBlockId(), datanode.getDatanodeUuid()); datanode.getPendingUncached().remove(cblock); iter.remove(); iter.hasNext(); ) { DatanodeDescriptor datanode = iter.next(); datanode.getPendingCached().remove(cblock); iter.remove(); LOG.trace("Block {}: removing from PENDING_CACHED for node {}" iter.hasNext(); ) { DatanodeDescriptor datanode = iter.next(); datanode.getPendingUncached().remove(cblock); iter.remove(); LOG.trace("Block {}: removing from PENDING_UNCACHED for node {} "
Iterator<CachedBlock> it = datanode.getPendingCached().iterator(); while (it.hasNext()) { CachedBlock cBlock = it.next(); it = datanode.getPendingUncached().iterator(); blockInfo.getBlockId(), datanode.getDatanodeUuid()); pendingCached.add(datanode); boolean added = datanode.getPendingCached().add(cachedBlock); assert added;
+ "because the DataNode uncached it.", cblock.getBlockId(), datanode.getDatanodeUuid()); datanode.getPendingUncached().remove(cblock); iter.remove(); iter.hasNext(); ) { DatanodeDescriptor datanode = iter.next(); datanode.getPendingCached().remove(cblock); iter.remove(); LOG.trace("Block {}: removing from PENDING_CACHED for node {}" iter.hasNext(); ) { DatanodeDescriptor datanode = iter.next(); datanode.getPendingUncached().remove(cblock); iter.remove(); LOG.trace("Block {}: removing from PENDING_UNCACHED for node {} "
Iterator<CachedBlock> it = datanode.getPendingCached().iterator(); while (it.hasNext()) { CachedBlock cBlock = it.next(); it = datanode.getPendingUncached().iterator(); blockInfo.getBlockId(), datanode.getDatanodeUuid()); pendingCached.add(datanode); boolean added = datanode.getPendingCached().add(cachedBlock); assert added;
!dn.getPendingCached().iterator().hasNext()); Assert.assertTrue("expected cached list to start off empty.", !dn.getCached().iterator().hasNext()); Assert.assertTrue("expected pending uncached list to start off empty.", !dn.getPendingUncached().iterator().hasNext()); Assert.assertTrue(dn.getCached().add(blocks[0])); Assert.assertTrue("expected pending cached list to still be empty.", !dn.getPendingCached().iterator().hasNext()); Assert.assertEquals("failed to insert blocks[0]", blocks[0], dn.getCached().iterator().next()); Assert.assertTrue("expected pending uncached list to still be empty.", !dn.getPendingUncached().iterator().hasNext()); Assert.assertTrue(dn.getCached().add(blocks[1])); Iterator<CachedBlock> iter = dn.getCached().iterator(); Assert.assertEquals(blocks[0], iter.next()); Assert.assertEquals(blocks[1], iter.next()); Assert.assertTrue(!iter.hasNext()); Assert.assertTrue(dn.getCached().addFirst(blocks[2])); iter = dn.getCached().iterator(); Assert.assertEquals(blocks[2], iter.next()); Assert.assertEquals(blocks[0], iter.next()); Assert.assertTrue(dn.getCached().remove(blocks[0])); iter = dn.getCached().iterator(); Assert.assertEquals(blocks[2], iter.next()); Assert.assertEquals(blocks[1], iter.next());
possibilities.remove(random.nextInt(possibilities.size())); pendingUncached.add(datanode); boolean added = datanode.getPendingUncached().add(cachedBlock); assert added; neededUncached--;
private void processCacheReportImpl(final DatanodeDescriptor datanode, final List<Long> blockIds) { CachedBlocksList cached = datanode.getCached(); cached.clear(); CachedBlocksList cachedList = datanode.getCached(); CachedBlocksList pendingCachedList = datanode.getPendingCached(); cachedList.add(cachedBlock); LOG.trace("Added block {} to CACHED list.", cachedBlock); pendingCachedList.remove(cachedBlock); LOG.trace("Removed block {} from PENDING_CACHED list.", cachedBlock);
possibilities.remove(random.nextInt(possibilities.size())); pendingUncached.add(datanode); boolean added = datanode.getPendingUncached().add(cachedBlock); assert added; neededUncached--;
private void processCacheReportImpl(final DatanodeDescriptor datanode, final List<Long> blockIds) { CachedBlocksList cached = datanode.getCached(); cached.clear(); CachedBlocksList cachedList = datanode.getCached(); CachedBlocksList pendingCachedList = datanode.getPendingCached(); cachedList.add(cachedBlock); LOG.trace("Added block {} to CACHED list.", cachedBlock); pendingCachedList.remove(cachedBlock); LOG.trace("Removed block {} from PENDING_CACHED list.", cachedBlock);
private void testRemoveElementsFromList(Random r, CachedBlocksList list, CachedBlock[] blocks) { int i = 0; for (Iterator<CachedBlock> iter = list.iterator(); iter.hasNext(); ) { Assert.assertEquals(blocks[i], iter.next()); i++; } if (r.nextBoolean()) { LOG.info("Removing via iterator"); for (Iterator<CachedBlock> iter = list.iterator(); iter.hasNext() ;) { iter.next(); iter.remove(); } } else { LOG.info("Removing in pseudo-random order"); CachedBlock[] remainingBlocks = Arrays.copyOf(blocks, blocks.length); for (int removed = 0; removed < remainingBlocks.length; ) { int toRemove = r.nextInt(remainingBlocks.length); if (remainingBlocks[toRemove] != null) { Assert.assertTrue(list.remove(remainingBlocks[toRemove])); remainingBlocks[toRemove] = null; removed++; } } } Assert.assertTrue("expected list to be empty after everything " + "was removed.", !list.iterator().hasNext()); }
/** * Convert a CachedBlockList into a DatanodeCommand with a list of blocks. * * @param list The {@link CachedBlocksList}. This function * clears the list. * @param datanode The datanode. * @param action The action to perform in the command. * @param poolId The block pool id. * @return A DatanodeCommand to be sent back to the DN, or null if * there is nothing to be done. */ private DatanodeCommand getCacheCommand(CachedBlocksList list, DatanodeDescriptor datanode, int action, String poolId) { int length = list.size(); if (length == 0) { return null; } // Read the existing cache commands. long[] blockIds = new long[length]; int i = 0; for (Iterator<CachedBlock> iter = list.iterator(); iter.hasNext(); ) { CachedBlock cachedBlock = iter.next(); blockIds[i++] = cachedBlock.getBlockId(); } return new BlockIdCommand(action, poolId, blockIds); }
/** * Convert a CachedBlockList into a DatanodeCommand with a list of blocks. * * @param list The {@link CachedBlocksList}. This function * clears the list. * @param datanode The datanode. * @param action The action to perform in the command. * @param poolId The block pool id. * @return A DatanodeCommand to be sent back to the DN, or null if * there is nothing to be done. */ private DatanodeCommand getCacheCommand(CachedBlocksList list, DatanodeDescriptor datanode, int action, String poolId) { int length = list.size(); if (length == 0) { return null; } // Read the existing cache commands. long[] blockIds = new long[length]; int i = 0; for (Iterator<CachedBlock> iter = list.iterator(); iter.hasNext(); ) { CachedBlock cachedBlock = iter.next(); blockIds[i++] = cachedBlock.getBlockId(); } return new BlockIdCommand(action, poolId, blockIds); }
/** * Get a list of the datanodes which this block is cached, * planned to be cached, or planned to be uncached on. * * @param type If null, this parameter is ignored. * If it is non-null, we match only datanodes which * have it on this list. * See {@link DatanodeDescriptor.CachedBlocksList.Type} * for a description of all the lists. * * @return The list of datanodes. Modifying this list does not * alter the state of the CachedBlock. */ public List<DatanodeDescriptor> getDatanodes(Type type) { List<DatanodeDescriptor> nodes = new LinkedList<DatanodeDescriptor>(); for (int i = 0; i < triplets.length; i += 3) { CachedBlocksList list = (CachedBlocksList)triplets[i]; if ((type == null) || (list.getType() == type)) { nodes.add(list.getDatanode()); } } return nodes; }
/** * Get a list of the datanodes which this block is cached, * planned to be cached, or planned to be uncached on. * * @param type If null, this parameter is ignored. * If it is non-null, we match only datanodes which * have it on this list. * See {@link DatanodeDescriptor.CachedBlocksList.Type} * for a description of all the lists. * * @return The list of datanodes. Modifying this list does not * alter the state of the CachedBlock. */ public List<DatanodeDescriptor> getDatanodes(Type type) { List<DatanodeDescriptor> nodes = new LinkedList<DatanodeDescriptor>(); for (int i = 0; i < triplets.length; i += 3) { CachedBlocksList list = (CachedBlocksList)triplets[i]; if ((type == null) || (list.getType() == type)) { nodes.add(list.getDatanode()); } } return nodes; }
public void resetBlocks() { updateStorageStats(this.getStorageReports(), 0L, 0L, 0, 0, null); this.invalidateBlocks.clear(); this.volumeFailures = 0; // pendingCached, cached, and pendingUncached are protected by the // FSN lock. this.pendingCached.clear(); this.cached.clear(); this.pendingUncached.clear(); }
public void clearBlockQueues() { synchronized (invalidateBlocks) { this.invalidateBlocks.clear(); this.recoverBlocks.clear(); this.replicateBlocks.clear(); } // pendingCached, cached, and pendingUncached are protected by the // FSN lock. this.pendingCached.clear(); this.cached.clear(); this.pendingUncached.clear(); }