com.sleepycat.je.log
Class LogEntryHeader

java.lang.Object
  extended by com.sleepycat.je.log.LogEntryHeader

public class LogEntryHeader
extends Object

A LogEntryHeader embodies the header information at the beginning of each log entry file.


Field Summary
static int CHECKSUM_BYTES
           
(package private) static int ENTRYTYPE_OFFSET
           
(package private) static int FLAGS_OFFSET
           
static int MAX_HEADER_SIZE
           
static int MIN_HEADER_SIZE
          Persistent fields.
static int VLSN_OFFSET
           
 
Constructor Summary
LogEntryHeader(ByteBuffer entryBuffer, int logVersion)
          For reading a log entry.
LogEntryHeader(byte entryType, int entryVersion, int itemSize, VLSN vlsn)
          For reading a replication message.
LogEntryHeader(LogEntry entry, Provisional provisional, ReplicationContext repContext)
          For writing a log header.
 
Method Summary
 ByteBuffer addPostMarshallingInfo(EnvironmentImpl envImpl, ByteBuffer entryBuffer, long lastOffset, ReplicationContext repContext)
          Add those parts of the header that must be calculated later to the entryBuffer, and also assign the fields in this class.
(package private)  void convertCommitToAbort(ByteBuffer entryBuffer)
          For use in special case where commits are transformed to aborts because of i/o errors during a logBuffer flush.
 void dumpLog(StringBuilder sb, boolean verbose)
           
(package private)  void dumpLogNoTag(StringBuilder sb, boolean verbose)
          Dump the header without enclosing
tags.
 void dumpRep(StringBuilder sb)
           
 long getChecksum()
           
(package private)  int getInvariantSizeMinusChecksum()
           
 int getItemSize()
           
 long getPrevOffset()
           
 Provisional getProvisional()
           
 boolean getReplicated()
           
 int getSize()
           
(package private)  int getSizeMinusChecksum()
           
 byte getType()
           
 int getVariablePortionSize()
           
 int getVersion()
           
 VLSN getVLSN()
           
 boolean isInvisible()
           
 boolean isVariableLength()
          May be called after reading MIN_HEADER_SIZE bytes to determine whether more bytes (getVariablePortionSize) should be read.
 boolean logicalEquals(LogEntryHeader other)
           
(package private) static byte makeInvisible(byte flags)
          Set the invisible bit in the given log entry flags.
 void readVariablePortion(ByteBuffer entryBuffer)
          Assumes this is called directly after the constructor, and that the entryBuffer is positioned right before the VLSN.
 void setFileHeaderVersion(int logVersion)
          Called to set the version for a file header entry after reading the version from the item data.
 String toString()
           
static void turnOffInvisible(ByteBuffer buffer, int logHeaderStartPosition)
          Turn off the invisible bit in the byte buffer which backs this log entry header.
 void writeToLog(ByteBuffer entryBuffer)
          Serialize this object into the buffer and leave the buffer positioned in the right place to write the following item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_HEADER_SIZE

public static final int MIN_HEADER_SIZE
Persistent fields. Layout on disk is (invariant) checksum - 4 bytes (invariant) entry type - 1 byte (invariant) entry flags - 1 byte (invariant) offset of previous log entry - 4 bytes (invariant) item size (not counting header size) - 4 bytes (optional) vlsn - 8 bytes Flags: The provisional bit can be set for any log type in the log. It's an indication to recovery that the entry shouldn't be processed when rebuilding the tree. See com.sleepycat.je.log.Provisional.java for the reasons why it's set. The replicated bit is set when this particular log entry is part of the replication stream and contains a VLSN in the header. The invisible bit is set when this log entry has been rolled back as part of replication syncup. The ensuing log entry has not been checksum-corrected, and to read it, the invisible bit must be cloaked.

See Also:
Constant Field Values

MAX_HEADER_SIZE

public static final int MAX_HEADER_SIZE
See Also:
Constant Field Values

CHECKSUM_BYTES

public static final int CHECKSUM_BYTES
See Also:
Constant Field Values

ENTRYTYPE_OFFSET

static final int ENTRYTYPE_OFFSET
See Also:
Constant Field Values

FLAGS_OFFSET

static final int FLAGS_OFFSET
See Also:
Constant Field Values

VLSN_OFFSET

public static final int VLSN_OFFSET
See Also:
Constant Field Values
Constructor Detail

