com.sleepycat.je.log
Class LogManager

java.lang.Object
  extended by com.sleepycat.je.log.LogManager
Direct Known Subclasses:
LatchedLogManager, SyncedLogManager

public abstract class LogManager
extends Object

The LogManager supports reading and writing to the JE log.


Field Summary
protected  EnvironmentImpl envImpl
           
protected  LogBufferPool logBufferPool
           
protected  Latch logWriteLatch
           
 
Constructor Summary
LogManager(EnvironmentImpl envImpl, boolean readOnly)
          There is a single log manager per database environment.
 
Method Summary
abstract  void countObsoleteDb(DatabaseImpl db)
           
(package private)  void countObsoleteDbInternal(DatabaseImpl db)
           
abstract  void countObsoleteNode(long lsn, LogEntryType type, int size, DatabaseImpl nodeDb, boolean countExact)
          Count node as obsolete under the log write latch.
abstract  void countObsoleteNodeDupsAllowed(long lsn, LogEntryType type, int size, DatabaseImpl nodeDb)
          A flavor of countObsoleteNode which does not fire an assert if the offset has already been counted.
(package private)  void countObsoleteNodeDupsAllowedInternal(long lsn, LogEntryType type, int size, DatabaseImpl nodeDb)
           
(package private)  void countObsoleteNodeInternal(long lsn, LogEntryType type, int size, DatabaseImpl nodeDb, boolean countExact)
           
 void flush()
          Flush all log entries, fsync the log file.
(package private) abstract  void flushInternal()
           
 void flushNoSync()
          May be used to avoid sync, for unit tests and for rep syncup.
 ByteBuffer getByteBufferFromLog(long lsn)
          Return a ByteBuffer holding the log entry at this LSN.
 boolean getChecksumOnRead()
           
 Object getEntry(long lsn)
          Fault in the first object in the log entry log entry at this LSN.
 Object getEntryHandleFileNotFound(long lsn)
           
 long getLastLsnAtRecovery()
           
 LogEntry getLogEntry(long lsn)
          Instantiate all the objects in the log entry at this LSN.
(package private)  LogEntry getLogEntryAllowChecksumException(long lsn)
          Throws ChecksumException rather than translating it to EnvironmentFailureException and invalidating the environment.
(package private)  LogEntry getLogEntryAllowChecksumException(long lsn, RandomAccessFile file, int logVersion)
           
 WholeEntry getLogEntryAllowInvisible(long lsn)
          Instantiate all the objects in the log entry at this LSN.
 LogEntry getLogEntryAllowInvisibleAtRecovery(long lsn)
          Instantiate all the objects in the log entry at this LSN.
(package private)  WholeEntry getLogEntryFromLogSource(long lsn, LogSource logSource, boolean invisibleReadAllowed)
          Instantiate all the objects in the log entry at this LSN.
 LogEntry getLogEntryHandleFileNotFound(long lsn)
           
 LogSource getLogSource(long lsn)
          Find the LSN, whether in a file or still in the log buffers.
 LogBuffer getReadBufferByLsn(long lsn)
          Return a log buffer locked for reading, or null if no log buffer holds this LSN location.
abstract  TrackedFileSummary getUnflushableTrackedSummary(long file)
          Returns a tracked summary for the given file which will not be flushed.
(package private)  TrackedFileSummary getUnflushableTrackedSummaryInternal(long file)
           
abstract  void loadEndOfLogStat()
           
(package private)  void loadEndOfLogStatInternal()
           
 StatGroup loadStats(StatsConfig config)
           
 long log(LogEntry entry, boolean isProvisional, boolean backgroundIO, long oldNodeLsn, DatabaseImpl nodeDb, ReplicationContext repContext)
          Write a log entry.
 long log(LogEntry entry, Provisional provisional, boolean backgroundIO, long oldNodeLsn, DatabaseImpl nodeDb, ReplicationContext repContext)
          Write a log entry.
 long log(LogEntry entry, ReplicationContext repContext)
          Write a log entry.
 void log(LogItem item, LogContext context)
          Convenience method for logging a single entry.
 long logForceFlip(LogEntry entry)
          Log this single object and force a flip of the log files.
 long logForceFlush(LogEntry entry, boolean fsyncRequired, ReplicationContext repContext)
          Log this single object and force a write of the log files.
 void logLazily(LogEntry entry, ReplicationContext repContext)
          Write a log entry lazily.
 void multiLog(LogItem[] itemArray, LogContext context)
           
