Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je.rep.vlsn;
  
 import static com.sleepycat.je.utilint.VLSN.NULL_VLSN;
 
 
 public class VLSNRange {
 
     /* On-disk version. */
     private static final int VERSION = 1;
     public static final long RANGE_KEY = -1L;
     static final VLSNRange EMPTY = new VLSNRange(,
                                                  );
 
     /*
      * Information about the range of contiguous VLSN entries on this node.
      * All the range values must be viewed together, to ensure a consistent set
      * of values.
      */
     private final VLSN first;
     private final VLSN last;
     private final byte commitType = ..getTypeNum();
     private final byte abortType = ..getTypeNum();
 
     /*
      * VLSN of the last log entry in our VLSN range that can serve as a sync
      * matchpoint.
      */
     private final VLSN lastSync;
     private final VLSN lastTxnEnd;
 
     private VLSNRange(VLSN first,
                       VLSN last,
                       VLSN lastSync,
                       VLSN lastTxnEnd) {
         this. = first;
         this. = last;
         this. = lastSync;
         this. = lastTxnEnd;
     }

    
When the range is written out by the VLSNTracker, we must always be sure to update the tracker's lastVSLNOnDisk field. Return the last VLSN in the range as part of this method, to help ensure that update.

Parameters:
envImpl
dbImpl
txn
 
     VLSN writeToDatabase(final EnvironmentImpl envImpl,
                          final DatabaseImpl dbImpl,
                          Txn txn) {
 
         VLSNRangeBinding binding = new VLSNRangeBinding();
         DatabaseEntry key = new DatabaseEntry();
         DatabaseEntry data = new DatabaseEntry();
 
         LongBinding.longToEntry(key);
         binding.objectToEntry(thisdata);
 
         Cursor c = null;
         try {
             c = DbInternal.makeCursor(dbImpl
                                       txn,
                                       .);
             DbInternal.getCursorImpl(c).setAllowEviction(false);
 
             OperationStatus status = c.put(keydata);
             if (status != .) {
                 throw EnvironmentFailureException.unexpectedState
                     (envImpl"Unable to write VLSNRange, status = " + status);
             }
         } finally {
             if (c != null) {
                 c.close();
             }
         }
         return ;
    }
    public static VLSNRange readFromDatabase(DatabaseEntry data) {
        VLSNRangeBinding binding = new VLSNRangeBinding();
        VLSNRange range = binding.entryToObject(data);
        return range;
    }
    public VLSN getFirst() {
        return ;
    }
    public VLSN getLast() {
        return ;
    }
    public VLSN getLastSync() {
        return ;
    }
    public VLSN getLastTxnEnd() {
        return ;
    }

    
Return the VLSN that should come after the lastVLSN.
    VLSN getUpcomingVLSN() {
        return .getNext();
    }

    

Returns:
true if this VLSN is within the range described by this class.
    public boolean contains(final VLSN vlsn) {
        if (.equals()) {
            return false;
        }
        if ((.compareTo(vlsn) <= 0) && (.compareTo(vlsn) >= 0)) {
            return true;
        }
        return false;
    }

    
A new VLSN->LSN mapping has been registered in a bucket. Update the range accordingly.
    VLSNRange getUpdateForNewMapping(final VLSN newValue,
                                     final byte entryTypeNum) {
        VLSN newFirst = ;
        VLSN newLast = ;
        VLSN newLastSync = ;
        VLSN newLastTxnEnd = ;
        if (.equals() || .compareTo(newValue) > 0) {
            newFirst = newValue;
        }
        if (.compareTo(newValue) < 0) {
            newLast = newValue;
        }
        if (LogEntryType.isSyncPoint(entryTypeNum)) {
            if (.compareTo(newValue) < 0) {
                newLastSync = newValue;
            }
        }
        if ((entryTypeNum == ) || (entryTypeNum == )) {
            if (.compareTo(newValue) < 0) {
                newLastTxnEnd = newValue;
            }
        }
        return new VLSNRange(newFirstnewLastnewLastSyncnewLastTxnEnd);
    }

    
Incorporate the information in "other" in this range.
    VLSNRange getUpdate(final VLSNRange other) {
        VLSN newFirst = getComparison(other.first,
                                      other.first.compareTo() < 0);
        VLSN newLast = getComparison(other.last,
                                     other.last.compareTo() > 0);
        VLSN newLastSync =
            getComparison(other.lastSync,
                          other.lastSync.compareTo() > 0);
        VLSN newLastTxnEnd =
            getComparison(other.lastTxnEnd,
                          other.lastTxnEnd.compareTo() > 0);
        return new VLSNRange(newFirstnewLastnewLastSyncnewLastTxnEnd);
    }

    
The "other" range is going to be appended to this range.
    VLSNRange merge(final VLSNRange other) {
        VLSN newLast = getComparison(other.lasttrue);
        VLSN newLastSync = getComparison(other.lastSynctrue);
        VLSN newLastTxnEnd = getComparison(other.lastTxnEndtrue);
        return new VLSNRange(newLastnewLastSyncnewLastTxnEnd);
    }
    /*
     * We can assume that deleteStart.getPrev() is either NULL_VLSN or is
     * on a sync-able boundary. We can also assume that lastTxnEnd has not
     * been changed. And lastly, we can assume that this range is not empty,
     * since that was checked earlier on.
     */
    VLSNRange shortenFromEnd(final VLSN deleteStart) {
        VLSN newLast = deleteStart.getPrev();
        assert newLast.compareTo() >= 0 :
        "Can't truncate at " + newLast +
            " because it overwrites a commit at " +  ;
        if (newLast.equals()) {
            return new VLSNRange();
        }
        return new VLSNRange(newLastnewLast);
    }
    /*
     * @return an new VLSNRange which starts at deleteEnd.getNext()
     */
    VLSNRange shortenFromHead(final VLSN deleteEnd) {
        /* We shouldn't be truncating the last sync */
        VLSN newFirst = null;
        VLSN newLast = ;
        if (deleteEnd.compareTo() == 0) {
            newFirst = ;
            newLast = ;
        } else {
            newFirst = deleteEnd.getNext();
        }
        assert (.equals() ||
                .compareTo(newFirst) >= 0 ) :
            "Can't truncate lastSync= " +  + " deleteEnd=" + deleteEnd;
        VLSN newTxnEnd = .compareTo(newFirst) > 0 ?
             : ;
        return new VLSNRange(newFirstnewLastnewTxnEnd);
    }

    
Compare two VLSNs, normalizing for NULL_VLSN. If one of them is NULL_VLSN, return the other one. If neither are NULL_VLSN, use the result of the comparison, expressed as the value of "better" to decide which one to return. If "better" is true, return "otherVLSN".
    private VLSN getComparison(final VLSN thisVLSN,
                               final VLSN otherVLSN,
                               final boolean better) {
        if (thisVLSN.equals()) {
            return otherVLSN;
        }
        if (otherVLSN.equals()) {
            return thisVLSN;
        }
        if (better) {
            return otherVLSN;
        }
        return thisVLSN;
    }
    boolean isEmpty() {
        return .equals();
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("first=").append();
        sb.append(" last=").append();
        sb.append(" sync=").append();
        sb.append(" txnEnd=").append();
        return sb.toString();
    }

    
Marshals a VLSNRange to a byte buffer to store in the database.
    static class VLSNRangeBinding extends TupleBinding<VLSNRange> {
        @Override
        public VLSNRange entryToObject(final TupleInput ti) {
            int onDiskVersion = ti.readPackedInt();
            if (onDiskVersion != ) {
                throw EnvironmentFailureException.unexpectedState
                    ("Don't expect version diff " +
                     "on_disk=" + onDiskVersion +
                     " source=" +
                     );
            }
            VLSNRange range =
                new VLSNRange(new VLSN(ti.readPackedLong()), // first
                              new VLSN(ti.readPackedLong()), // last
                              new VLSN(ti.readPackedLong()), // lastSync
                              new VLSN(ti.readPackedLong())); // lastTxnEnd
            return range;
        }
        @Override
        public void objectToEntry(final VLSNRange range,
                                  final TupleOutput to) {
            /* No need to store the file number -- that's the key */
            to.writePackedInt();
            to.writePackedLong(range.getFirst().getSequence());
            to.writePackedLong(range.getLast().getSequence());
            to.writePackedLong(range.getLastSync().getSequence());
            to.writePackedLong(range.getLastTxnEnd().getSequence());
        }
    }
    boolean verify(final boolean verbose) {
        if (.equals()) {
            if (!(.equals() &&
                  (.equals()) &&
                  (.equals()))) {
                if (verbose) {
                    ..println("Range: All need to be NULL_VLSN " +
                                       this);
                }
                return false;
            }
        } else {
            if (.compareTo() > 0) {
                if (verbose) {
                    ..println("Range: first > last " + this);
                }
                return false;
            }
            if (!.equals()) {
                if (.compareTo() > 0) {
                    if (verbose) {
                        ..println("Range: lastSync > last " + this);
                    }
                    return false;
                }
            }
            if (!.equals()) {
                if (.compareTo() > 0) {
                    if (verbose) {
                        ..println("Range: lastTxnEnd > last " + this);
                    }
                    return false;
                }
            }
        }
        return true;
    }

    

Returns:
true if subsetRange is a subset of this range.
    boolean verifySubset(final boolean verbosefinal VLSNRange subsetRange) {
        if (subsetRange == null) {
            return true;
        }
        if ((subsetRange.getFirst().equals()) &&
            (subsetRange.getLast().equals()) &&
            (subsetRange.getLastSync().equals()) &&
            (subsetRange.getLastTxnEnd().equals())) {
            return true;
        }
    
        if (.compareTo(subsetRange.getFirst()) >  0) {
            if (verbose) {
                ..println("Range: subset must be LTE: this=" + this +
                                   " subset=" + subsetRange);
            }
            return false;
        }
        if (.equals()) {
            return true;
        }
        if (.compareTo(subsetRange.getLast()) < 0) {
            if (verbose) {
                ..println("Range: last must be GTE: this=" + this +
                                   " subsetRange=" + subsetRange);
            }
            return false;
        }
        return true;
    }
New to GrepCode? Check out our FAQ X