use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteTheHeaderInTheFile.
@Test
public void shouldWriteTheHeaderInTheFile() throws IOException {
// given
final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs);
final File output = new File(getLegacyLogFilename(3));
final LogHeader header = new LogHeader(CURRENT_LOG_VERSION, 1, 42L);
// when
try (LogVersionedStoreChannel channel = writer.openWritableChannel(output)) {
writer.writeLogHeader(channel, header);
}
// then
assertEquals(header, readLogHeader(fs, output));
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInSeveralCommitsToTheFile.
@Test
public void shouldWriteAllTheEntryInSeveralCommitsToTheFile() throws IOException {
// given
final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
final LogEntryStart start1 = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command1 = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
final LogEntryCommit commit1 = new OnePhaseCommit(42L, 43L);
final LogEntryStart start2 = new LogEntryStart(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command2 = new LogEntryCommand(new Command.RelationshipCommand(relRecord, relRecord));
final LogEntryCommit commit2 = new OnePhaseCommit(84L, 85L);
// when
IOCursor<LogEntry> cursor = mockCursor(start1, command1, commit1, start2, command2, commit2);
writer.writeAllLogEntries(channel, cursor);
// then
verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected1 = new PhysicalTransactionRepresentation(Arrays.asList(command1.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected1));
verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
verify(logEntryWriter, times(1)).writeStartEntry(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected2 = new PhysicalTransactionRepresentation(Arrays.asList(command2.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected2));
verify(logEntryWriter, times(1)).writeCommitEntry(84L, 85L);
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class ReaderLogVersionBridgeTest method shouldReturnOldChannelWhenNextChannelHasntGottenCompleteHeaderYet.
@Test
public void shouldReturnOldChannelWhenNextChannelHasntGottenCompleteHeaderYet() throws Exception {
// given
final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(fs, logFiles);
final StoreChannel nextVersionWithIncompleteHeader = mock(StoreChannel.class);
when(nextVersionWithIncompleteHeader.read(any(ByteBuffer.class))).thenReturn(LOG_HEADER_SIZE / 2);
when(channel.getVersion()).thenReturn(version);
when(fs.fileExists(file)).thenReturn(true);
when(logFiles.getLogFileForVersion(version + 1)).thenReturn(file);
when(fs.open(file, "r")).thenReturn(nextVersionWithIncompleteHeader);
// when
final LogVersionedStoreChannel result = bridge.next(channel);
// then
assertEquals(channel, result);
verify(channel, never()).close();
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class ReaderLogVersionBridgeTest method shouldOpenTheNextChannelWhenItExists.
@Test
void shouldOpenTheNextChannelWhenItExists() throws IOException {
// given
final StoreChannel newStoreChannel = mock(StoreChannel.class);
final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(logFiles.getLogFile());
when(channel.getVersion()).thenReturn(version);
when(channel.getLogFormatVersion()).thenReturn(CURRENT_LOG_FORMAT_VERSION);
when(fs.fileExists(any(Path.class))).thenReturn(true);
when(fs.read(any(Path.class))).thenReturn(newStoreChannel);
when(newStoreChannel.read(ArgumentMatchers.<ByteBuffer>any())).then(new Answer<>() {
private int count;
@Override
public Integer answer(InvocationOnMock invocation) {
count++;
ByteBuffer buffer = invocation.getArgument(0);
if (count == 1) {
buffer.putLong(encodeLogVersion(version + 1, CURRENT_LOG_FORMAT_VERSION));
return Long.BYTES;
}
if (count == 2) {
buffer.putLong(42);
buffer.putLong(1);
buffer.putLong(2);
buffer.putLong(3);
buffer.putLong(4);
buffer.putLong(5);
// reserved
buffer.putLong(0);
return Long.BYTES * 7;
}
throw new AssertionError("Should only be called twice.");
}
});
// when
final LogVersionedStoreChannel result = bridge.next(channel, false);
// then
PhysicalLogVersionedStoreChannel expected = new PhysicalLogVersionedStoreChannel(newStoreChannel, version + 1, CURRENT_LOG_FORMAT_VERSION, Path.of("log.file"), ChannelNativeAccessor.EMPTY_ACCESSOR);
assertEquals(expected, result);
verify(channel).close();
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel 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));
}
}
Aggregations