/** * Returns a new node. The node is retrieved (and removed) from the * released list or created new. */ private BlockIo getNewNode( long blockid ) throws IOException { BlockIo retval = null; if ( !free.isEmpty() ) { retval = free.removeFirst(); } if ( retval == null ) { retval = new BlockIo( 0, new byte[BLOCK_SIZE] ); } retval.setBlockId( blockid ); retval.setView( null ); return retval; }
/** Discards the indicated blocks and notify the owner. */ private void discardBlocks(ArrayList<BlockIo> blocks) throws IOException { for (BlockIo cur:blocks) { cur.decrementTransactionCount(); if (!cur.isInTransaction()) { owner.releaseFromTransaction(cur, false); } } }
/** * Releases a block. * * @param block The block to release. */ void release( BlockIo block ) { inUse.remove( block.getBlockId() ); if ( block.isDirty() ) { // System.out.println( "Dirty: " + key + block ); dirty.put( block.getBlockId(), block ); } else { if ( !transactionsDisabled && block.isInTransaction() ) { inTxn.put( block.getBlockId(), block ); } else { free.add( block ); } } }
private static BlockIo deserializeBlockIo(DataInputStream is) throws IOException, ClassNotFoundException { BlockIo b = new BlockIo(); b.readExternal(is); return b; }
/** * Synchronizes a node to disk. This is called by the transaction manager's * synchronization code. */ void synch( BlockIo node ) throws IOException { byte[] data = node.getData(); if ( data != null ) { long offset = node.getBlockId() * BLOCK_SIZE; file.seek( offset ); file.write( data ); } }
long offset = node.getBlockId() * BLOCK_SIZE; file.seek( offset ); file.write( node.getData() ); node.setClean(); free.add( node ); inTxn.put( node.getBlockId(), node );
/** * Releases a block. * * @param blockid The record number to release. * @param isDirty If true, the block was modified since the get(). */ void release(long blockid, boolean isDirty) throws IOException { BlockIo node = inUse.get(blockid); if (node == null) throw new IOException("bad blockid " + blockid + " on release"); if (!node.isDirty() && isDirty) node.setDirty(); release(node); }
/** Returns the block number */ long getBlock() { return block.readLong( pos + O_BLOCK ); }
public int compare( BlockIo block1, BlockIo block2 ) { if ( block1.getBlockId() == block2.getBlockId() ) { return 0; } else if ( block1.getBlockId() < block2.getBlockId() ) { return -1; } else { return 1; } }
/** * Factory method to create or return a data page for the indicated block. */ static FreePhysicalRowIdPage getFreePhysicalRowIdPageView(BlockIo block,int pageSize) { BlockView view = block.getView(); if (view != null && view instanceof FreePhysicalRowIdPage) return (FreePhysicalRowIdPage) view; else return new FreePhysicalRowIdPage(block, pageSize); }
/** Returns the available size */ int getAvailableSize() { return block.readInt( pos + O_AVAILABLESIZE ); }
toCopy = leftToWrite; System.arraycopy(data, offsetInBuffer, block.getData(), dataOffset, toCopy);
/** * Indicates the block is part of the transaction. */ void add(BlockIo block) throws IOException { block.incrementTransactionCount(); txns[curTxn].add(block); }
/** * Sets the block number. Should only be called by RecordFile. */ void setBlockId(long id) { if (isInTransaction()) throw new Error("BlockId assigned for transaction block"); blockId = id; }
/** Synchs in-core transactions to data file and opens a fresh log */ private void synchronizeLogFromMemory() throws IOException { close(); TreeSet blockList = new TreeSet( new BlockIoComparator() ); int numBlocks = 0; int writtenBlocks = 0; for (int i = 0; i < _maxTxns; i++) { if (txns[i] == null) continue; // Add each block to the blockList, replacing the old copy of this // block if necessary, thus avoiding writing the same block twice for (Iterator k = txns[i].iterator(); k.hasNext(); ) { BlockIo block = (BlockIo)k.next(); if ( blockList.contains( block ) ) { block.decrementTransactionCount(); } else { writtenBlocks++; boolean result = blockList.add( block ); } numBlocks++; } txns[i] = null; } // Write the blocks from the blockList to disk synchronizeBlocks(blockList.iterator(), true); owner.sync(); open(); }
long offset = node.getBlockId() * BLOCK_SIZE; file.seek( offset ); file.write( node.getData() ); node.setClean(); free.add( node ); inTxn.put( node.getBlockId(), node );
/** * Synchronizes a node to disk. This is called by the transaction manager's * synchronization code. */ void synch( BlockIo node ) throws IOException { byte[] data = node.getData(); if ( data != null ) { long offset = node.getBlockId() * BLOCK_SIZE; file.seek( offset ); file.write( data ); } }
/** * Releases a block. * * @param blockId The record number to release. * @param isDirty If true, the block was modified since the get(). */ void release( long blockId, boolean isDirty ) throws IOException { BlockIo blockIo = inUse.get( blockId ); if ( blockIo == null ) { throw new IOException( I18n.err( I18n.ERR_555, blockId ) ); } if ( ! blockIo.isDirty() && isDirty ) { blockIo.setDirty(); } release( blockIo ); }
/** Returns the block number */ long getBlock() { return block.readLong( pos + O_BLOCK ); }