Search in sources :

Example 41 with LifeSupport

use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.

the class PhysicalLogFileTest method shouldReadOlderLogs.

@Test
public void shouldReadOlderLogs() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
    // WHEN
    life.start();
    try {
        FlushablePositionAwareChannel writer = logFile.getWriter();
        LogPositionMarker positionMarker = new LogPositionMarker();
        writer.getCurrentPosition(positionMarker);
        LogPosition position1 = positionMarker.newPosition();
        int intValue = 45;
        long longValue = 4854587;
        byte[] someBytes = someBytes(40);
        writer.putInt(intValue);
        writer.putLong(longValue);
        writer.put(someBytes, someBytes.length);
        writer.prepareForFlush().flush();
        writer.getCurrentPosition(positionMarker);
        LogPosition position2 = positionMarker.newPosition();
        long longValue2 = 123456789L;
        writer.putLong(longValue2);
        writer.put(someBytes, someBytes.length);
        writer.prepareForFlush().flush();
        // THEN
        try (ReadableClosableChannel reader = logFile.getReader(position1)) {
            assertEquals(intValue, reader.getInt());
            assertEquals(longValue, reader.getLong());
            assertArrayEquals(someBytes, readBytes(reader, 40));
        }
        try (ReadableClosableChannel reader = logFile.getReader(position2)) {
            assertEquals(longValue2, reader.getLong());
            assertArrayEquals(someBytes, readBytes(reader, 40));
        }
    } finally {
        life.shutdown();
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Matchers.anyString(org.mockito.Matchers.anyString) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 42 with LifeSupport

use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.

the class PhysicalLogFileTest method shouldVisitLogFile.

@Test
public void shouldVisitLogFile() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
    life.start();
    FlushablePositionAwareChannel writer = logFile.getWriter();
    LogPositionMarker mark = new LogPositionMarker();
    writer.getCurrentPosition(mark);
    for (int i = 0; i < 5; i++) {
        writer.put((byte) i);
    }
    writer.prepareForFlush();
    // WHEN/THEN
    final AtomicBoolean called = new AtomicBoolean();
    logFile.accept((position, channel) -> {
        for (int i = 0; i < 5; i++) {
            assertEquals((byte) i, channel.get());
        }
        called.set(true);
        return true;
    }, mark.newPosition());
    assertTrue(called.get());
    life.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 43 with LifeSupport

use of org.neo4j.kernel.lifecycle.LifeSupport 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 44 with LifeSupport

use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.

the class LabelScanStoreTest method start.

private void start(List<NodeLabelUpdate> existingData, boolean usePersistentStore, boolean readOnly) {
    life = new LifeSupport();
    monitor = new TrackingMonitor();
    store = createLabelScanStore(fileSystemRule.get(), dir, existingData, usePersistentStore, readOnly, monitor);
    life.add(store);
    life.start();
    assertTrue(monitor.initCalled);
}
Also used : LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport)

Example 45 with LifeSupport

use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.

the class KernelTransactionsTest method newKernelTransactions.

private static KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions) throws Throwable {
    LifeSupport life = new LifeSupport();
    life.start();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(0, 0, 0));
    Tracers tracers = new Tracers("null", NullLog.getInstance(), new Monitors(), mock(JobScheduler.class));
    StatementLocksFactory statementLocksFactory = new SimpleStatementLocksFactory(locks);
    StatementOperationContainer statementOperationsContianer = new StatementOperationContainer(null, null);
    KernelTransactions transactions;
    if (testKernelTransactions) {
        transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    } else {
        transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    }
    transactions.start();
    return transactions;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StatementLocksFactory(org.neo4j.kernel.impl.locking.StatementLocksFactory) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Tracers(org.neo4j.kernel.monitoring.tracing.Tracers)

Aggregations

LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)51 Test (org.junit.Test)22 IOException (java.io.IOException)14 File (java.io.File)12 Monitors (org.neo4j.kernel.monitoring.Monitors)12 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)6 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)6 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)5 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)5 Monitor (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor)5 Dependencies (org.neo4j.kernel.impl.util.Dependencies)5 StorageEngine (org.neo4j.storageengine.api.StorageEngine)5 URI (java.net.URI)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Config (org.neo4j.kernel.configuration.Config)4 UnableToCopyStoreFromOldMasterException (org.neo4j.kernel.ha.store.UnableToCopyStoreFromOldMasterException)4 KernelContext (org.neo4j.kernel.impl.spi.KernelContext)4