int peekAmount = LogRecord.formatOverhead() + LogRecord.maxGroupStoredSize();
if (tranId != null)
peekAmount += LogRecord.maxTransactionIdStoredSize(tranId);
int readAmount; // the number of bytes actually read
LogRecord lr;
do
{
if (!open || !positionToNextRecord())
return null;
int checkLength;
// this log record is a candidate unless proven otherwise
lr = null;
candidate = true;
readAmount = -1;
currentInstant = scan.readLong();
byte[] data = input.getData();
if (data.length < nextRecordLength)
{
// make a new array of sufficient size and reset the arrary
// in the input stream
data = new byte[nextRecordLength];
input.setData(data);
}
if (logFactory.databaseEncrypted())
{
scan.readFully(data, 0, nextRecordLength);
int len = logFactory.decrypt(data, 0, nextRecordLength, data, 0);
if (SanityManager.DEBUG)
SanityManager.ASSERT(len == nextRecordLength);
input.setLimit(0, len);
}
else // no need to decrypt, only get the group and tid if we filter
{
if (groupmask == 0 && tranId == null)
{
// no filter, get the whole thing
scan.readFully(data, 0, nextRecordLength);
input.setLimit(0, nextRecordLength);
}
else
{
// Read only enough so that group and the tran id is in
// the data buffer. Group is stored as compressed int
// and tran id is stored as who knows what. read min
// of peekAmount or nextRecordLength
readAmount = (nextRecordLength > peekAmount) ?
peekAmount : nextRecordLength;
// in the data buffer, we now have enough to peek
scan.readFully(data, 0, readAmount);
input.setLimit(0, readAmount);
}
}
lr = (LogRecord) input.readObject();
if (groupmask != 0 || tranId != null)
{
if (groupmask != 0 && (groupmask & lr.group()) == 0)
candidate = false; // no match, throw this log record out
if (candidate && tranId != null)
{
TransactionId tid = lr.getTransactionId();
if (!tid.equals(tranId)) // nomatch
candidate = false; // throw this log record out
}
// if this log record is not filtered out, we need to read