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, VLSNReader

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.


Nested Class Summary
static class FileReader.EOFException
          Never seen by user, used to indicate that the file reader should stop.
protected static class FileReader.ReadWindow
          A ReadWindow provides a swathe of data read from the JE log.
 
Field Summary
protected  ChecksumValidator cksumValidator
           
protected  LogEntryHeader currentEntryHeader
           
protected  long currentEntryOffset
           
protected  long currentEntryPrevOffset
           
protected  EnvironmentImpl envImpl
           
protected  boolean eof
           
protected  FileManager fileManager
           
protected  boolean forward
           
protected  Logger logger
           
protected  long nextEntryOffset
           
protected  long startLsn
           
protected  FileReader.ReadWindow window
           
 
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
 boolean entryIsReplicated()
           
 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()
           
protected  FileReader.ReadWindow makeWindow(int readBufferSize)
          May be overridden by other FileReaders.
protected abstract  boolean processEntry(ByteBuffer entryBuffer)
          Each file reader implements this method to process the entry data.
 boolean readNextEntry()
          Scans the log files until either it has reached the end of the log or has hit an invalid portion.
 boolean readNextEntryAllowExceptions()
          Variant of readNextEntry that throws FileNotFoundException and ChecksumException, rather than wrapping them in an EnvironmentFailureException and invalidating the enviornment.
protected  boolean resyncReader(long nextGoodRecordPostCorruption, boolean dumpCorruptedBounds)
           
 void setAlwaysValidateChecksum(boolean validate)
          Whether to always validate the checksum, even for non-target entries.
protected  void setBackwardPosition()
          Ensure that the next target is in the window.
protected  void setForwardPosition()
          Ensure that the next target is in the window.
 void skipData(int amountToSkip)
           
protected  void skipEntry(ByteBuffer entryBuffer)
          May be called by processEntry when it determines that the entry does not need to be read/de-serialized.
(package private) static Buffer threadSafeBufferFlip(ByteBuffer buffer)
          Note that we catch Exception here because it is possible that another thread is modifying the state of buffer simultaneously.
(package private) static int threadSafeBufferPosition(ByteBuffer buffer)
           
(package private) static 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 final EnvironmentImpl envImpl

fileManager

protected final FileManager fileManager

window

protected final FileReader.ReadWindow window

eof

protected boolean eof

forward

protected final boolean forward

currentEntryHeader

protected LogEntryHeader currentEntryHeader

currentEntryPrevOffset

protected long currentEntryPrevOffset

currentEntryOffset

protected long currentEntryOffset

nextEntryOffset

protected long nextEntryOffset

startLsn

protected long startLsn

cksumValidator

protected ChecksumValidator cksumValidator

logger

protected final Logger logger
Constructor Detail

FileReader

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

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

makeWindow

protected FileReader.ReadWindow makeWindow(int readBufferSize)
                                    throws DatabaseException
May be overridden by other FileReaders.

Throws:
DatabaseException

initStartingPosition

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


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.


readNextEntry

public boolean readNextEntry()
Scans the log files until either it has reached the end of the log or has hit an invalid portion.

Returns:
true if an element has been read, false at end-of-log.
Throws:
EnvironmentFailureException - if a ChecksumException, FileNotFoundException, or another internal problem occurs.

readNextEntryAllowExceptions

public final boolean readNextEntryAllowExceptions()
                                           throws FileNotFoundException,
                                                  ChecksumException
Variant of readNextEntry that throws FileNotFoundException and ChecksumException, rather than wrapping them in an EnvironmentFailureException and invalidating the enviornment. This allows users of this class (see cleaner.FileProcessor), and subclasses that override readNextEntry (see ScavengerFileReader and LastFileReader), to handle these exceptions specially.

Throws:
FileNotFoundException
ChecksumException

skipEntry

protected void skipEntry(ByteBuffer entryBuffer)
May be called by processEntry when it determines that the entry does not need to be read/de-serialized.


resyncReader

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

setForwardPosition

protected void setForwardPosition()
                           throws FileReader.EOFException,
                                  DatabaseException,
                                  ChecksumException,
                                  FileNotFoundException
Ensure that the next target is in the window. The default behavior is that the next target is the next, following entry, so we can assume that it's in the window. All we have to do is to check if we've gone past the specified end point.

Throws:
DatabaseException
FileNotFoundException
ChecksumException
FileReader.EOFException

setBackwardPosition

protected void setBackwardPosition()
                            throws ChecksumException,
                                   FileNotFoundException,
                                   FileReader.EOFException,
                                   DatabaseException
Ensure that the next target is in the window. The default behavior is that the next target is the next previous entry.

Throws:
DatabaseException
ChecksumException
FileNotFoundException
FileReader.EOFException

skipData

public void skipData(int amountToSkip)
              throws ChecksumException,
                     FileReader.EOFException,
                     FileNotFoundException,
                     DatabaseException
Throws:
ChecksumException
FileReader.EOFException
FileNotFoundException
DatabaseException

getAndResetNReads

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


isTargetEntry

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

processEntry

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

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

entryIsReplicated

public boolean entryIsReplicated()
Returns:
true if the current entry is part of replication stream.

threadSafeBufferFlip

static Buffer threadSafeBufferFlip(ByteBuffer buffer)
Note that we catch Exception here because it is possible that another thread is modifying the state of buffer simultaneously. Specifically, this can happen if another thread is writing this log buffer out and it does (e.g.) a flip operation on it. The actual mark/pos of the buffer may be caught in an unpredictable state. We could add another latch to protect this buffer, but that's heavier weight than we need. So the easiest thing to do is to just retry the duplicate operation. See [#9822].


threadSafeBufferPosition

static int threadSafeBufferPosition(ByteBuffer buffer)

threadSafeBufferPosition

static Buffer threadSafeBufferPosition(ByteBuffer buffer,
                                       int newPosition)


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