/** * Release a block ID back into the free list. * * @param blockId The ID of the block to release. * @throws IOException if an I/O error occurs. */ public void freeBlock(long blockId) throws IOException { assert this == currentPhase; freeList.free(blockId); }
/** * Changes the block ID of the specified Block. This method is called * copyBlock because a call to copyBlock() followed by a call to * writeBlock() can be used to copy the contents of a block to a new * location in the block file. * * @param block the Block to be copied. * @param dstBlockId the ID of the block to which the Block will be written * when writeBlock() is called. * @throws IOException if an I/O error occurs. */ public void copyBlock(Block block, long dstBlockId) throws IOException { assert this == currentPhase; assert block.getBlockId() != dstBlockId; if (freeList.isSharedItem(dstBlockId)) { // Choose an alternative destination block since this one is shared // with another phase. freeList.free(dstBlockId); dstBlockId = freeList.allocate(); blockFile.setNrBlocks(freeList.getNextItem()); } blockFile.copyBlock(block, dstBlockId); }
/** * METHOD TO DO * * @param node PARAMETER TO DO * @throws NodePoolException EXCEPTION TO DO * @throws NoSuchNodeException EXCEPTION TO DO */ public synchronized void releaseNode( long node ) throws NodePoolException, NoSuchNodeException { checkInitialized(); try { if (node < MIN_NODE || node >= freeList.getNextItem()) { throw new NoSuchNodeException(node, "Invalid node ID: " + node); } freeList.free(node); } catch (NullPointerException ex) { throw new NodePoolException("Node pool not open."); } catch (IOException ex) { throw new NodePoolException("Failed to free node.", ex); } catch (IllegalStateException ex) { throw new NodePoolException("Node pool already initialized.", ex); } }
/** * Gets a new block from the file to write block data to. * The block data to write is a modified version of an existing block. * * @param block The block to be copied into the new "modified" block. * @throws IOException if an I/O error occurs. */ public void modifyBlock(Block block) throws IOException { assert this == currentPhase; if (freeList.isSharedItem(block.getBlockId())) { // Allocate a new block and copy block to it. long newBlockId = freeList.allocate(); blockFile.setNrBlocks(freeList.getNextItem()); // Although we use block after the block is freed, the block can't // be reused (by a later phase) until the current phase is committed. freeList.free(block.getBlockId()); blockFile.copyBlock(block, newBlockId); } }