/** * Remove INode reference from block b. * If it does not belong to any file and data-nodes, * then remove the block from the block map. */ void removeINode(Block b) { BlockInfo info = blocks.get(b); if (info != null) { info.inode = null; if (info.getDatanode(0) == null) { // no datanodes left removeBlockFromMap(b); // 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; }