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;
  
Delta file summary info for a tracked file. Tracked files are managed by the UtilizationTracker.

The methods in this class for reading obsolete offsets may be used by multiple threads without synchronization even while another thread is adding offsets. This is possible because elements are never deleted from the lists. The thread adding obsolete offsets does so under the log write latch to prevent multiple threads from adding concurrently.

 
 public class TrackedFileSummary extends FileSummary {
 
     private BaseUtilizationTracker tracker;
     private long fileNum;
     private OffsetList obsoleteOffsets;
     private int memSize;
     private boolean trackDetail;
     private boolean allowFlush = true;

    
Creates an empty tracked summary.
 
                        long fileNum,
                        boolean trackDetail) {
         this. = tracker;
         this. = fileNum;
         this. = trackDetail;
     }

    
Returns whether this summary is allowed or prohibited from being flushed or evicted during cleaning. By default, flushing is allowed.
 
     public boolean getAllowFlush() {
         return ;
     }

    
Allows or prohibits this summary from being flushed or evicted during cleaning. By default, flushing is allowed.
 
     void setAllowFlush(boolean allowFlush) {
         this. = allowFlush;
     }

    
Returns the file number being tracked.
 
     public long getFileNumber() {
         return ;
     }

    
Return the total memory size for this object. We only bother to budget obsolete detail, not the overhead for this object, for two reasons: 1) The number of these objects is very small, and 2) unit tests disable detail tracking as a way to prevent budget adjustments here.
 
     int getMemorySize() {
         return ;
     }

    
Overrides reset for a tracked file, and is called when a FileSummaryLN is written to the log.

Must be called under the log write latch.

 
     @Override
     public void reset() {
 
          = null;
 
         .resetFile(this);
 
         if ( > 0) {
             updateMemoryBudget(0 - );
         }
 
         super.reset();
     }

    
Tracks the given offset as obsolete or non-obsolete.

Must be called under the log write latch.

 
    void trackObsolete(long offsetboolean checkDupOffsets) {
        if (!) {
            return;
        }
        int adjustMem = 0;
        if ( == null) {
             = new OffsetList();
            adjustMem += .;
        }
        if (.add(offsetcheckDupOffsets)) {
            adjustMem += .;
        }
        if (adjustMem != 0) {
            updateMemoryBudget(adjustMem);
        }
    }

    
Adds the obsolete offsets as well as the totals of the given object.
    void addTrackedSummary(TrackedFileSummary other) {
        /* Add the totals. */
        add(other);
        /*
         * Add the offsets and the memory used [#15505] by the other tracker.
         * The memory budget has already been updated for the offsets to be
         * added, so we only need to account for a possible difference of one
         * segment when we merge them.
         */
         += other.memSize;
        if (other.obsoleteOffsets != null) {
            if ( != null) {
                /* Merge the other offsets into our list. */
                if (.merge(other.obsoleteOffsets)) {
                    /* There is one segment less as a result of the merge. */
                    updateMemoryBudget
                        (- .);
                }
            } else {
                /* Adopt the other's offsets as our own. */
                 = other.obsoleteOffsets;
            }
        }
    }

    
Returns obsolete offsets as an array of longs, or null if none.
    public long[] getObsoleteOffsets() {
        if ( != null) {
            return .toArray();
        } else {
            return null;
        }
    }

    
Returns whether the given offset is present in the tracked offsets. This does not indicate whether the offset is obsolete in general, but only if it is known to be obsolete in this version of the tracked information.
    boolean containsObsoleteOffset(long offset) {
        if ( != null) {
            return .contains(offset);
        } else {
            return false;
        }
    }
    private void updateMemoryBudget(int delta) {
         += delta;
    }

    
Update memory budgets when this tracker is closed and will never be accessed again.
    void close() {
         = 0;
    }
New to GrepCode? Check out our FAQ X