}
if (!checkPageIntegrity(pageContent))
throw new OWALPageBrokenException("WAL page with index " + pageIndex + " is broken.");
ODirectMemoryPointer pointer = new ODirectMemoryPointer(pageContent);
try {
OWALPage page = new OWALPage(pointer, false);
byte[] content = page.getRecord(pageOffset);
if (record == null)
record = content;
else {
byte[] oldRecord = record;
record = new byte[record.length + content.length];
System.arraycopy(oldRecord, 0, record, 0, oldRecord.length);
System.arraycopy(content, 0, record, oldRecord.length, record.length - oldRecord.length);
}
if (page.mergeWithNextPage(pageOffset)) {
pageOffset = OWALPage.RECORDS_OFFSET;
pageIndex++;
if (pageIndex >= pageCount)
throw new OWALPageBrokenException("WAL page with index " + pageIndex + " is broken.");
} else {
if (page.getFreeSpace() >= OWALPage.MIN_RECORD_SIZE && pageIndex < pageCount - 1)
throw new OWALPageBrokenException("WAL page with index " + pageIndex + " is broken.");
break;
}
} finally {
pointer.free();
}
}
lastReadRecord = new WeakReference<OPair<OLogSequenceNumber, byte[]>>(new OPair<OLogSequenceNumber, byte[]>(lsn, record));
return record;