use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter in project neo4j by neo4j.
the class RecoveryTest method shouldTellTransactionIdStoreAfterSuccessfullRecovery.
@Test
public void shouldTellTransactionIdStoreAfterSuccessfullRecovery() throws Exception {
// GIVEN
final PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), "log", fileSystemRule.get());
File file = logFiles.getLogFileForVersion(logVersion);
final LogPositionMarker marker = new LogPositionMarker();
final byte[] additionalHeaderData = new byte[0];
final int masterId = 0;
final int authorId = 1;
final long transactionId = 4;
final long commitTimestamp = 5;
writeSomeData(file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException>() {
@Override
public boolean visit(Pair<LogEntryWriter, Consumer<LogPositionMarker>> pair) throws IOException {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
// last committed tx
writer.writeStartEntry(masterId, authorId, 2L, 3L, additionalHeaderData);
writer.writeCommitEntry(transactionId, commitTimestamp);
consumer.accept(marker);
return true;
}
});
// WHEN
boolean recoveryRequired = recover(logFiles);
// THEN
assertTrue(recoveryRequired);
long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
assertEquals(transactionId, lastClosedTransaction[0]);
assertEquals(LogEntryStart.checksum(additionalHeaderData, masterId, authorId), transactionIdStore.getLastCommittedTransaction().checksum());
assertEquals(commitTimestamp, transactionIdStore.getLastCommittedTransaction().commitTimestamp());
assertEquals(logVersion, lastClosedTransaction[1]);
assertEquals(marker.getByteOffset(), lastClosedTransaction[2]);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter in project neo4j by neo4j.
the class RecoveryTest method shouldTruncateLogAfterSinglePartialTransaction.
@Test
public void shouldTruncateLogAfterSinglePartialTransaction() throws Exception {
// GIVEN
final PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), "log", fileSystemRule.get());
File file = logFiles.getLogFileForVersion(logVersion);
final LogPositionMarker marker = new LogPositionMarker();
writeSomeData(file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException>() {
@Override
public boolean visit(Pair<LogEntryWriter, Consumer<LogPositionMarker>> pair) throws IOException {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
// incomplete tx
// <-- marker has the last good position
consumer.accept(marker);
writer.writeStartEntry(0, 1, 5L, 4L, new byte[0]);
return true;
}
});
// WHEN
boolean recoveryRequired = recover(logFiles);
// THEN
assertTrue(recoveryRequired);
assertEquals(marker.getByteOffset(), file.length());
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter in project neo4j by neo4j.
the class RecoveryTest method writeSomeData.
private void writeSomeData(File file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor) throws IOException {
try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystemRule.get().open(file, "rw"), logVersion, CURRENT_LOG_VERSION);
final PositionAwarePhysicalFlushableChannel writableLogChannel = new PositionAwarePhysicalFlushableChannel(versionedStoreChannel)) {
writeLogHeader(writableLogChannel, logVersion, 2L);
Consumer<LogPositionMarker> consumer = marker -> {
try {
writableLogChannel.getCurrentPosition(marker);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
LogEntryWriter first = new LogEntryWriter(writableLogChannel);
visitor.visit(Pair.of(first, consumer));
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter in project neo4j by neo4j.
the class RecoveryTest method shouldTruncateLogAfterLastCompleteTransactionAfterSuccessfullRecovery.
@Test
public void shouldTruncateLogAfterLastCompleteTransactionAfterSuccessfullRecovery() throws Exception {
// GIVEN
final PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), "log", fileSystemRule.get());
File file = logFiles.getLogFileForVersion(logVersion);
final LogPositionMarker marker = new LogPositionMarker();
writeSomeData(file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException>() {
@Override
public boolean visit(Pair<LogEntryWriter, Consumer<LogPositionMarker>> pair) throws IOException {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
// last committed tx
writer.writeStartEntry(0, 1, 2L, 3L, new byte[0]);
writer.writeCommitEntry(4L, 5L);
// incomplete tx
// <-- marker has the last good position
consumer.accept(marker);
writer.writeStartEntry(0, 1, 5L, 4L, new byte[0]);
return true;
}
});
// WHEN
boolean recoveryRequired = recover(logFiles);
// THEN
assertTrue(recoveryRequired);
assertEquals(marker.getByteOffset(), file.length());
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter 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);
}
Aggregations