private void checkUpdate(Action action) { if ( inUpdate == 0 ) error(action, "called outside update") ; }
private void checkRead(Action action) { if ( inUpdate == 0 && inRead == 0 ) error(action, "Called outside update and read") ; }
private void checkUpdate(Action action) { if ( inUpdate == 0 ) error(action, "called outside update") ; }
private void checkRead(Action action) { if ( inUpdate == 0 && inRead == 0 ) error(action, "Called outside update and read") ; }
@Override synchronized public void beginRead() { synchronized (this) { if ( inUpdate != 0 ) error(BeginRead, "beginRead when already in update") ; inRead++ ; } blockMgr.beginRead() ; }
@Override synchronized public void beginRead() { synchronized (this) { if ( inUpdate != 0 ) error(BeginRead, "beginRead when already in update") ; inRead++ ; } blockMgr.beginRead() ; }
@Override public void endUpdate() { synchronized (this) { if ( inUpdate == 0 ) error(EndUpdate, "endUpdate but not in update") ; if ( inRead > 0 ) error(EndUpdate, "endUpdate when in read") ; checkEmpty("Outstanding read blocks at end of update operations", activeReadBlocks) ; checkEmpty("Outstanding write blocks at end of update operations", activeWriteBlocks) ; inUpdate-- ; clearBlockTracking() ; } blockMgr.endUpdate() ; }
@Override public void endUpdate() { synchronized (this) { if ( inUpdate == 0 ) error(EndUpdate, "endUpdate but not in update") ; if ( inRead > 0 ) error(EndUpdate, "endUpdate when in read") ; checkEmpty("Outstanding read blocks at end of update operations", activeReadBlocks) ; checkEmpty("Outstanding write blocks at end of update operations", activeWriteBlocks) ; inUpdate-- ; clearBlockTracking() ; } blockMgr.endUpdate() ; }
@Override synchronized public void endRead() { synchronized (this) { if ( inRead == 0 ) error(EndRead, "endRead but not in read") ; if ( inUpdate != 0 ) error(EndRead, "endRead when in update") ; checkEmpty("Outstanding write blocks at end of read operations!", activeWriteBlocks) ; if ( inRead == 0 ) { // Check at end of multiple reads or a write checkEmpty("Outstanding read blocks at end of read operations", activeReadBlocks) ; clearBlockTracking() ; } inRead-- ; } blockMgr.endRead() ; }
private void error(Action action, String string) { error(action + ": " + string) ; history() ; throw new BlockException(msg(action + ": " + string)) ; // debugPoint() ; }
private void error(Action action, String string) { error(action + ": " + string) ; history() ; throw new BlockException(msg(action + ": " + string)) ; // debugPoint() ; }
private void writeTracker(Block block) { synchronized (this) { checkUpdate(Write) ; Long id = block.getId() ; add(Write, id) ; if ( !activeWriteBlocks.contains(id) ) error(Write, id + " is not an active write block") ; } }
private void checkEmpty(String string, Multiset<Long> blocks) { if ( !blocks.isEmpty() ) { error(string) ; for ( Long id : blocks ) warn(" Block: " + id) ; if ( collectHistory ) history() ; throw new DBOpEnvException() ; // debugPoint() ; } }
private void checkEmpty(String string, Multiset<Long> blocks) { if ( !blocks.isEmpty() ) { error(string) ; for ( Long id : blocks ) warn(" Block: " + id) ; if ( collectHistory ) history() ; throw new DBOpEnvException() ; // debugPoint() ; } }
private void writeTracker(Block block) { synchronized (this) { checkUpdate(Write) ; Long id = block.getId() ; add(Write, id) ; if ( !activeWriteBlocks.contains(id) ) error(Write, id + " is not an active write block") ; } }
@Override public Block promote(Block block) { synchronized (this) { checkUpdate(Promote) ; Long id = block.getId() ; add(Promote, id) ; if ( !activeWriteBlocks.contains(id) && !activeReadBlocks.contains(id) ) error(Promote, id + " is not an active block") ; while ( activeReadBlocks.contains(id) ) activeReadBlocks.remove(id) ; // Double promotion results in only one entry. if ( !activeWriteBlocks.contains(id) ) activeWriteBlocks.add(id) ; } return blockMgr.promote(block) ; }
@Override public Block promote(Block block) { synchronized (this) { checkUpdate(Promote) ; Long id = block.getId() ; add(Promote, id) ; if ( !activeWriteBlocks.contains(id) && !activeReadBlocks.contains(id) ) error(Promote, id + " is not an active block") ; while ( activeReadBlocks.contains(id) ) activeReadBlocks.remove(id) ; // Double promotion results in only one entry. if ( !activeWriteBlocks.contains(id) ) activeWriteBlocks.add(id) ; } return blockMgr.promote(block) ; }
@Override public void free(Block block) { synchronized (this) { checkUpdate(Free) ; Long id = block.getId() ; add(Free, id) ; if ( activeReadBlocks.contains(id) ) warn(Free, id + " is a read block") ; if ( !activeWriteBlocks.contains(id) ) error(Free, id + " is not a write block") ; activeWriteBlocks.remove(id) ; if ( activeWriteBlocks.count(id) != 0 ) warn(Free, id + " has "+activeWriteBlocks.count(id)+" outstanding write registrations") ; } blockMgr.free(block) ; }