Class BlockLogBuffer
- Direct Known Subclasses:
BlockLogBufferSink
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
FieldsModifier and TypeFieldDescriptionprivate static final int
The number of bytes to reserve for block footer information.private int
Offset within the block header of the bytes_used field.private byte[]
private byte[]
Carriage Return Line Feed sequence used for debugging purposes.(package private) boolean
switch to disable writes.private static final int
end-of-block string stuffed into buffers to help identify end of used portion of buffer in a hex dump.private byte[]
Signature for each logical block footer.private byte[]
private byte[]
Signature for each logical block header.private byte[]
(package private) int
number of times this buffer was used.private int
maximum size of user data record.private int
Size of the header for each data record in the block.(package private) long
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
ConstructorsConstructorDescriptionBlockLogBuffer
(Configuration config) default constructor calls super class constructor.BlockLogBuffer
(Configuration config, boolean doWrite) constructs instance of BlockLogBuffer with file IO disabled. -
Method Summary
Modifier and TypeMethodDescriptiongenerate 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) 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
Reads a block from LogFile lf and validates header and footer information.(package private) boolean
determines if buffer should be forced to disk.(package private) void
write()
write ByteBuffer to the log file.
-
Field Details
-
todPut
long todPutcurrentTimeMillis that last record was added.This field is used by shouldForce() to determine if the buffer should be forced.
-
initCounter
int initCounternumber of times this buffer was used.In general, should be about the same for all buffers in a pool.
-
bytesUsedOffset
private int bytesUsedOffsetOffset within the block header of the bytes_used field. -
recordHeaderSize
private int recordHeaderSizeSize 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[] CRLFCarriage Return Line Feed sequence used for debugging purposes. -
crlf
private byte[] crlf -
HEADER_ID
private byte[] HEADER_IDSignature for each logical block header. -
headerId
private byte[] headerId -
FOOTER_ID
private byte[] FOOTER_IDSignature for each logical block footer. -
doWrite
boolean doWriteswitch to disable writes.Used to measure performance of implementation sans physical writes. Subclass defines doWrite to be false to eliminate IO.
-
maxRecordSize
private int maxRecordSizemaximum 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 EOBend-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:
-
-
Constructor Details
-
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 Details
-
put
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:
-
write
write ByteBuffer to the log file.- Specified by:
write
in classLogBuffer
- Throws:
IOException
- rethrows any IOExceptions thrown by FileChannel methods.QUESTION: should waiters be interupted if IO Error occurs?
- See Also:
-
init
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 IOException, InvalidLogBufferException, 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:
IOException
- if anything goes wrong during the file read.InvalidLogBufferException
- if any of the block header or footer fields are invalid.InvalidMarkException
- See Also:
-
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
String getStats()return statistics for this buffer. -
bufferInfo
generate a String that represents the state of this LogBuffer object
-