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;
  
 import java.util.Map;
 
Accumulates changes to the utilization profile during recovery.

Per-database information is keyed by DatabaseId because the DatabaseImpl is not always available during recovery. In fact this is the only reason that a "local" tracker is used during recovery -- to avoid requiring that the DatabaseImpl is available, which is necessary to use the "global" UtilizationTracker. There is no requirement to accumulate totals locally, since recovery is single threaded.

When finished with this object, its information should be added to the Environment's UtilizationTracker and DatabaseImpl objects by calling transferToUtilizationTracker. This is done at the end of recovery, just prior to the checkpoint. It does not have to be done under the log write latch, since recovery is single threaded.

 
 
     /* File number -> LSN of FileSummaryLN */
     private final Map<LongLongfileSummaryLsns;
     /* DatabaseId  -> LSN of MapLN */
     private final Map<DatabaseIdLongdatabaseLsns;
 
         super(envnew HashMap<Object,DbFileSummaryMap>());
          = new HashMap<LongLong>();
          = new HashMap<DatabaseIdLong>();
     }

    
Saves the LSN of the last logged FileSummaryLN.
 
     public void saveLastLoggedFileSummaryLN(long fileNumlong lsn) {
         .put(Long.valueOf(fileNum), Long.valueOf(lsn));
     }

    
Saves the LSN of the last logged MapLN.
 
     public void saveLastLoggedMapLN(DatabaseId dbIdlong lsn) {
         .put(dbId, Long.valueOf(lsn));
     }

    
Counts the addition of all new log entries including LNs.
 
     public void countNewLogEntry(long lsn,
                                  LogEntryType type,
                                  int size,
                                  DatabaseId dbId) {
         countNew(lsndbIdtypesize);
     }

    
Counts the LSN of a node obsolete unconditionally.

Even when countExact is true, duplicate offsets are not checked (no assertion is fired) because recovery is known to count the same LSN offset twice in certain circumstances.

 
     public void countObsoleteUnconditional(long lsn,
                                            LogEntryType type,
                                            int size,
                                            DatabaseId dbId,
                                            boolean countExact) {
         countObsolete
             (lsndbIdtypesize,
              true,       // countPerFile
              true,       // countPerDb
              countExact// trackOffset
              false);     // checkDupOffsets
     }

    
Counts the oldLsn of a node obsolete if it has not already been counted at the point of newLsn in the log.

Even when countExact is true, duplicate offsets are not checked (no assertion is fired) because recovery is known to count the same LSN offset twice in certain circumstances.

Returns:
whether the file was previously uncounted.
    public boolean countObsoleteIfUncounted(long oldLsn,
                                            long newLsn,
                                            LogEntryType type,
                                            int size,
                                            DatabaseId dbId,
                                            boolean countExact) {
        Long fileNum = Long.valueOf(DbLsn.getFileNumber(oldLsn));
        boolean fileUncounted = isFileUncounted(fileNumnewLsn);
        boolean dbUncounted = isDbUncounted(dbIdnewLsn);
        countObsolete
            (oldLsndbIdtypesize,
             fileUncounted// countPerFile
             dbUncounted,   // countPerDb
             countExact,    // trackOffset
             false);        // checkDupOffsets
        return fileUncounted;
    }

    
Fetches the LN to get its size only if necessary and so configured.
    public int fetchLNSize(int sizelong lsn)
        throws DatabaseException {
        if (size == 0 && .getCleaner().getFetchObsoleteSize()) {
            try {
                LN ln = (LN.getLogManager().getEntry(lsn);
                size = ln.getLastLoggedSize();
            } catch (FileNotFoundException e) {
                /* Ignore errors if the file was cleaned. */
            }
        }
        return size;
    }

    
Overrides this method for recovery and returns whether the FileSummaryLN for the given file is prior to the given LSN.
    @Override
    boolean isFileUncounted(Long fileNumlong lsn) {
        long fsLsn = DbLsn.longToLsn(.get(fileNum));
        int cmpFsLsnToNewLsn = (fsLsn != .) ?
            DbLsn.compareTo(fsLsnlsn) : -1;
        return cmpFsLsnToNewLsn < 0;
    }

    
Returns whether the MapLN for the given database ID is prior to the given LSN.
    private boolean isDbUncounted(DatabaseId dbIdlong lsn) {
        long dbLsn = DbLsn.longToLsn(.get(dbId));
        int cmpDbLsnToLsn = (dbLsn != .) ?
            DbLsn.compareTo(dbLsnlsn) : -1;
        return cmpDbLsnToLsn < 0;
    }

    
Clears all accmulated utilization info for the given file.
    public void resetFileInfo(long fileNum) {
        TrackedFileSummary trackedSummary = getTrackedFile(fileNum);
        if (trackedSummary != null) {
            trackedSummary.reset();
        }
    }

    
Clears all accmulated utilization info for the given database.
    public void resetDbInfo(DatabaseId dbId) {
        removeDbFileSummaries(dbId);
    }

    
Returns the DatabaseImpl from the database key, which in this case is the DatabaseId.
    @Override
        throws DatabaseException {
        DatabaseId dbId = (DatabaseIddatabaseKey;
        return .getDbTree().getDb(dbId);
    }

    
Must release the database, since DbTree.getDb was called by databaseKeyToDatabaseImpl.
    @Override
    void releaseDatabaseImpl(DatabaseImpl db) {
        .getDbTree().releaseDb(db);
    }
New to GrepCode? Check out our FAQ X