(package private)  ByteBuffer putIntoBuffer(LogEntry entry, long prevLogEntryOffset)
          Serialize a log entry into this buffer with proper entry header.
abstract  boolean removeDbFileSummary(DatabaseImpl db, Long fileNum)
           
(package private)  boolean removeDbFileSummaryInternal(DatabaseImpl db, Long fileNum)
           
abstract  void removeTrackedFile(TrackedFileSummary tfs)
          Removes the tracked summary for the given file.
protected  void removeTrackedFileInternal(TrackedFileSummary tfs)
           
 void resetPool(DbConfigManager configManager)
          Reset the pool when the cache is resized.
(package private) abstract  void serialLog(LogItem[] itemArray, LogContext context)
          Log one or more items while latched or synchronized in order to serialize log output.
(package private)  void serialLogInternal(LogItem[] itemArray, LogContext context)
          Called within the log write critical section.
 void setDelayVLSNRegisterHook(TestHook<Object> hook)
           
 void setFlushLogHook(TestHook<CountDownLatch> hook)
           
 void setLastLsnAtRecovery(long lastLsnAtRecovery)
           
 void setReadHook(TestHook hook)
           
abstract  void transferToUtilizationTracker(LocalUtilizationTracker localTracker)
           
(package private)  void transferToUtilizationTrackerInternal(LocalUtilizationTracker localTracker)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logBufferPool

protected LogBufferPool logBufferPool

logWriteLatch

protected Latch logWriteLatch

envImpl

protected EnvironmentImpl envImpl
Constructor Detail

LogManager

public LogManager(EnvironmentImpl envImpl,
                  boolean readOnly)
           throws DatabaseException
There is a single log manager per database environment.

Throws:
DatabaseException
Method Detail

getChecksumOnRead

public boolean getChecksumOnRead()

getLastLsnAtRecovery

public long getLastLsnAtRecovery()

setLastLsnAtRecovery

public void setLastLsnAtRecovery(long lastLsnAtRecovery)

resetPool

public void resetPool(DbConfigManager configManager)
               throws DatabaseException
Reset the pool when the cache is resized. This method is called after the memory budget has been calculated.

Throws:
DatabaseException

logForceFlush

public long logForceFlush(LogEntry entry,
                          boolean fsyncRequired,
                          ReplicationContext repContext)
                   throws DatabaseException
Log this single object and force a write of the log files.

Parameters:
entry - object to be logged
fsyncRequired - if true, log files should also be fsynced.
Returns:
LSN of the new log entry
Throws:
DatabaseException

logForceFlip

public long logForceFlip(LogEntry entry)
                  throws DatabaseException
Log this single object and force a flip of the log files.

Parameters:
entry - object to be logged
Returns:
LSN of the new log entry
Throws:
DatabaseException

log

public long log(LogEntry entry,
                ReplicationContext repContext)
         throws DatabaseException
Write a log entry.

Parameters:
entry - object to be logged
Returns:
LSN of the new log entry
Throws:
DatabaseException

logLazily

public void logLazily(LogEntry entry,
                      ReplicationContext repContext)
Write a log entry lazily.

Parameters:
entry - object to be logged

log

public long log(LogEntry entry,
                boolean isProvisional,
                boolean backgroundIO,
                long oldNodeLsn,
                DatabaseImpl nodeDb,
                ReplicationContext repContext)
         throws DatabaseException
Write a log entry.

Parameters:
entry - object to be logged
isProvisional - true if this entry should not be read during recovery.
backgroundIO - if true, sleep when the backgroundIOLimit is exceeded.
oldNodeLsn - is the previous version of the node to be counted as obsolete, or NULL_LSN if the entry is not a node or has no old LSN.
nodeDb - database of the node, or null if entry is not a node.
Returns:
LSN of the new log entry
Throws:
DatabaseException

log

public long log(LogEntry entry,
                Provisional provisional,
                boolean backgroundIO,
                long oldNodeLsn,
                DatabaseImpl nodeDb,
                ReplicationContext repContext)
         throws DatabaseException
Write a log entry.

Parameters:
entry - object to be logged
provisional - whether this entry should be processed during recovery.
backgroundIO - if true, sleep when the backgroundIOLimit is exceeded.
oldNodeLsn - is the previous version of the node to be counted as obsolete, or NULL_LSN if the entry is not a node or has no old LSN.
nodeDb - database of the node, or null if entry is not a node.
Returns:
LSN of the new log entry
Throws:
DatabaseException

