private void basicModify(DiskRegionView dr,DiskEntry entry,ValueWrapper value,byte userBits,boolean async,boolean calledByCompactor) throws IOException, InterruptedException {
  DiskId id=entry.getDiskId();
  boolean useNextOplog=false;
  long startPosForSynchOp=-1L;
  int adjustment=0;
  Oplog emptyOplog=null;
  if (DiskStoreImpl.KRF_DEBUG) {
    System.out.println("basicModify KRF_DEBUG");
    Thread.sleep(1000);
  }
synchronized (this.lock) {
    if (getOplogSet().getChild() != this) {
      useNextOplog=true;
    }
 else {
      initOpState(OPLOG_MOD_ENTRY_1ID,dr,entry,value,userBits,false);
      adjustment=getOpStateSize();
      assert adjustment > 0;
      long temp=(this.crf.currSize + adjustment);
      if (temp > getMaxCrfSize() && !isFirstRecord()) {
        switchOpLog(dr,adjustment,entry);
        useNextOplog=true;
      }
 else {
        if (this.lockedForKRFcreate) {
          CacheClosedException cce=new CacheClosedException("The disk store is closed.");
          dr.getCancelCriterion().checkCancelInProgress(cce);
          throw cce;
        }
        this.firstRecord=false;
        long oldOplogId;
        startPosForSynchOp=writeOpLogBytes(this.crf,async,true);
        this.crf.currSize=temp;
        startPosForSynchOp+=getOpStateValueOffset();
        if (logger.isTraceEnabled(LogMarker.PERSIST_WRITES)) {
          VersionTag tag=null;
          if (entry.getVersionStamp() != null) {
            tag=entry.getVersionStamp().asVersionTag();
          }
          logger.trace(LogMarker.PERSIST_WRITES,"basicModify: id=<{}> key=<{}> valueOffset={} userBits={} valueLen={} valueBytes=<{}> drId={} versionStamp={} oplog#{}",abs(id.getKeyId()),entry.getKey(),startPosForSynchOp,userBits,value.getLength(),value.getBytesAsString(),dr.getId(),tag,getOplogId());
        }
        if (EntryBits.isNeedsValue(userBits)) {
          id.setValueLength(value.getLength());
        }
 else {
          id.setValueLength(0);
        }
        id.setUserBits(userBits);
        if (logger.isTraceEnabled()) {
          logger.trace("Oplog::basicModify:Released ByteBuffer with data for Disk ID = {}",id);
        }
synchronized (id) {
          oldOplogId=id.setOplogId(getOplogId());
          if (EntryBits.isAnyInvalid(userBits) || EntryBits.isTombstone(userBits)) {
            id.setOffsetInOplog(-1);
          }
 else {
            id.setOffsetInOplog(startPosForSynchOp);
          }
        }
        this.dirHolder.incrementTotalOplogSize(adjustment);
        this.incTotalCount();
        EntryLogger.logPersistPut(dr.getName(),entry.getKey(),dr.getDiskStoreID());
        if (oldOplogId != getOplogId()) {
          Oplog oldOplog=getOplogSet().getChild(oldOplogId);
          if (oldOplog != null) {
            oldOplog.rmLive(dr,entry);
            emptyOplog=oldOplog;
          }
          addLive(dr,entry);
        }
 else {
          getOrCreateDRI(dr).update(entry);
        }
        RegionVersionVector rvv=dr.getRegionVersionVector();
        if (rvv != null && entry.getVersionStamp() != null) {
          rvv.recordVersion(entry.getVersionStamp().getMemberID(),entry.getVersionStamp().getRegionVersion());
        }
      }
      clearOpState();
    }
  }
  if (useNextOplog) {
    if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
      CacheObserverHolder.getInstance().afterSwitchingOplog();
    }
    Assert.assertTrue(getOplogSet().getChild() != this);
    getOplogSet().getChild().basicModify(dr,entry,value,userBits,async,calledByCompactor);
  }
 else {
    if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
      CacheObserverHolder.getInstance().afterSettingOplogOffSet(startPosForSynchOp);
    }
    if (emptyOplog != null && (!emptyOplog.isCompacting() || emptyOplog.calledByCompactorThread())) {
      if (calledByCompactor && emptyOplog.hasNoLiveValues()) {
        flushAll(true);
      }
      emptyOplog.handleNoLiveValues();
    }
  }
}

