use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class OWOWCache method flushPage.
private void flushPage(final int fileId, final long pageIndex, final ByteBuffer buffer) throws IOException, InterruptedException {
if (writeAheadLog != null) {
final OLogSequenceNumber lsn = ODurablePage.getLogSequenceNumberFromPage(buffer);
final OLogSequenceNumber flushedLSN = writeAheadLog.getFlushedLsn();
if (flushedLSN == null || flushedLSN.compareTo(lsn) < 0)
writeAheadLog.flush();
}
final byte[] content = new byte[pageSize];
buffer.position(0);
buffer.get(content);
OLongSerializer.INSTANCE.serializeNative(checksumMode == OChecksumMode.Off ? MAGIC_NUMBER_WITHOUT_CHECKSUM : MAGIC_NUMBER_WITH_CHECKSUM, content, MAGIC_NUMBER_OFFSET);
if (checksumMode != OChecksumMode.Off) {
final int crc32 = calculatePageCrc(content);
OIntegerSerializer.INSTANCE.serializeNative(crc32, content, CHECKSUM_OFFSET);
}
final long externalId = composeFileId(id, fileId);
final OClosableEntry<Long, OFileClassic> entry = files.acquire(externalId);
try {
final OFileClassic fileClassic = entry.get();
fileClassic.write(pageIndex * pageSize, content);
if (syncOnPageFlush)
fileClassic.synch();
} finally {
files.release(entry);
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class OWOWCache method loadFileContent.
private OCachePointer[] loadFileContent(final int intId, final long startPageIndex, final int pageCount, boolean verifyChecksums) throws IOException {
final long fileId = composeFileId(id, intId);
try {
final OClosableEntry<Long, OFileClassic> entry = files.acquire(fileId);
try {
final OFileClassic fileClassic = entry.get();
if (fileClassic == null)
throw new IllegalArgumentException("File with id " + intId + " not found in WOW Cache");
final long firstPageStartPosition = startPageIndex * pageSize;
final long firstPageEndPosition = firstPageStartPosition + pageSize;
if (fileClassic.getFileSize() >= firstPageEndPosition) {
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
}
int pagesRead = 0;
final OLogSequenceNumber lastLsn = writeAheadLog == null ? new OLogSequenceNumber(-1, -1) : writeAheadLog.getFlushedLsn();
try {
if (pageCount == 1) {
final ByteBuffer buffer = bufferPool.acquireDirect(false);
assert buffer.position() == 0;
fileClassic.read(firstPageStartPosition, buffer, false);
if (verifyChecksums && (checksumMode == OChecksumMode.StoreAndVerify || checksumMode == OChecksumMode.StoreAndThrow))
verifyChecksum(buffer, fileId, startPageIndex, null);
buffer.position(0);
final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
pagesRead = 1;
return new OCachePointer[] { dataPointer };
}
final long maxPageCount = (fileClassic.getFileSize() - firstPageStartPosition) / pageSize;
final int realPageCount = Math.min((int) maxPageCount, pageCount);
final ByteBuffer[] buffers = new ByteBuffer[realPageCount];
for (int i = 0; i < buffers.length; i++) {
buffers[i] = bufferPool.acquireDirect(false);
assert buffers[i].position() == 0;
}
fileClassic.read(firstPageStartPosition, buffers, false);
if (verifyChecksums && (checksumMode == OChecksumMode.StoreAndVerify || checksumMode == OChecksumMode.StoreAndThrow))
for (int i = 0; i < buffers.length; ++i) verifyChecksum(buffers[i], fileId, startPageIndex + i, buffers);
final OCachePointer[] dataPointers = new OCachePointer[buffers.length];
for (int n = 0; n < buffers.length; n++) {
buffers[n].position(0);
dataPointers[n] = new OCachePointer(buffers[n], bufferPool, lastLsn, fileId, startPageIndex + n);
}
pagesRead = dataPointers.length;
return dataPointers;
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(pagesRead);
}
}
} else
return null;
} finally {
files.release(entry);
}
} catch (InterruptedException e) {
throw OException.wrapException(new OStorageException("Data load was interrupted"), e);
}
}
Aggregations