private void flushPage(long fileId, long pageIndex, ODirectMemoryPointer dataPointer) throws IOException { if (writeAheadLog != null) { OLogSequenceNumber lsn = ODurablePage.getLogSequenceNumberFromPage(dataPointer); OLogSequenceNumber flushedLSN = writeAheadLog.getFlushedLSN(); if (flushedLSN == null || flushedLSN.compareTo(lsn) < 0) writeAheadLog.flush(); } final byte[] content = dataPointer.get(0, pageSize); OLongSerializer.INSTANCE.serializeNative(MAGIC_NUMBER, content, 0); final int crc32 = calculatePageCrc(content); OIntegerSerializer.INSTANCE.serializeNative(crc32, content, OLongSerializer.LONG_SIZE); final OFileClassic fileClassic = files.get(fileId); fileClassic.write(pageIndex * pageSize, content); if (syncOnPageFlush) fileClassic.synch(); }
public Set<ODirtyPage> logDirtyPagesTable() throws IOException { synchronized (syncObject) { if (writeAheadLog == null) return Collections.emptySet(); Set<ODirtyPage> logDirtyPages = new HashSet<ODirtyPage>(writeGroups.size() * 16); for (Map.Entry<GroupKey, WriteGroup> writeGroupEntry : writeGroups.entrySet()) { final GroupKey groupKey = writeGroupEntry.getKey(); final WriteGroup writeGroup = writeGroupEntry.getValue(); for (int i = 0; i < 16; i++) { final OCachePointer cachePointer = writeGroup.pages[i]; if (cachePointer != null) { final OLogSequenceNumber lastFlushedLSN = cachePointer.getLastFlushedLsn(); final String fileName = files.get(groupKey.fileId).getName(); final long pageIndex = (groupKey.groupIndex << 4) + i; final ODirtyPage logDirtyPage = new ODirtyPage(fileName, pageIndex, lastFlushedLSN); logDirtyPages.add(logDirtyPage); } } } writeAheadLog.logDirtyPages(logDirtyPages); return logDirtyPages; } }