private void basicModify ( DiskRegionView dr , DiskEntry entry , ValueWrapper value , byte userBits , boolean async , boolean calledByCompactor ) throws IOException , InterruptedException { DiskId id = entry . getDiskId ( ) ; boolean useNextOplog = false ; long startPosForSynchOp = - 1L ; int adjustment = 0 ; Oplog emptyOplog = null ; if ( DiskStoreImpl . KRF_DEBUG ) { System . out . println ( "basicModify KRF_DEBUG" ) ; Thread . sleep ( 1000 ) ; } synchronized ( this . lock ) { if ( getOplogSet ( ) . getChild ( ) != this ) { useNextOplog = true ; } else { initOpState ( OPLOG_MOD_ENTRY_1ID , dr , entry , value , userBits , false ) ; adjustment = getOpStateSize ( ) ; assert adjustment > 0 ; long temp = ( this . crf . currSize + adjustment ) ; if ( temp > getMaxCrfSize ( ) && ! isFirstRecord ( ) ) { switchOpLog ( dr , adjustment , entry ) ; useNextOplog = true ; } else { if ( this . lockedForKRFcreate ) { CacheClosedException cce = new CacheClosedException ( "The disk store is closed." ) ; dr . getCancelCriterion ( ) . checkCancelInProgress ( cce ) ; throw cce ; } this . firstRecord = false ; long oldOplogId ; startPosForSynchOp = writeOpLogBytes ( this . crf , async , true ) ; this . crf . currSize = temp ; startPosForSynchOp += getOpStateValueOffset ( ) ; if ( logger . isTraceEnabled ( LogMarker . PERSIST_WRITES ) ) { VersionTag tag = null ; if ( entry . getVersionStamp ( ) != null ) { tag = entry . getVersionStamp ( ) . asVersionTag ( ) ; } logger . trace ( LogMarker . PERSIST_WRITES , "basicModify: id=<{}> key=<{}> valueOffset={} userBits={} valueLen={} valueBytes=<{}> drId={} versionStamp={} oplog#{}" , abs ( id . getKeyId ( ) ) , entry . getKey ( ) , startPosForSynchOp , userBits , value . getLength ( ) , value . getBytesAsString ( ) , dr . getId ( ) , tag , getOplogId ( ) ) ; } if ( EntryBits . isNeedsValue ( userBits ) ) { id . setValueLength ( value . getLength ( ) ) ; } else { id . setValueLength ( 0 ) ; } id . setUserBits ( userBits ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Oplog::basicModify:Released ByteBuffer with data for Disk ID = {}" , id ) ; } synchronized ( id ) { oldOplogId = id . setOplogId ( getOplogId ( ) ) ; if ( EntryBits . isAnyInvalid ( userBits ) || EntryBits . isTombstone ( userBits ) ) { id . setOffsetInOplog ( - 1 ) ; } else { id . setOffsetInOplog ( startPosForSynchOp ) ; } } this . dirHolder . incrementTotalOplogSize ( adjustment ) ; this . incTotalCount ( ) ; EntryLogger . logPersistPut ( dr . getName ( ) , entry . getKey ( ) , dr . getDiskStoreID ( ) ) ; if ( oldOplogId != getOplogId ( ) ) { Oplog oldOplog = getOplogSet ( ) . getChild ( oldOplogId ) ; if ( oldOplog != null ) { oldOplog . rmLive ( dr , entry ) ; emptyOplog = oldOplog ; } addLive ( dr , entry ) ; } else { getOrCreateDRI ( dr ) . update ( entry ) ; } RegionVersionVector rvv = dr . getRegionVersionVector ( ) ; if ( rvv != null && entry . getVersionStamp ( ) != null ) { rvv . recordVersion ( entry . getVersionStamp ( ) . getMemberID ( ) , entry . getVersionStamp ( ) . getRegionVersion ( ) ) ; } } clearOpState ( ) ; } } if ( useNextOplog ) { if ( LocalRegion . ISSUE_CALLBACKS_TO_CACHE_OBSERVER ) { CacheObserverHolder . getInstance ( ) . afterSwitchingOplog ( ) ; } Assert . assertTrue ( getOplogSet ( ) . getChild ( ) != this ) ; getOplogSet ( ) . getChild ( ) . basicModify ( dr , entry , value , userBits , async , calledByCompactor ) ; } else { if ( LocalRegion . ISSUE_CALLBACKS_TO_CACHE_OBSERVER ) { CacheObserverHolder . getInstance ( ) . afterSettingOplogOffSet ( startPosForSynchOp ) ; } if ( emptyOplog != null && ( ! emptyOplog . isCompacting ( ) || emptyOplog . calledByCompactorThread ( ) ) ) { if ( calledByCompactor && emptyOplog . hasNoLiveValues ( ) ) { flushAll ( true ) ; } emptyOplog . handleNoLiveValues ( ) ; } } }
asif : a helper function which identifies whether to modify the entry in the current oplog or to make the switch to the next oplog . this function enables us to reuse the byte buffer which got created for an oplog which no longer permits us to use itself . it will also take acre of compaction if required
