use of org.neo4j.kernel.impl.transaction.log.LogPosition 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.LogPosition in project neo4j by neo4j.
the class PositionToRecoverFromTest method shouldReturnUnspecifiedIfThereIsNoNeedForRecovery.
@Test
public void shouldReturnUnspecifiedIfThereIsNoNeedForRecovery() throws Throwable {
// given
when(finder.find(logVersion)).thenReturn(new LatestCheckPoint(null, false, NO_TRANSACTION_ID, logVersion));
// when
LogPosition logPosition = new PositionToRecoverFrom(finder, monitor).apply(logVersion);
// then
verify(monitor).noCommitsAfterLastCheckPoint(null);
assertEquals(LogPosition.UNSPECIFIED, logPosition);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class PositionToRecoverFromTest method shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero.
@Test
public void shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero() throws Throwable {
// given
when(finder.find(logVersion)).thenReturn(new LatestCheckPoint(null, true, 10L, INITIAL_LOG_VERSION));
// when
LogPosition logPosition = new PositionToRecoverFrom(finder, monitor).apply(logVersion);
// then
verify(monitor).noCheckPointFound();
assertEquals(LogPosition.start(INITIAL_LOG_VERSION), logPosition);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class PositionToRecoverFromTest method shouldReturnLogPositionToRecoverFromIfNeeded.
@Test
public void shouldReturnLogPositionToRecoverFromIfNeeded() throws Throwable {
// given
LogPosition checkPointLogPosition = new LogPosition(1L, 4242);
when(finder.find(logVersion)).thenReturn(new LatestCheckPoint(new CheckPoint(checkPointLogPosition), true, 10L, logVersion));
// when
LogPosition logPosition = new PositionToRecoverFrom(finder, monitor).apply(logVersion);
// then
verify(monitor).commitsAfterLastCheckPoint(checkPointLogPosition, 10L);
assertEquals(checkPointLogPosition, logPosition);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class StoreMigratorTest method writeAndReadLastTxLogPosition.
@Test
public void writeAndReadLastTxLogPosition() throws IOException {
StoreMigrator migrator = newStoreMigrator();
LogPosition writtenLogPosition = new LogPosition(random.nextLong(), random.nextLong());
migrator.writeLastTxLogPosition(directory.graphDbDir(), writtenLogPosition);
LogPosition readLogPosition = migrator.readLastTxLogPosition(directory.graphDbDir());
assertEquals(writtenLogPosition, readLogPosition);
}
Aggregations