Block block = blockFilePhase.allocateBlock(objectPool); try { block.put(0, data);
block = phase.getAVLBlockFilePhase().readBlock(objectPool, nodeId); } catch (IOException ex) { throw new Error("IOException", ex);
/** * Establishes that the structure of the blocks is what it should be. * * @throws Error When the file is shorter than the fields in the file indicate. */ private void check() throws IOException { // Initial phase. // Check that the block file has the correct size. long nrValidBlocks = freeList.getNextItem(); long nrBlocks = getNrBlocks(); if (nrBlocks != nrValidBlocks) { if (nrBlocks < nrValidBlocks) { logger.error("File " + file + " may have been truncated."); throw new Error("File " + file + " may have been truncated."); } if (logger.isDebugEnabled()) { logger.debug("File " + file + " may not have been closed properly on shutdown.\n nrBlocks=" + nrBlocks + " nrValidBlocks=" + nrValidBlocks, new Throwable()); } blockFile.setNrBlocks(nrValidBlocks); } }
/** * Initialises a node on the given information. * * @param phase The phase that the node exists in. * @param objectPool The pool that the node will return to. * @throws IOException If an I/O error occurs. */ private void init( AVLFile.Phase phase, ObjectPool objectPool ) throws IOException { assert this.objectPool == null; this.phase = phase; parentNode = null; childIndex = 0; this.leftChildNode = null; this.rightChildNode = null; this.objectPool = objectPool; //X trace = new Throwable(); refCount = 1; writable = true; dirty = true; block = phase.getAVLBlockFilePhase().allocateBlock(objectPool); block.putLong(IDX_LEFT, NULL_NODE); block.putLong(IDX_RIGHT, NULL_NODE); block.putByte(IDX_BALANCE_B, (byte) 0); }
/** * Reads data from the specified block into the ByteBuffer starting at the * current position. The number of bytes read is the number of remaining * bytes in the ByteBuffer. */ private ByteBuffer retrieveRemainingBytes( ObjectPool objectPool, ByteBuffer data, long blockId ) throws IOException { int dataSize = data.remaining(); if (dataSize > 0) { // Determine the block file to use. int fileIndex = XAUtils.log2( (dataSize - 1) >> (LOG2_MIN_BLOCK_SIZE - 1) ); ManagedBlockFile.Phase blockFilePhase = blockFilePhases[fileIndex]; Block block = blockFilePhase.readBlock(objectPool, blockId); try { block.get(0, data); } finally { block.release(); } } return data; }
/** * Creates a new phase for this AVL tree. * * @throws IOException If and I/O error occurs. */ public Phase() throws IOException { if (currentPhase == null) { rootId = AVLNode.NULL_NODE; nrNodes = 0; } else { rootId = currentPhase.rootId; nrNodes = currentPhase.nrNodes; } avlBlockFilePhase = avlBlockFile.new Phase(); check(); currentPhase = this; }
/** * CONSTRUCTOR Phase TO DO * * @param b PARAMETER TO DO * @param offset PARAMETER TO DO * @throws IOException EXCEPTION TO DO */ Phase(Block b, int offset) throws IOException { avlFilePhase = avlFile.new Phase(b, offset); offset += AVLFile.Phase.RECORD_SIZE; for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFilePhases[i] = blockFiles[i].new Phase(b, offset); offset += ManagedBlockFile.Phase.RECORD_SIZE; } currentPhase = this; dirty = false; }
/** * CONSTRUCTOR Phase TO DO * * @throws IOException EXCEPTION TO DO */ Phase(Phase p) throws IOException { assert p != null; avlFilePhase = avlFile.new Phase(p.avlFilePhase); for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFilePhases[i] = blockFiles[i].new Phase( p.blockFilePhases[i] ); } currentPhase = this; dirty = true; }
private void freeBlock(AVLNode avlNode) throws IOException { int dataSize = avlNode.getPayloadInt(IDX_DATA_SIZE_I); // Check if a block has been allocated. if (dataSize > MAX_DIRECT_DATA_BYTES) { // The number of SPObject data bytes in the AVLNode. int directDataSize = MAX_DIRECT_DATA_BYTES - Constants.SIZEOF_LONG; // Free the block. long blockId = avlNode.getPayloadLong(IDX_BLOCK_ID); // Determine the block file to use. int fileIndex = XAUtils.log2( (dataSize - directDataSize - 1) >> (LOG2_MIN_BLOCK_SIZE - 1) ); ManagedBlockFile.Phase blockFilePhase = blockFilePhases[fileIndex]; blockFilePhase.freeBlock(blockId); } }
/** * Writes this PersistableMetaRoot to the specified Block. The ints are * written at the current position of the Block. * * @param b the Block. * @param offset PARAMETER TO DO */ public void writeToBlock(Block b, int offset) { avlFilePhase.writeToBlock(b, offset); offset += AVLFile.Phase.RECORD_SIZE; for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFilePhases[i].writeToBlock(b, offset); offset += ManagedBlockFile.Phase.RECORD_SIZE; } }
/** * Constructs a phase, copying another phase. * * @param p The phase to copy. * @throws IOException If an I/O error occurs. */ public Phase(Phase p) throws IOException { assert p != null; rootId = p.rootId; nrNodes = p.nrNodes; avlBlockFilePhase = avlBlockFile.new Phase(p.avlBlockFilePhase); check(); currentPhase = this; }
boolean isInUse() { return blockFilePhases[0].isInUse(); }
/** * Construct a phase, copy the phase data found in an existing block. * * @param b The block containing the phase data. * @param offset The offset of the phase data within the block. * @throws IOException If an I/O error occurs. */ public Phase(Block b, int offset) throws IOException { rootId = b.getLong(offset + IDX_ROOT_ID); nrNodes = b.getLong(offset + IDX_NR_NODES); avlBlockFilePhase = avlBlockFile.new Phase(b, offset + HEADER_SIZE); check(); currentPhase = this; }
/** * CONSTRUCTOR Phase TO DO * * @throws IOException EXCEPTION TO DO */ Phase() throws IOException { avlFilePhase = avlFile.new Phase(); for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFilePhases[i] = blockFiles[i].new Phase(); } currentPhase = this; dirty = true; }
/** * Creates a new phase, using a freelist block. * * @param b The block in the freelist to start the new phase in. * @param offset The offset in the block to find the start of the freelist block. * @throws IOException If an I/O error occurred on the free list. */ public Phase(Block b, int offset) throws IOException { freeListPhase = freeList.new Phase(b, offset); currentPhase = this; check(); }
/** * CONSTRUCTOR Token TO DO */ Token() { avlFileToken = avlFilePhase.use(); for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFileTokens[i] = blockFilePhases[i].use(); } }
/** * Creates the token, adding a reference count to the block file phase. */ Token() { avlBlockFileToken = avlBlockFilePhase.use(); }
/** * Writes this PersistableMetaRoot to the specified Block. The ints are * written at the specified offset. * * @param b the Block. * @param offset the offset into the Block to start writing. */ public void writeToBlock(Block b, int offset) { check(); b.putLong(offset + IDX_ROOT_ID, rootId); b.putLong(offset + IDX_NR_NODES, nrNodes); avlBlockFilePhase.writeToBlock(b, offset + HEADER_SIZE); }