@Override public void sync() { checkIfClosed() ; }
private Block localBlock(long id) { checkIfClosed() ; return writeBlocks.get(id) ; }
@Override public boolean isEmpty() { checkIfClosed() ; return writeBlocks.isEmpty() && blockMgr.isEmpty() ; }
@Override public boolean valid(int id) { checkIfClosed() ; if ( writeBlocks.containsKey(Long.valueOf(id))) return true ; return blockMgr.valid(id) ; }
@Override public void endUpdate() { checkIfClosed() ; blockMgr.endRead() ; }
@Override public void free(Block block) { checkIfClosed() ; freedBlocks.put(block.getId(), block) ; }
@Override public void endIterator(Iterator<?> iterator) { checkIfClosed() ; transaction.removeIterator(iterator) ; // Don't pass down the beginIterator call - we track and manage here, not lower down. //blockMgr.endIterator(iterator) ; }
@Override public void beginIterator(Iterator<?> iterator) { checkIfClosed() ; transaction.addIterator(iterator) ; // Don't pass down the beginIterator call - we track and manage here, not lower down. //blockMgr.beginIterator(iterator) ; }
@Override public void endRead() { checkIfClosed() ; blockMgr.endRead() ; }
@Override public void beginUpdate() { checkIfClosed() ; blockMgr.beginRead() ; }
@Override public void beginRead() { checkIfClosed() ; blockMgr.beginRead() ; }
@Override public void release(Block block) { checkIfClosed() ; Long id = block.getId() ; // Only release unchanged blocks. if ( ! writeBlocks.containsKey(id)) blockMgr.release(block) ; }
@Override public Block promote(Block block) { checkIfClosed() ; if ( writeBlocks.containsKey(block.getId()) ) return block ; return _promote(block) ; }
@Override public Block getRead(long id) { checkIfClosed() ; Block block = localBlock(id) ; if ( block != null ) return block ; block = blockMgr.getRead(id) ; if ( active ) readBlocks.add(block.getId()) ; return block ; }
@Override public Block allocate(int blockSize) { checkIfClosed() ; // Might as well allocate now. // This allocates the id. Block block = blockMgr.allocate(blockSize) ; // But we "copy" it by allocating ByteBuffer space. if ( active ) { block = replicate(block) ; writeBlocks.put(block.getId(), block) ; } return block ; }
@Override public Block getReadIterator(long id) { //logState() ; checkIfClosed() ; Block block = localBlock(id) ; if ( block == null ) block = blockMgr.getReadIterator(id) ; if ( block == null ) throw new BlockException("No such block: "+getLabel()+" "+id) ; if ( active ) iteratorBlocks.add(block.getId()) ; return block ; }
@Override public void write(Block block) { checkIfClosed() ; if ( ! block.isModified() ) Log.warn(this, "Page for block "+fileRef+"/"+block.getId()+" not modified") ; if ( ! writeBlocks.containsKey(block.getId()) ) { Log.warn(this, "Block not recognized: "+block.getId()) ; // Probably corruption by writing in-place. // but at least when this transaction commits, // the update data is written, writeBlocks.put(block.getId(), block) ; } }
@Override public Block getWrite(long id) { // NB: If we are in a stack of BlockMgrs, after a transaction has committed, // we would be called via getRead and the upper Blockgr does the promotion. checkActive() ; checkIfClosed() ; Block block = localBlock(id) ; if ( block != null ) return block ; // Get-as-read. block = blockMgr.getRead(id) ; // If most blocks get modified, then a copy is needed // anyway so now is as good a time as any. block = _promote(block) ; return block ; }