log

public void log(LogItem item,
                LogContext context)
         throws DatabaseException
Convenience method for logging a single entry.

Throws:
DatabaseException

multiLog

public void multiLog(LogItem[] itemArray,
                     LogContext context)
              throws DatabaseException
Throws:
DatabaseException

serialLog

abstract void serialLog(LogItem[] itemArray,
                        LogContext context)
                 throws IOException,
                        DatabaseException
Log one or more items while latched or synchronized in order to serialize log output. Implementations of this method call serialLogInternal.

Throws:
IOException
DatabaseException

serialLogInternal

void serialLogInternal(LogItem[] itemArray,
                       LogContext context)
                 throws IOException,
                        DatabaseException
Called within the log write critical section.

Throws:
IOException
DatabaseException

putIntoBuffer

ByteBuffer putIntoBuffer(LogEntry entry,
                         long prevLogEntryOffset)
Serialize a log entry into this buffer with proper entry header. Return it ready for a copy.


getLogEntry

public LogEntry getLogEntry(long lsn)
                     throws FileNotFoundException
Instantiate all the objects in the log entry at this LSN.

Throws:
FileNotFoundException

getLogEntryAllowInvisibleAtRecovery

public LogEntry getLogEntryAllowInvisibleAtRecovery(long lsn)
                                             throws FileNotFoundException
Instantiate all the objects in the log entry at this LSN. Allow the fetch of invisible log entries if we are in recovery.

Throws:
FileNotFoundException

getLogEntryAllowInvisible

public WholeEntry getLogEntryAllowInvisible(long lsn)
                                     throws FileNotFoundException
Instantiate all the objects in the log entry at this LSN. The entry may be marked invisible.

Throws:
FileNotFoundException

getLogEntryHandleFileNotFound

public LogEntry getLogEntryHandleFileNotFound(long lsn)
                                       throws DatabaseException
Throws:
DatabaseException

getLogEntryAllowChecksumException

LogEntry getLogEntryAllowChecksumException(long lsn)
                                     throws ChecksumException,
                                            FileNotFoundException,
                                            DatabaseException
Throws ChecksumException rather than translating it to EnvironmentFailureException and invalidating the environment. Used instead of getLogEntry when a ChecksumException is handled specially.

Throws:
ChecksumException
FileNotFoundException
DatabaseException

getLogEntryAllowChecksumException

LogEntry getLogEntryAllowChecksumException(long lsn,
                                           RandomAccessFile file,
                                           int logVersion)
                                     throws ChecksumException,
                                            DatabaseException
Throws:
ChecksumException
DatabaseException

getLogEntryFromLogSource

WholeEntry getLogEntryFromLogSource(long lsn,
                                    LogSource logSource,
                                    boolean invisibleReadAllowed)
                              throws ChecksumException,
                                     DatabaseException
Instantiate all the objects in the log entry at this LSN. This will release the log source at the first opportunity. Is non-private for unit testing.

Parameters:
lsn - location of entry in log
invisibleReadAllowed - if true, we will permit the read of invisible log entries, and we will adjust the invisible bit so that the checksum will validate
Returns:
log entry that embodies all the objects in the log entry
Throws:
ChecksumException
DatabaseException

getByteBufferFromLog

public ByteBuffer getByteBufferFromLog(long lsn)
                                throws DatabaseException
Return a ByteBuffer holding the log entry at this LSN. The log entry must begin at position 0, to mimic the marshalledBuffer used in logInternal().

Parameters:
lsn - location of entry in log
Returns:
log entry that embodies all the objects in the log entry
Throws:
DatabaseException

getEntry

public Object getEntry(long lsn)
                throws FileNotFoundException,
                       DatabaseException
Fault in the first object in the log entry log entry at this LSN.

Parameters:
lsn - location of object in log
Returns:
the object in the log
Throws:
FileNotFoundException
DatabaseException

getEntryHandleFileNotFound

public Object getEntryHandleFileNotFound(long lsn)

getLogSource

public LogSource getLogSource(long lsn)
                       throws FileNotFoundException,
                              ChecksumException,
                              DatabaseException
Find the LSN, whether in a file or still in the log buffers. Is public for unit testing.

