use of org.neo4j.kernel.impl.transaction.log.LogPositionMarker 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.LogPositionMarker 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.LogPositionMarker 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.LogPositionMarker in project neo4j by neo4j.
the class LatestCheckPointFinderTest method logFile.
private LogCreator logFile(Entry... entries) {
return (logVersion, positions) -> {
try {
AtomicLong lastTxId = new AtomicLong();
Supplier<Long> lastTxIdSupplier = () -> lastTxId.get();
LogVersionRepository logVersionRepository = new DeadSimpleLogVersionRepository(logVersion);
LifeSupport life = new LifeSupport();
life.start();
PhysicalLogFile logFile = life.add(new PhysicalLogFile(fsRule.get(), logFiles, mebiBytes(1), lastTxIdSupplier, logVersionRepository, NO_MONITOR, new LogHeaderCache(10)));
try {
FlushablePositionAwareChannel writeChannel = logFile.getWriter();
LogPositionMarker positionMarker = new LogPositionMarker();
LogEntryWriter writer = new LogEntryWriter(writeChannel);
for (Entry entry : entries) {
LogPosition currentPosition = writeChannel.getCurrentPosition(positionMarker).newPosition();
positions.put(entry, currentPosition);
if (entry instanceof StartEntry) {
writer.writeStartEntry(0, 0, 0, 0, new byte[0]);
} else if (entry instanceof CommitEntry) {
CommitEntry commitEntry = (CommitEntry) entry;
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;
writer.writeCheckPointEntry(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 {
life.shutdown();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
use of org.neo4j.kernel.impl.transaction.log.LogPositionMarker in project neo4j by neo4j.
the class LogPositionMarkerTest method shouldReturnUnspecifiedIfNothingHasBeenMarked.
@Test
void shouldReturnUnspecifiedIfNothingHasBeenMarked() {
// given
final LogPositionMarker marker = new LogPositionMarker();
// when
final LogPosition logPosition = marker.newPosition();
// given
assertEquals(LogPosition.UNSPECIFIED, logPosition);
}
Aggregations