use of com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage in project orientdb by orientechnologies.
the class LocalPaginatedClusterWithWALTest method restoreClusterFromWAL.
private void restoreClusterFromWAL() throws IOException {
ODiskWriteAheadLog log = new ODiskWriteAheadLog(4, -1, 10 * 1024L * OWALPage.PAGE_SIZE, null, true, storage, 10);
OLogSequenceNumber lsn = log.begin();
List<OWALRecord> atomicUnit = new ArrayList<OWALRecord>();
boolean atomicChangeIsProcessed = false;
while (lsn != null) {
OWALRecord walRecord = log.read(lsn);
if (walRecord instanceof OOperationUnitRecord)
atomicUnit.add(walRecord);
if (!atomicChangeIsProcessed) {
if (walRecord instanceof OAtomicUnitStartRecord)
atomicChangeIsProcessed = true;
} else if (walRecord instanceof OAtomicUnitEndRecord) {
atomicChangeIsProcessed = false;
for (OWALRecord restoreRecord : atomicUnit) {
if (restoreRecord instanceof OAtomicUnitStartRecord || restoreRecord instanceof OAtomicUnitEndRecord || restoreRecord instanceof ONonTxOperationPerformedWALRecord)
continue;
if (restoreRecord instanceof OFileCreatedWALRecord) {
final OFileCreatedWALRecord fileCreatedCreatedRecord = (OFileCreatedWALRecord) restoreRecord;
final String fileName = fileCreatedCreatedRecord.getFileName().replace("actualPaginatedClusterWithWALTest", "expectedPaginatedClusterWithWALTest");
if (!expectedWriteCache.exists(fileName))
expectedReadCache.addFile(fileName, fileCreatedCreatedRecord.getFileId(), expectedWriteCache);
} else {
final OUpdatePageRecord updatePageRecord = (OUpdatePageRecord) restoreRecord;
final long fileId = updatePageRecord.getFileId();
final long pageIndex = updatePageRecord.getPageIndex();
OCacheEntry cacheEntry = expectedReadCache.load(fileId, pageIndex, true, expectedWriteCache, 1);
if (cacheEntry == null) {
do {
if (cacheEntry != null)
readCache.release(cacheEntry, expectedWriteCache);
cacheEntry = expectedReadCache.allocateNewPage(fileId, expectedWriteCache);
} while (cacheEntry.getPageIndex() != pageIndex);
}
cacheEntry.acquireExclusiveLock();
try {
ODurablePage durablePage = new ODurablePage(cacheEntry, null);
durablePage.restoreChanges(updatePageRecord.getChanges());
durablePage.setLsn(updatePageRecord.getLsn());
cacheEntry.markDirty();
} finally {
cacheEntry.releaseExclusiveLock();
expectedReadCache.release(cacheEntry, expectedWriteCache);
}
}
}
atomicUnit.clear();
} else {
Assert.assertTrue(walRecord instanceof OUpdatePageRecord || walRecord instanceof OFileCreatedWALRecord || walRecord instanceof ONonTxOperationPerformedWALRecord);
}
lsn = log.next(lsn);
}
Assert.assertTrue(atomicUnit.isEmpty());
log.close();
}
Aggregations