if (walRecord instanceof OAtomicUnitStartRecord) {
List<OLogSequenceNumber> operationList = new ArrayList<OLogSequenceNumber>();
operationUnits.put(((OAtomicUnitStartRecord) walRecord).getOperationUnitId(), operationList);
operationList.add(lsn);
} else if (walRecord instanceof OOperationUnitRecord) {
OOperationUnitRecord operationUnitRecord = (OOperationUnitRecord) walRecord;
OOperationUnitId unitId = operationUnitRecord.getOperationUnitId();
final List<OLogSequenceNumber> records = operationUnits.get(unitId);
assert records != null;
if (records == null) {
OLogManager.instance().warn(this,
"Record with lsn %s which indication of start of atomic operation was truncated will be skipped.",
walRecord.getLsn());
continue;
}
records.add(lsn);
if (operationUnitRecord instanceof OUpdatePageRecord) {
final OUpdatePageRecord updatePageRecord = (OUpdatePageRecord) operationUnitRecord;
final long fileId = updatePageRecord.getFileId();
final long pageIndex = updatePageRecord.getPageIndex();
if (!diskCache.isOpen(fileId))
diskCache.openFile(fileId);
final OCacheEntry cacheEntry = diskCache.load(fileId, pageIndex, true);
final OCachePointer cachePointer = cacheEntry.getCachePointer();
cachePointer.acquireExclusiveLock();
try {
ODurablePage durablePage = new ODurablePage(cacheEntry, ODurablePage.TrackMode.NONE);
durablePage.restoreChanges(updatePageRecord.getChanges());
durablePage.setLsn(lsn);
cacheEntry.markDirty();
} finally {
cachePointer.releaseExclusiveLock();
diskCache.release(cacheEntry);
}
} else if (operationUnitRecord instanceof OFileCreatedCreatedWALRecord) {
final OFileCreatedCreatedWALRecord fileCreatedCreatedRecord = (OFileCreatedCreatedWALRecord) operationUnitRecord;
diskCache.openFile(fileCreatedCreatedRecord.getFileName(), fileCreatedCreatedRecord.getFileId());
} else if (operationUnitRecord instanceof OAtomicUnitEndRecord) {
final OAtomicUnitEndRecord atomicUnitEndRecord = (OAtomicUnitEndRecord) walRecord;
if (atomicUnitEndRecord.isRollback())
undoOperation(records);
operationUnits.remove(unitId);
} else {
OLogManager.instance().error(this, "Invalid WAL record type was passed %s. Given record will be skipped.",
operationUnitRecord.getClass());
assert false : "Invalid WAL record type was passed " + operationUnitRecord.getClass().getName();
}
} else
OLogManager.instance().warn(this, "Record %s will be skipped during data restore.", walRecord);
recordsProcessed++;