LogEntryHeader

public LogEntryHeader(ByteBuffer entryBuffer,
                      int logVersion)
               throws ChecksumException
For reading a log entry.

Parameters:
entryBuffer - the buffer containing at least the first MIN_HEADER_SIZE bytes of the entry header.
logVersion - is the log version of the file that contains the given buffer, and is obtained from the file header. Note that for the file header entry itself, UNKNOWN_FILE_HEADER_VERSION may be passed.
Throws:
ChecksumException

LogEntryHeader

public LogEntryHeader(LogEntry entry,
                      Provisional provisional,
                      ReplicationContext repContext)
For writing a log header. public for unit tests.


LogEntryHeader

public LogEntryHeader(byte entryType,
                      int entryVersion,
                      int itemSize,
                      VLSN vlsn)
For reading a replication message. The node-specific parts of the header are not needed.

Method Detail

setFileHeaderVersion

public void setFileHeaderVersion(int logVersion)
Called to set the version for a file header entry after reading the version from the item data. See FileHeaderEntry.readEntry. [#16939]


getChecksum

public long getChecksum()

getType

public byte getType()

getVersion

public int getVersion()

getPrevOffset

public long getPrevOffset()

getItemSize

public int getItemSize()

getVLSN

public VLSN getVLSN()

getReplicated

public boolean getReplicated()

getProvisional

public Provisional getProvisional()

isInvisible

public boolean isInvisible()

getVariablePortionSize

public int getVariablePortionSize()

getSize

public int getSize()
Returns:
number of bytes used to store this header

getSizeMinusChecksum

int getSizeMinusChecksum()
Returns:
the number of bytes used to store the header, excepting the checksum field.

getInvariantSizeMinusChecksum

int getInvariantSizeMinusChecksum()
Returns:
the number of bytes used to store the header, excepting the checksum field.

readVariablePortion

public void readVariablePortion(ByteBuffer entryBuffer)
Assumes this is called directly after the constructor, and that the entryBuffer is positioned right before the VLSN.


writeToLog

public void writeToLog(ByteBuffer entryBuffer)
Serialize this object into the buffer and leave the buffer positioned in the right place to write the following item. The checksum, prevEntry, and vlsn values will filled in later on. public for unit tests.


addPostMarshallingInfo

public ByteBuffer addPostMarshallingInfo(EnvironmentImpl envImpl,
                                         ByteBuffer entryBuffer,
                                         long lastOffset,
                                         ReplicationContext repContext)
Add those parts of the header that must be calculated later to the entryBuffer, and also assign the fields in this class. That's - the prev offset, which must be done within the log write latch to be sure what that lsn is - the VLSN, for the same reason - the checksumVal, which must be added last, after all other fields are marshalled. (public for unit tests)


dumpLog

public void dumpLog(StringBuilder sb,
                    boolean verbose)
Parameters:
sb - destination string buffer
verbose - if true, dump the full, verbose version

dumpLogNoTag

void dumpLogNoTag(StringBuilder sb,
                  boolean verbose)
Dump the header without enclosing
tags. Used for DbPrintLog, to make the header attributes in the tag, for a more compact rendering.

Parameters:
sb - destination string buffer
verbose - if true, dump the full, verbose version

convertCommitToAbort

void convertCommitToAbort(ByteBuffer entryBuffer)
For use in special case where commits are transformed to aborts because of i/o errors during a logBuffer flush. See [11271]. Assumes that the entryBuffer is positioned at the start of the item. Return with the entryBuffer positioned to the end of the log entry.


toString

public String toString()
Overrides:
toString in class Object

dumpRep

public void dumpRep(StringBuilder sb)

logicalEquals

public boolean logicalEquals(LogEntryHeader other)
Returns:
true if these two log headers are logically the same. Used for replication.

isVariableLength

public boolean isVariableLength()
May be called after reading MIN_HEADER_SIZE bytes to determine whether more bytes (getVariablePortionSize) should be read.


makeInvisible

static byte makeInvisible(byte flags)
Set the invisible bit in the given log entry flags.


turnOffInvisible

public static void turnOffInvisible(ByteBuffer buffer,
                                    int logHeaderStartPosition)
Turn off the invisible bit in the byte buffer which backs this log entry header.

Parameters:
logHeaderStartPosition - the byte position of the start of the log entry header.


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