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.cleaner;
  
 
Per-file utilization counters. The UtilizationProfile stores a persistent map of file number to FileSummary.
 
 public class FileSummary implements LoggableCloneable {
 
     /* Persistent fields. */
     public int totalCount;      // Total # of log entries
     public int totalSize;       // Total bytes in log file
     public int totalINCount;    // Number of IN log entries
     public int totalINSize;     // Byte size of IN log entries
     public int totalLNCount;    // Number of LN log entries
     public int totalLNSize;     // Byte size of LN log entries
     public int maxLNSize;       // Byte size of largest LN log entry
     public int obsoleteINCount// Number of obsolete IN log entries
     public int obsoleteLNCount// Number of obsolete LN log entries
     public int obsoleteLNSize;  // Byte size of obsolete LN log entries
     public int obsoleteLNSizeCounted;  // Number obsolete LNs with size counted
 
    
Creates an empty summary.
 
     public FileSummary() {
     }
 
     public FileSummary clone() {
         try {
             return (FileSummarysuper.clone();
         } catch (CloneNotSupportedException willNeverOccur) {
             return null;
         }
     }

    
Returns whether this summary contains any non-zero totals.
 
     public boolean isEmpty() {
 
         return  == 0 &&
                 == 0 &&
                 == 0 &&
                 == 0;
     }

    
Returns the approximate byte size of all obsolete LN entries, using the default average LN size for LN sizes that were not counted.
 
     public int getObsoleteLNSize() {
         return getObsoleteLNSize(.);
     }

    
Returns the approximate byte size of all obsolete LN entries, using the given average LN size for LN sizes that were not counted.

Parameters:
obsoleteLNSizeCorrectionFactor is the correction factor to use for uncounted LNs, or NaN to use the default average size calculation.
 
     public int getObsoleteLNSize(float obsoleteLNSizeCorrectionFactor) {
 
         if ( == 0) {
             return 0;
         }
 
         /* Normalize obsolete amounts to account for double-counting. */
         final int obsLNCount = Math.min();
         final int obsLNSize = Math.min();
         final int obsLNSizeCounted = Math.min(,
                                               obsLNCount);
 
         /*
          * Use the tracked obsolete size for all entries for which the size was
          * counted, plus the average size for all obsolete entries whose size
          * was not counted.
          */
         long obsSize = obsLNSize;
         final int obsCountNotCounted = obsLNCount - obsLNSizeCounted;
         if (obsCountNotCounted > 0) {
 
             /*
              * When there are any obsolete LNs with sizes uncounted, we add an
              * obsolete amount that is the product of the number of LNs
              * uncounted and the corrected average LN size.
             */
            if (Float.isNaN(obsoleteLNSizeCorrectionFactor)) {
                obsoleteLNSizeCorrectionFactor = 1.0F;
            }
            final float avgLNSizeNotCounted =
                getAvgObsoleteLNSizeNotCounted() *
                obsoleteLNSizeCorrectionFactor;
            if (!Float.isNaN(avgLNSizeNotCounted)) {
                obsSize += (int) (obsCountNotCounted * avgLNSizeNotCounted);
            }
        }
        /* Don't return an impossibly large estimate. */
        return (obsSize > ) ?  : (intobsSize;
    }

    
Returns the average size for LNs with sizes not counted, or NaN if there are no such LNs. In FileSummaryLN version 3 and greater the obsolete size is normally counted, but not in exceptional circumstances such as recovery. If it is not counted, obsoleteLNSizeCounted will be less than obsoleteLNCount. In log version 8 and greater, we don't count the size when the LN is not resident in cache during update/delete. We added maxLNSize in version 8 for use in estimating obsolete LN sizes. To compute the average LN size, we only consider the LNs (both obsolete and non-obsolete) for which the size has not been counted. This increases accuracy when counted and uncounted LN sizes are not uniform. An example is when large LNs are inserted and deleted. The size of the deleted LN log entry (which is small) is always counted, but the previous version (which has a large size) may not be counted.
    public float getAvgObsoleteLNSizeNotCounted() {
        /* Normalize obsolete amounts to account for double-counting. */
        final int obsLNCount = Math.min();
        final int obsLNSize = Math.min();
        final int obsLNSizeCounted = Math.min(,
                                              obsLNCount);
        final int obsCountNotCounted = obsLNCount - obsLNSizeCounted;
        if (obsCountNotCounted <= 0) {
            return .;
        }
        final int totalSizeNotCounted =  - obsLNSize;
        final int totalCountNotCounted =  - obsLNSizeCounted;
        if (totalSizeNotCounted <= 0 || totalCountNotCounted <= 0) {
            return .;
        }
        return totalSizeNotCounted / ((floattotalCountNotCounted);
    }

    
Returns the maximum possible obsolete LN size, using the maximum LN size for LN sizes that were not counted.
    public int getMaxObsoleteLNSize() {
        /*
         * In log version 7 and earlier the maxLNSize is not available.  It is
         * safe to use getObsoleteLNSize in that case, because LSN locking was
         * not used and the obsolete size was counted for updates and deletes.
         */
        if ( == 0) {
            return getObsoleteLNSize();
        }
        if ( == 0) {
            return 0;
        }
        /* Normalize obsolete amounts to account for double-counting. */
        final int obsLNCount = Math.min();
        final int obsLNSize = Math.min();
        final int obsLNSizeCounted = Math.min(,
                                              obsLNCount);
        /*
         * Use the tracked obsolete size for all entries for which the size was
         * counted, plus the maximum possible size for all obsolete entries
         * whose size was not counted.
         */
        long obsSize = obsLNSize;
        final long obsCountNotCounted = obsLNCount - obsLNSizeCounted;
        if (obsCountNotCounted > 0) {
            /*
             * When there are any obsolete LNs with sizes uncounted, we add an
             * obsolete amount that is the minimum of two values.  Either value
             * may be much higher than the true obsolete amount, but by taking
             * their minimum we use a much more realistic obsolete amount.
             *
             * maxLNSizeNotCounted is the maximum obsolete not counted, based
             * on the multiplying maxLNSize and the number of obsolete LNs not
             * counted.
             *
             * maxObsSizeNotCounted is also an upper bound on the obsolete size
             * not not counted.  The (totalLNSize - obsLNSize) gives the amount
             * non-obsolete plus the obsolete amount not counted.  From this we
             * subtract the minimum non-obsolete size, based on the minimum
             * size of any LN.  This leaves the maximum obsolete size not
             * counted.
             *
             * Note that the mutiplication immediately below would overflow if
             * type 'int' instead of 'long' were used for the operands.  This
             * was fixed in [#21106].
             */
            final long maxLNSizeNotCounted = obsCountNotCounted * ;
            final long maxObsSizeNotCounted =  - obsLNSize -
                (( - obsLNCount) * .);
            obsSize += Math.min(maxLNSizeNotCountedmaxObsSizeNotCounted);
        }
        /* Don't return an impossibly large estimate. */
        return (obsSize > ) ?  : (intobsSize;
    }

    
Returns the approximate byte size of all obsolete IN entries.
    public int getObsoleteINSize() {
        if ( == 0) {
            return 0;
        }
        /* Normalize obsolete amounts to account for double-counting. */
        final int obsINCount = Math.min();
        /* Use average IN size to compute total. */
        final float size = ;
        final float avgSizePerIN = size / ;
        return (int) (obsINCount * avgSizePerIN);
    }

    
Returns an estimate of the total bytes that are obsolete, using getObsoleteLNSize instead of getMaxObsoleteLNSize.
    public int getObsoleteSize() {
        return calculateObsoleteSize(getObsoleteLNSize());
    }

    
Returns an estimate of the total bytes that are obsolete, using a given correction factor for LN sizes that were not counted.
    public int getObsoleteSize(float obsoleteLNSizeCorrectionFactor) {
        return calculateObsoleteSize
            (getObsoleteLNSize(obsoleteLNSizeCorrectionFactor));
    }

    
Returns an estimate of the total bytes that are obsolete, using getMaxObsoleteLNSize instead of getObsoleteLNSize.
    public int getMaxObsoleteSize() {
    }
    private int calculateObsoleteSize(int lnObsoleteSize) {
        if ( > 0) {
            /* Leftover (non-IN non-LN) space is considered obsolete. */
            final int leftoverSize =  - ( + );
            int obsoleteSize = lnObsoleteSize +
                               getObsoleteINSize() +
                               leftoverSize;
            /*
             * Don't report more obsolete bytes than the total.  We may
             * calculate more than the total because of (intentional)
             * double-counting during recovery.
             */
            if (obsoleteSize > ) {
                obsoleteSize = ;
            }
            return obsoleteSize;
        } else {
            return 0;
        }
    }

    
Returns the total number of entries counted. This value is guaranted to increase whenever the tracking information about a file changes. It is used a key discriminator for FileSummaryLN records.
    public int getEntriesCounted() {
        return  +  + ;
    }

    
Returns the number of non-obsolete LN and IN entries.
    public int getNonObsoleteCount() {
        return  +
                -
                -
               ;
    }

    
Calculates utilization percentage using average LN sizes.
    public int utilization() {
        return utilization(getObsoleteSize(), );
    }

    
Calculates utilization percentage using average LN sizes, using a given correction factor for LN sizes that were not counted.
    public int utilization(float obsoleteLNSizeCorrectionFactor) {
        return utilization(getObsoleteSize(obsoleteLNSizeCorrectionFactor),
                           );
    }

    
Calculates a utilization percentage.
    public static int utilization(long obsoleteSizelong totalSize) {
        if (totalSize == 0) {
            return 0;
        }
        return Math.round(((100.0F * (totalSize - obsoleteSize)) / totalSize));
    }

    
Reset all totals to zero.
    public void reset() {
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
         = 0;
    }

    
Add the totals of the given summary object to the totals of this object.
    public void add(FileSummary o) {
         += o.totalCount;
         += o.totalSize;
         += o.totalINCount;
         += o.totalINSize;
         += o.totalLNCount;
         += o.totalLNSize;
        if ( < o.maxLNSize) {
             = o.maxLNSize;
        }
         += o.obsoleteINCount;
         += o.obsoleteLNCount;
         += o.obsoleteLNSize;
         += o.obsoleteLNSizeCounted;
    }

    
    public int getLogSize() {
        return 11 * LogUtils.getIntLogSize();
    }

    
    public void writeToLog(ByteBuffer buf) {
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
        LogUtils.writeInt(buf);
    }

    
    public void readFromLog(ByteBuffer bufint entryVersion) {
         = LogUtils.readInt(buf);
         = LogUtils.readInt(buf);
         = LogUtils.readInt(buf);
         = LogUtils.readInt(buf);
         = LogUtils.readInt(buf);
         = LogUtils.readInt(buf);
        if (entryVersion >= 8) {
             = LogUtils.readInt(buf);
        }
         = LogUtils.readInt(buf);
        if ( == -1) {
            /*
             * If INs were not counted in an older log file written by 1.5.3 or
             * earlier, consider all INs to be obsolete.  This causes the file
             * to be cleaned, and then IN counting will be accurate.
             */
             = ;
        }
         = LogUtils.readInt(buf);
        /*
         * obsoleteLNSize and obsoleteLNSizeCounted were added in FileSummaryLN
         * version 3.
         */
        if (entryVersion >= 3) {
             = LogUtils.readInt(buf);
             = LogUtils.readInt(buf);
        } else {
             = 0;
             = 0;
        }
    }

    
    public void dumpLog(StringBuilder bufboolean verbose) {
        buf.append("<summary totalCount=\"");
        buf.append();
        buf.append("\" totalSize=\"");
        buf.append();
        buf.append("\" totalINCount=\"");
        buf.append();
        buf.append("\" totalINSize=\"");
        buf.append();
        buf.append("\" totalLNCount=\"");
        buf.append();
        buf.append("\" totalLNSize=\"");
        buf.append();
        buf.append("\" maxLNSize=\"");
        buf.append();
        buf.append("\" obsoleteINCount=\"");
        buf.append();
        buf.append("\" obsoleteLNCount=\"");
        buf.append();
        buf.append("\" obsoleteLNSize=\"");
        buf.append();
        buf.append("\" obsoleteLNSizeCounted=\"");
        buf.append();
        buf.append("\" getObsoleteSize=\"");
        buf.append(getObsoleteSize());
        buf.append("\" getObsoleteINSize=\"");
        buf.append(getObsoleteINSize());
        buf.append("\" getObsoleteLNSize=\"");
        buf.append(getObsoleteLNSize());
        buf.append("\" getMaxObsoleteSize=\"");
        buf.append(getMaxObsoleteSize());
        buf.append("\" getMaxObsoleteLNSize=\"");
        buf.append(getMaxObsoleteLNSize());
        buf.append("\" getAvgObsoleteLNSizeNotCounted=\"");
        buf.append("\"/>");
    }

    
    public long getTransactionId() {
        return 0;
    }

    

See also:
com.sleepycat.je.log.Loggable.logicalEquals(com.sleepycat.je.log.Loggable) Always return false, this item should never be compared.
    public boolean logicalEquals(Loggable other) {
        return false;
    }
    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder();
        dumpLog(buftrue);
        return buf.toString();
    }
New to GrepCode? Check out our FAQ X