private OLogSequenceNumber readMasterRecord(final int index) throws IOException {
final long masterPosition = index * (OIntegerSerializer.INT_SIZE + 2L * OLongSerializer.LONG_SIZE);
if (masterRecordLSNHolder.size() < masterPosition + MASTER_RECORD_SIZE) {
OLogManager.instance().debugNoDb(this, "Cannot restore %d WAL master record for storage %s", null, index, storageName);
return null;
}
final CRC32 crc32 = new CRC32();
try {
final ByteBuffer buffer = ByteBuffer.allocate(MASTER_RECORD_SIZE);
OIOUtils.readByteBuffer(buffer, masterRecordLSNHolder, masterPosition, true);
buffer.rewind();
final int firstCRC = buffer.getInt();
final long segment = buffer.getLong();
final long position = buffer.getLong();
final byte[] serializedLSN = new byte[2 * OLongSerializer.LONG_SIZE];
OLongSerializer.INSTANCE.serializeLiteral(segment, serializedLSN, 0);
OLongSerializer.INSTANCE.serializeLiteral(position, serializedLSN, OLongSerializer.LONG_SIZE);
crc32.update(serializedLSN);
if (firstCRC != ((int) crc32.getValue())) {
OLogManager.instance()
.errorNoDb(this, "Cannot restore %d WAL master record for storage %s crc check is failed", null, index, storageName);
return null;
}
return new OLogSequenceNumber(segment, position);
} catch (final EOFException eofException) {
OLogManager.instance()
.debugNoDb(this, "Cannot restore %d WAL master record for storage %s", eofException, index, storageName);
return null;
}
}