Search in sources :

Example 31 with LogPosition

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);
        }
    };
}
Also used : ByteUnit.mebiBytes(org.neo4j.io.ByteUnit.mebiBytes) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Supplier(java.util.function.Supplier) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) NO_MONITOR(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.NO_MONITOR) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) Map(java.util.Map) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Parameterized(org.junit.runners.Parameterized) NO_TRANSACTION_ID(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint.NO_TRANSACTION_ID) Before(org.junit.Before) Collection(java.util.Collection) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) Test(org.junit.Test) IOException(java.io.IOException) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) UncheckedIOException(java.io.UncheckedIOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) FlushablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChannel) Assert.assertEquals(org.junit.Assert.assertEquals) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) AtomicLong(java.util.concurrent.atomic.AtomicLong) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Supplier(java.util.function.Supplier) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) FlushablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 32 with LogPosition

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);
}
Also used : LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 33 with 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);
}
Also used : LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 34 with 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);
}
Also used : LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) Test(org.junit.Test)

Example 35 with 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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Aggregations

LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)42 Test (org.junit.Test)26 File (java.io.File)11 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)9 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)9 IOException (java.io.IOException)6 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)6 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)5 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)5 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)5 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)4 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)4 CheckPoint (org.neo4j.kernel.impl.transaction.log.entry.CheckPoint)4 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)4 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)4 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)4 LatestCheckPoint (org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint)4 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)3 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)3 HashMap (java.util.HashMap)2