/** * Remove data-node reference from the block. * Remove the block from the block map * only if it does not belong to any file and data-nodes. */ boolean removeNode(Block b, DatanodeDescriptor node) { BlockInfo info = map.get(b); if (info == null) return false; // remove block from the data-node list and the node from the block info boolean removed = node.removeBlock(info); if (info.getDatanode(0) == null // no datanodes left && info.inode == null) { // does not belong to a file map.remove(b); // remove block from the map } return removed; }
/** * Remove the block from the block map; * remove it from all data-node lists it belongs to; * and remove all data-node locations associated with the block. */ void removeBlock(BlockInfo blockInfo) { if (blockInfo == null) return; blockInfo.inode = null; for(int idx = blockInfo.numNodes()-1; idx >= 0; idx--) { DatanodeDescriptor dn = blockInfo.getDatanode(idx); dn.removeBlock(blockInfo); // remove from the list and wipe the location } map.remove(blockInfo); // remove block from the map }
/** * Remove the block from the block map; * remove it from all data-node lists it belongs to; * and remove all data-node locations associated with the block. */ void removeBlock(Block block) { BlockInfo blockInfo = removeBlockFromMap(block); if (blockInfo == null) return; blockInfo.inode = null; for(int idx = blockInfo.numNodes()-1; idx >= 0; idx--) { DatanodeDescriptor dn = blockInfo.getDatanode(idx); dn.removeBlock(blockInfo); // remove from the list and wipe the location } }
/** * Remove data-node reference from the block. * Remove the block from the block map * only if it does not belong to any file and data-nodes. */ boolean removeNode(Block b, DatanodeDescriptor node) { BlockInfo info = blocks.get(b); if (info == null) return false; // remove block from the data-node list and the node from the block info boolean removed = node.removeBlock(info); if (info.getDatanode(0) == null // no datanodes left && info.inode == null) { // does not belong to a file removeBlockFromMap(b); // remove block from the map } return removed; }
targets[i].removeBlock(storedBlock);
while(it.hasNext()) toRemove.add(it.next()); this.removeBlock(delimiter);
targets[i].removeBlock(storedBlock);
public void testBlocksCounter() throws Exception { DatanodeDescriptor dd = new DatanodeDescriptor(); assertEquals(0, dd.numBlocks()); BlockInfo blk = new BlockInfo(new Block(1L), 1); BlockInfo blk1 = new BlockInfo(new Block(2L), 2); // add first block assertTrue(dd.addBlock(blk)); assertEquals(1, dd.numBlocks()); // remove a non-existent block assertFalse(dd.removeBlock(blk1)); assertEquals(1, dd.numBlocks()); // add an existent block assertFalse(dd.addBlock(blk)); assertEquals(1, dd.numBlocks()); // add second block assertTrue(dd.addBlock(blk1)); assertEquals(2, dd.numBlocks()); // remove first block assertTrue(dd.removeBlock(blk)); assertEquals(1, dd.numBlocks()); // remove second block assertTrue(dd.removeBlock(blk1)); assertEquals(0, dd.numBlocks()); } }
this.removeBlock(delimiter);