use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LegacyLogsTest method readableChannel.
private Pair<LogHeader, IOCursor<LogEntry>> readableChannel(LogEntry[] entries) {
IOCursor<LogEntry> cursor = new ArrayIOCursor<>(entries);
LogHeader logHeader = new LogHeader((byte) 1, 1, 1);
return Pair.of(logHeader, cursor);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class PhysicalLogFileInformationTest method shouldReadAndCacheFirstCommittedTransactionIdForAGivenVersionWhenNotCached.
@Test
public void shouldReadAndCacheFirstCommittedTransactionIdForAGivenVersionWhenNotCached() throws Exception {
PhysicalLogFileInformation info = new PhysicalLogFileInformation(logFiles, logHeaderCache, transactionIdStore::getLastCommittedTransactionId, logVersionToTimestamp);
long expected = 5;
long version = 10L;
when(logHeaderCache.getLogHeader(version)).thenReturn(null);
when(logFiles.versionExists(version)).thenReturn(true);
when(logFiles.extractHeader(version)).thenReturn(new LogHeader((byte) -1, /*ignored*/
-1L, /*ignored*/
expected - 1L));
long firstCommittedTxId = info.getFirstEntryId(version);
assertEquals(expected, firstCommittedTxId);
verify(logHeaderCache, times(1)).putHeader(version, expected - 1);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method writeSomeDataWithVersion.
private void writeSomeDataWithVersion(Path file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor, KernelVersion version) throws IOException {
try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystem.write(file), logVersion, CURRENT_LOG_FORMAT_VERSION, file, EMPTY_ACCESSOR);
PositionAwarePhysicalFlushableChecksumChannel writableLogChannel = new PositionAwarePhysicalFlushableChecksumChannel(versionedStoreChannel, new HeapScopedBuffer(1, KibiByte, INSTANCE))) {
writeLogHeader(writableLogChannel, new LogHeader(logVersion, 2L, StoreId.UNKNOWN));
writableLogChannel.beginChecksum();
Consumer<LogPositionMarker> consumer = marker -> {
try {
writableLogChannel.getCurrentPosition(marker);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
LogEntryWriter first = new LogEntryWriter(writableLogChannel, version);
visitor.visit(Pair.of(first, consumer));
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogFile method accept.
@Override
public void accept(LogHeaderVisitor visitor) throws IOException {
// Start from the where we're currently at and go backwards in time (versions)
long logVersion = getHighestLogVersion();
long highTransactionId = context.getLastCommittedTransactionId();
while (versionExists(logVersion)) {
LogHeader logHeader = extractHeader(logVersion, false);
if (logHeader != null) {
long lowTransactionId = logHeader.getLastCommittedTxId() + 1;
LogPosition position = logHeader.getStartPosition();
if (!visitor.visit(logHeader, position, lowTransactionId, highTransactionId)) {
break;
}
highTransactionId = logHeader.getLastCommittedTxId();
}
logVersion--;
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogChannelAllocator method openLogChannel.
public PhysicalLogVersionedStoreChannel openLogChannel(long version, boolean raw) throws IOException {
Path fileToOpen = fileHelper.getLogFileForVersion(version);
if (!fileSystem.fileExists(fileToOpen)) {
throw new NoSuchFileException(fileToOpen.toAbsolutePath().toString());
}
StoreChannel rawChannel = null;
try {
rawChannel = fileSystem.read(fileToOpen);
try (var scopedBuffer = new HeapScopedBuffer(CURRENT_FORMAT_LOG_HEADER_SIZE, logFilesContext.getMemoryTracker())) {
var buffer = scopedBuffer.getBuffer();
LogHeader header = readLogHeader(buffer, rawChannel, true, fileToOpen);
if ((header == null) || (header.getLogVersion() != version)) {
throw new IllegalStateException(format("Unexpected log file header. Expected header version: %d, actual header: %s", version, header != null ? header.toString() : "null header."));
}
var versionedStoreChannel = new PhysicalLogVersionedStoreChannel(rawChannel, version, header.getLogFormatVersion(), fileToOpen, nativeChannelAccessor, raw);
if (!raw) {
nativeChannelAccessor.adviseSequentialAccessAndKeepInCache(rawChannel, version);
}
return versionedStoreChannel;
}
} catch (NoSuchFileException cause) {
throw (NoSuchFileException) new NoSuchFileException(fileToOpen.toAbsolutePath().toString()).initCause(cause);
} catch (Throwable unexpectedError) {
if (rawChannel != null) {
// If we managed to open the file before failing, then close the channel
try {
rawChannel.close();
} catch (IOException e) {
unexpectedError.addSuppressed(e);
}
}
throw unexpectedError;
}
}
Aggregations