Search in sources :

Example 1 with NO_MONITOR

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.NO_MONITOR 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)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Supplier (java.util.function.Supplier)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 Parameterized (org.junit.runners.Parameterized)1 ByteUnit.mebiBytes (org.neo4j.io.ByteUnit.mebiBytes)1 DeadSimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository)1 FlushablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChannel)1 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)1 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)1