/** * Reads the reallocate block from blockFile. If the current reallocate buffer * already holds the reallocate block then nothing is done. If the reallocate * buffer contains a different block then it is released first. * * @param blockId The block number of the reallocate block. * @throws IOException if an I/O error occurs. */ private void readReallocateBlock(int blockId) throws IOException { if (reallocateBlock != null) { if (blockId == (int) reallocateBlock.getBlockId()) { return; } releaseReallocateBlock(); } reallocateBlock = findBlock(blockId); if (reallocateBlock == null) { reallocateBlock = blockFile.readBlock(objectPool, blockId); } reallocateBlockDirty = false; }
/** * Reads the tail block from blockFile. If the current tail buffer already * holds the tail block then nothing is done. If the tail buffer contains a * different block then it is freed first. * * @param blockId The block number to use as the tail buffer. * @throws IOException if an I/O error occurs. */ private void readTailBlock(int blockId) throws IOException { if (tailBlock != null) { if (blockId == (int) tailBlock.getBlockId()) { return; } releaseTailBlock(); } tailBlock = findBlock(blockId); if (tailBlock == null) { tailBlock = blockFile.readBlock(objectPool, blockId); } }
/** * Reads the head block from blockFile. If the current head buffer already * holds the head block then nothing is done. If the head buffer contains a * different block then it is freed first (writing it to the file). This is * similar to {@link #allocateHeadBlock} only it will not allocate a new * block from the file, and always reads the contents of the existing block * in the file. * * @param blockId The block number of the head block. * @throws IOException if an I/O error occurs. */ private void readHeadBlock(int blockId) throws IOException { if (headBlock != null) { if (blockId == (int) headBlock.getBlockId()) { return; } releaseHeadBlock(); } headBlock = findBlock(blockId); if (headBlock == null) { headBlock = blockFile.readBlock(objectPool, blockId); } headBlockDirty = false; }
/** * Allocates a buffer from blockFile to hold the head block. If the current * head buffer already holds the head block then nothing is done. If the head * buffer contains a different block then it is released first (writing the * head block to the file). This method uses a previous version of the * block, unless no block with that ID exists yet, in which case a new block * is read in, or allocated if it does not exist in the file either. If the * block existed in the file, then its contents will be ignored. Contrast * this to {@link #readHeadBlock} where the contents of the block on the disk * are always read. * * @param blockId The block number of the head block. * @throws IOException if an I/O error occurs. */ private void allocateHeadBlock(int blockId) throws IOException { if (headBlock != null) { if (blockId == (int) headBlock.getBlockId()) { headBlockDirty = false; return; } releaseHeadBlock(); } headBlock = findBlock(blockId); if (headBlock == null) { headBlock = blockFile.allocateBlock(objectPool, blockId); } headBlockDirty = false; }
Block nextHeadBlock = findBlock(nextHeadBlockId);