Class BlockLogBuffer
- java.lang.Object
-
- org.objectweb.howl.log.LogObject
-
- org.objectweb.howl.log.LogBuffer
-
- org.objectweb.howl.log.BlockLogBuffer
-
- Direct Known Subclasses:
BlockLogBufferSink
class BlockLogBuffer extends LogBuffer
An implementation of LogBuffer that provides features necessary for a reliable Transaction Monitor journal.Each block contains a header, zero or more log records, and a footer. The header and footer contain enough information to allow recovery operations to validate the integrity of each log block.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
bufferFooterSize
The number of bytes to reserve for block footer information.private int
bytesUsedOffset
Offset within the block header of the bytes_used field.private byte[]
crlf
private byte[]
CRLF
Carriage Return Line Feed sequence used for debugging purposes.(package private) boolean
doWrite
switch to disable writes.private static int
EOB
end-of-block string stuffed into buffers to help identify end of used portion of buffer in a hex dump.private byte[]
FOOTER_ID
Signature for each logical block footer.private byte[]
footerId
private byte[]
HEADER_ID
Signature for each logical block header.private byte[]
headerId
(package private) int
initCounter
number of times this buffer was used.private int
maxRecordSize
maximum size of user data record.private int
recordHeaderSize
Size of the header for each data record in the block.(package private) long
todPut
currentTimeMillis that last record was added.-
Fields inherited from class org.objectweb.howl.log.LogBuffer
bsn, buffer, bytesUsed, checksum, checksumBuffer, doChecksum, forceNow, index, ioexception, iostatus, lf, name, rewind, tod, waitingThreads, waitingThreadsLock
-
-
Constructor Summary
Constructors Constructor Description BlockLogBuffer(Configuration config)
default constructor calls super class constructor.BlockLogBuffer(Configuration config, boolean doWrite)
constructs instance of BlockLogBuffer with file IO disabled.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
bufferInfo()
generate a String that represents the state of this LogBuffer objectprivate boolean
compareBytes(byte[] val, byte[] expected)
internal routine used to compare two byte[] objects.(package private) java.lang.String
getStats()
return statistics for this buffer.(package private) LogBuffer
init(int bsn, LogFileManager lfm)
initialize members for buffer reuse.(package private) long
put(short type, byte[][] data, boolean sync)
puts a data record into the buffer and returns a token for record.(package private) LogBuffer
read(LogFile lf, long position)
Reads a block from LogFile lf and validates header and footer information.(package private) boolean
shouldForce()
determines if buffer should be forced to disk.(package private) void
write()
write ByteBuffer to the log file.
-
-
-
Field Detail
-
todPut
long todPut
currentTimeMillis that last record was added.This field is used by shouldForce() to determine if the buffer should be forced.
-
initCounter
int initCounter
number of times this buffer was used.In general, should be about the same for all buffers in a pool.
-
bytesUsedOffset
private int bytesUsedOffset
Offset within the block header of the bytes_used field.
-
bufferFooterSize
private static final int bufferFooterSize
The number of bytes to reserve for block footer information.- See Also:
- Constant Field Values
-
recordHeaderSize
private int recordHeaderSize
Size of the header for each data record in the block.Record header format: short record type [2] see LogRecordType short record length of user data [2]
-
CRLF
private byte[] CRLF
Carriage Return Line Feed sequence used for debugging purposes.
-
crlf
private byte[] crlf
-
HEADER_ID
private byte[] HEADER_ID
Signature for each logical block header.
-
headerId
private byte[] headerId
-
FOOTER_ID
private byte[] FOOTER_ID
Signature for each logical block footer.
-
footerId
private byte[] footerId
-
doWrite
boolean doWrite
switch to disable writes.Used to measure performance of implementation sans physical writes. Subclass defines doWrite to be false to eliminate IO.
-
maxRecordSize
private int maxRecordSize
maximum size of user data record.Although this member is local to a LogBuffer instance, it is assumed to have the same value in all instances.
-
EOB
private static final int EOB
end-of-block string stuffed into buffers to help identify end of used portion of buffer in a hex dump.This string is only stored if there is room, and it is not accounted for in the length field of the buffer header.
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BlockLogBuffer
BlockLogBuffer(Configuration config)
default constructor calls super class constructor.
-
BlockLogBuffer
BlockLogBuffer(Configuration config, boolean doWrite)
constructs instance of BlockLogBuffer with file IO disabled.use this constructor when doing performance measurements on the implementation sans file IO.
- Parameters:
doWrite
- false to disable IO for performance measurements.When set to false, the write() method does not issue writes to the file. This reduces the elapse time of a force() to zero and allows performance of the log logic (sans IO) to be measured.
-
-
Method Detail
-
put
long put(short type, byte[][] data, boolean sync) throws LogRecordSizeException
puts a data record into the buffer and returns a token for record.Each record consists of zero or more byte[] fields. Each field is preceded by a short (2 bytes) containing the length of the field to allow for subsequent unpacking.
- Specified by:
put
in classLogBuffer
- Parameters:
type
- short containing implementation defined record type information. The type is stored as the first field of the log record.data
- byte[][] to be written to log.sync
- true if thread will call sync following the put. Causes count of waitingThreads to be incremented.- Returns:
- a long that contains the physical position of the record is returned. The value returned by put() is an encoding of the physical position. The format of the returned value is implementation specific, and should be treated as opaque by the caller. Returns 0 if there is no room for the record in the current buffer.
- Throws:
LogRecordSizeException
- if the sum of all data[] array sizes is larger than the maximum allowed record size for the configured buffer size.- See Also:
LogBuffer.put(short, byte[][], boolean)
-
write
void write() throws java.io.IOException
write ByteBuffer to the log file.- Specified by:
write
in classLogBuffer
- Throws:
java.io.IOException
- rethrows any IOExceptions thrown by FileChannel methods.QUESTION: should waiters be interupted if IO Error occurs?
- See Also:
LogBuffer.init(int, LogFileManager)
,LogFile.write(LogBuffer)
-
init
LogBuffer init(int bsn, LogFileManager lfm) throws LogFileOverflowException
initialize members for buffer reuse.- Specified by:
init
in classLogBuffer
- Parameters:
bsn
- Logic Block Sequence Number of the buffer. LogBufferManager maintains a list of block sequence numbers to ensure correct order of writes to disk. Some implementations of LogBuffer may include the BSN as part of a record or block header.lfm
- LogFileMaager to call to obtain a LogFile.- Returns:
- this LogBuffer
- Throws:
LogFileOverflowException
-
compareBytes
private boolean compareBytes(byte[] val, byte[] expected)
internal routine used to compare two byte[] objects.- Parameters:
val
- byte[] containing data to be validatedexpected
- byte[] containing expected sequence of data- Returns:
- true if the two byte[] objects are equal, otherwise false.
-
read
LogBuffer read(LogFile lf, long position) throws java.io.IOException, InvalidLogBufferException, java.nio.InvalidMarkException
Reads a block from LogFile lf and validates header and footer information.- Specified by:
read
in classLogBuffer
- Parameters:
lf
- LogFile to read.position
- within the LogFile to be read.- Returns:
- this LogBuffer reference.
- Throws:
java.io.IOException
- if anything goes wrong during the file read.InvalidLogBufferException
- if any of the block header or footer fields are invalid.java.nio.InvalidMarkException
- See Also:
LogBuffer.read(LogFile, long)
-
shouldForce
boolean shouldForce()
determines if buffer should be forced to disk.If there are any waiting threads, then buffer is forced when it is 50 ms old. Otherwise, if there are no waiting threads, we wait 1/4 second before we force.
- Specified by:
shouldForce
in classLogBuffer
- Returns:
- true if buffer should be forced now.
-
getStats
java.lang.String getStats()
return statistics for this buffer.
-
bufferInfo
public java.lang.String bufferInfo()
generate a String that represents the state of this LogBuffer object
-
-