Throws:
FileNotFoundException
ChecksumException
DatabaseException

getReadBufferByLsn

public LogBuffer getReadBufferByLsn(long lsn)
Return a log buffer locked for reading, or null if no log buffer holds this LSN location.


flush

public void flush()
           throws DatabaseException
Flush all log entries, fsync the log file.

Throws:
DatabaseException

flushNoSync

public void flushNoSync()
                 throws DatabaseException
May be used to avoid sync, for unit tests and for rep syncup.

Throws:
DatabaseException

flushInternal

abstract void flushInternal()
                     throws DatabaseException
Throws:
DatabaseException

loadStats

public StatGroup loadStats(StatsConfig config)
                    throws DatabaseException
Throws:
DatabaseException

getUnflushableTrackedSummary

public abstract TrackedFileSummary getUnflushableTrackedSummary(long file)
                                                         throws DatabaseException
Returns a tracked summary for the given file which will not be flushed. Used for watching changes that occur while a file is being cleaned.

Throws:
DatabaseException

getUnflushableTrackedSummaryInternal

TrackedFileSummary getUnflushableTrackedSummaryInternal(long file)

removeTrackedFile

public abstract void removeTrackedFile(TrackedFileSummary tfs)
                                throws DatabaseException
Removes the tracked summary for the given file.

Throws:
DatabaseException

removeTrackedFileInternal

protected void removeTrackedFileInternal(TrackedFileSummary tfs)

countObsoleteNode

public abstract void countObsoleteNode(long lsn,
                                       LogEntryType type,
                                       int size,
                                       DatabaseImpl nodeDb,
                                       boolean countExact)
                                throws DatabaseException
Count node as obsolete under the log write latch. This is done here because the log write latch is managed here, and all utilization counting must be performed under the log write latch.

Throws:
DatabaseException

countObsoleteNodeInternal

void countObsoleteNodeInternal(long lsn,
                               LogEntryType type,
                               int size,
                               DatabaseImpl nodeDb,
                               boolean countExact)

countObsoleteNodeDupsAllowed

public abstract void countObsoleteNodeDupsAllowed(long lsn,
                                                  LogEntryType type,
                                                  int size,
                                                  DatabaseImpl nodeDb)
                                           throws DatabaseException
A flavor of countObsoleteNode which does not fire an assert if the offset has already been counted. Called through the LogManager so that this incidence of all utilization counting can be performed under the log write latch.

Throws:
DatabaseException

countObsoleteNodeDupsAllowedInternal

void countObsoleteNodeDupsAllowedInternal(long lsn,
                                          LogEntryType type,
                                          int size,
                                          DatabaseImpl nodeDb)

transferToUtilizationTracker

public abstract void transferToUtilizationTracker(LocalUtilizationTracker localTracker)
                                           throws DatabaseException
Throws:
DatabaseException
See Also:
BaseLocalUtilizationTracker.transferToUtilizationTracker(com.sleepycat.je.cleaner.UtilizationTracker)

transferToUtilizationTrackerInternal

void transferToUtilizationTrackerInternal(LocalUtilizationTracker localTracker)
                                    throws DatabaseException
Throws:
DatabaseException

countObsoleteDb

public abstract void countObsoleteDb(DatabaseImpl db)
                              throws DatabaseException
Throws:
DatabaseException
See Also:
DatabaseImpl.countObsoleteDb(com.sleepycat.je.cleaner.BaseUtilizationTracker, long)

countObsoleteDbInternal

void countObsoleteDbInternal(DatabaseImpl db)

removeDbFileSummary

public abstract boolean removeDbFileSummary(DatabaseImpl db,
                                            Long fileNum)
                                     throws DatabaseException
Throws:
DatabaseException

removeDbFileSummaryInternal

boolean removeDbFileSummaryInternal(DatabaseImpl db,
                                    Long fileNum)

loadEndOfLogStat

public abstract void loadEndOfLogStat()
                               throws DatabaseException
Throws:
DatabaseException

loadEndOfLogStatInternal

void loadEndOfLogStatInternal()

setReadHook

public void setReadHook(TestHook hook)

setDelayVLSNRegisterHook

public void setDelayVLSNRegisterHook(TestHook<Object> hook)

setFlushLogHook

public void setFlushLogHook(TestHook<CountDownLatch> hook)


Copyright (c) 2004-2010 Oracle. All rights reserved.