use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method shouldTruncateLogAfterSinglePartialTransaction.
@Test
void shouldTruncateLogAfterSinglePartialTransaction() throws Exception {
// GIVEN
Path file = logFiles.getLogFile().getLogFileForVersion(logVersion);
final LogPositionMarker marker = new LogPositionMarker();
writeSomeData(file, pair -> {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
// incomplete tx
// <-- marker has the last good position
consumer.accept(marker);
writer.writeStartEntry(5L, 4L, 0, new byte[0]);
return true;
});
// WHEN
boolean recoveryRequired = recover(storeDir, logFiles);
// THEN
assertTrue(recoveryRequired);
assertEquals(marker.getByteOffset(), Files.size(file));
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method shouldTellTransactionIdStoreAfterSuccessfulRecovery.
@Test
void shouldTellTransactionIdStoreAfterSuccessfulRecovery() throws Exception {
// GIVEN
Path file = logFiles.getLogFile().getLogFileForVersion(logVersion);
final LogPositionMarker marker = new LogPositionMarker();
final byte[] additionalHeaderData = new byte[0];
final long transactionId = 4;
final long commitTimestamp = 5;
writeSomeData(file, pair -> {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
// last committed tx
writer.writeStartEntry(2L, 3L, BASE_TX_CHECKSUM, additionalHeaderData);
writer.writeCommitEntry(transactionId, commitTimestamp);
consumer.accept(marker);
return true;
});
// WHEN
boolean recoveryRequired = recover(storeDir, logFiles);
// THEN
assertTrue(recoveryRequired);
long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
assertEquals(transactionId, lastClosedTransaction[0]);
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 AbstractLogTailScannerTest method logFile.
LogCreator logFile(Entry... entries) {
return (logVersion, positions) -> {
try {
AtomicLong lastTxId = new AtomicLong();
logVersionRepository.setCurrentLogVersion(logVersion, NULL);
logVersionRepository.setCheckpointLogVersion(logVersion, NULL);
LifeSupport logFileLife = new LifeSupport();
logFileLife.start();
logFileLife.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var checkpointFile = logFiles.getCheckpointFile();
int previousChecksum = BASE_TX_CHECKSUM;
try {
TransactionLogWriter logWriter = logFile.getTransactionLogWriter();
LogEntryWriter writer = logWriter.getWriter();
for (Entry entry : entries) {
LogPosition currentPosition = logWriter.getCurrentPosition();
positions.put(entry, currentPosition);
if (entry instanceof StartEntry) {
writer.writeStartEntry(0, 0, previousChecksum, new byte[0]);
} else if (entry instanceof CommitEntry) {
CommitEntry commitEntry = (CommitEntry) entry;
previousChecksum = writer.writeCommitEntry(commitEntry.txId, 0);
lastTxId.set(commitEntry.txId);
} else if (entry instanceof CheckPointEntry) {
CheckPointEntry checkPointEntry = (CheckPointEntry) entry;
Entry target = checkPointEntry.withPositionOfEntry;
LogPosition logPosition = target != null ? positions.get(target) : currentPosition;
assert logPosition != null : "No registered log position for " + target;
writeCheckpoint(writer, checkpointFile, logPosition);
} else if (entry instanceof PositionEntry) {
// Don't write anything, this entry is just for registering a position so that
// another CheckPointEntry can refer to it
} else {
throw new IllegalArgumentException("Unknown entry " + entry);
}
}
} finally {
logFileLife.shutdown();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
Aggregations