com.sleepycat.je.log
Class FileReader

java.lang.Object
  extended by com.sleepycat.je.log.FileReader
Direct Known Subclasses:
CheckpointFileReader, CleanerFileReader, DumpFileReader, INFileReader, LastFileReader, LNFileReader, ScavengerFileReader, SearchFileReader, UtilizationFileReader

public abstract class FileReader
extends Object

A FileReader is an abstract class that traverses the log files, reading in chunks of the file at a time. Concrete subclasses perform a particular action to each entry.


Field Summary
protected  boolean anticipateChecksumErrors
           
protected  ChecksumValidator cksumValidator
           
protected  LogEntryHeader currentEntryHeader
           
protected  long currentEntryOffset
           
protected  long currentEntryPrevOffset
           
protected  EnvironmentImpl envImpl
           
protected  boolean eof
           
protected  FileManager fileManager
           
protected  long nextEntryOffset
           
protected  long readBufferFileEnd
           
protected  long readBufferFileNum
           
protected  long readBufferFileStart
           
protected  long startLsn
           
 
Constructor Summary
FileReader(EnvironmentImpl envImpl, int readBufferSize, boolean forward, long startLsn, Long singleFileNumber, long endOfFileLsn, long finishLsn)
          A FileReader just needs to know what size chunks to read in.
 
Method Summary
 int getAndResetNReads()
          Returns the number of reads since the last time this method was called.
 int getLastEntrySize()
          Returns the total size (including header) of the last entry read.
 long getLastLsn()
          Get LSN of the last entry read.
 long getNRepeatIteratorReads()
           
 int getNumRead()
           
protected  void initStartingPosition(long endOfFileLsn, Long ignoreSingleFileNumber)
          Helper for determining the starting position and opening up a file at the desired location.
protected  boolean isTargetEntry(byte logEntryTypeNumber, byte logEntryTypeVersion)
           
protected abstract  boolean processEntry(ByteBuffer entryBuffer)
          Each file reader implements this method to process the entry data.
(package private)  void readEntry(LogEntry entry, ByteBuffer buffer, boolean readFullItem)
          A bottleneck for all calls to LogEntry.readEntry.
 boolean readNextEntry()
          readNextEntry scans the log files until either it's reached the end of the log or has hit an invalid portion.
protected  boolean resyncReader(long nextGoodRecordPostCorruption, boolean dumpCorruptedBounds)
           
 void setAlwaysValidateChecksum(boolean validate)
          Whether to always validate the checksum, even for non-target entries.
(package private)  Buffer threadSafeBufferPosition(ByteBuffer buffer, int newPosition)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

envImpl

protected EnvironmentImpl envImpl

fileManager

protected FileManager fileManager

eof

protected boolean eof

readBufferFileNum

protected long readBufferFileNum

readBufferFileStart

protected long readBufferFileStart

readBufferFileEnd

protected long readBufferFileEnd

currentEntryHeader

protected LogEntryHeader currentEntryHeader

currentEntryPrevOffset

protected long currentEntryPrevOffset

currentEntryOffset

protected long currentEntryOffset

nextEntryOffset

protected long nextEntryOffset

startLsn

protected long startLsn

cksumValidator

protected ChecksumValidator cksumValidator

anticipateChecksumErrors

protected boolean anticipateChecksumErrors
Constructor Detail

FileReader

public FileReader(EnvironmentImpl envImpl,
                  int readBufferSize,
                  boolean forward,
                  long startLsn,
                  Long singleFileNumber,
                  long endOfFileLsn,
                  long finishLsn)
           throws IOException,
                  DatabaseException
A FileReader just needs to know what size chunks to read in.

Parameters:
endOfFileLsn - indicates the end of the log file
Throws:
IOException
DatabaseException
Method Detail

initStartingPosition

protected void initStartingPosition(long endOfFileLsn,
                                    Long ignoreSingleFileNumber)
                             throws IOException,
                                    DatabaseException
Helper for determining the starting position and opening up a file at the desired location.

Throws:
IOException
DatabaseException

setAlwaysValidateChecksum

public void setAlwaysValidateChecksum(boolean validate)
Whether to always validate the checksum, even for non-target entries.


getNumRead

public int getNumRead()
Returns:
the number of entries processed by this reader.

getNRepeatIteratorReads

public long getNRepeatIteratorReads()

getLastLsn

public long getLastLsn()
Get LSN of the last entry read.


getLastEntrySize

public int getLastEntrySize()
Returns the total size (including header) of the last entry read.


readEntry

void readEntry(LogEntry entry,
               ByteBuffer buffer,
               boolean readFullItem)
         throws DatabaseException
A bottleneck for all calls to LogEntry.readEntry. This method ensures that setLastLogSize is called after LogEntry.readEntry, and should be called by all FileReaders instead of calling LogEntry.readEntry directly.

Throws:
DatabaseException

readNextEntry

public boolean readNextEntry()
                      throws DatabaseException,
                             IOException
readNextEntry scans the log files until either it's reached the end of the log or has hit an invalid portion. It then returns false.

Returns:
true if an element has been read
Throws:
DatabaseException
IOException

resyncReader

protected boolean resyncReader(long nextGoodRecordPostCorruption,
                               boolean dumpCorruptedBounds)
                        throws DatabaseException,
                               IOException
Throws:
DatabaseException
IOException

getAndResetNReads

public int getAndResetNReads()
Returns the number of reads since the last time this method was called.


isTargetEntry

protected boolean isTargetEntry(byte logEntryTypeNumber,
                                byte logEntryTypeVersion)
                         throws DatabaseException
Returns:
true if this reader should process this entry, or just skip over it.
Throws:
DatabaseException

processEntry

protected abstract boolean processEntry(ByteBuffer entryBuffer)
                                 throws DatabaseException
Each file reader implements this method to process the entry data.

Parameters:
enteryBuffer - contains the entry data and is positioned at the data
Returns:
true if this entry should be returned
Throws:
DatabaseException

threadSafeBufferPosition

Buffer threadSafeBufferPosition(ByteBuffer buffer,
                                int newPosition)


Copyright 2004,2008 Oracle. All rights reserved.