/** * 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 System.out.println("BLOCKSMAP removes block : " + blockInfo); }
/** * 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 System.out.println("BLOCKSMAP removes block : " + b); } return removed; }