Search in sources :

Example 46 with LifeSupport

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

the class PhysicalLogFileTest method skipLogFileWithoutHeader.

@Test
public void skipLogFileWithoutHeader() throws IOException {
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles physicalLogFiles = new PhysicalLogFiles(directory.directory(), "logs", fs);
    PhysicalLogFile physicalLogFile = new PhysicalLogFile(fs, physicalLogFiles, 1000, () -> 1L, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10));
    life.add(physicalLogFile);
    life.start();
    // simulate new file without header presence
    PhysicalLogFile logFileToSearchFrom = new PhysicalLogFile(fs, physicalLogFiles, 1000, () -> 10L, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10));
    logVersionRepository.incrementAndGetVersion();
    fs.create(physicalLogFiles.getLogFileForVersion(logVersionRepository.getCurrentLogVersion())).close();
    PhysicalLogicalTransactionStore.LogVersionLocator versionLocator = new PhysicalLogicalTransactionStore.LogVersionLocator(4L);
    logFileToSearchFrom.accept(versionLocator);
    LogPosition logPosition = versionLocator.getLogPosition();
    assertEquals(1, logPosition.getLogVersion());
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 47 with LifeSupport

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

the class PhysicalLogicalTransactionStoreTest method shouldThrowNoSuchTransactionExceptionIfLogFileIsMissing.

@Test
public void shouldThrowNoSuchTransactionExceptionIfLogFileIsMissing() throws Exception {
    // GIVEN
    LogFile logFile = mock(LogFile.class);
    // a missing file
    when(logFile.getReader(any(LogPosition.class))).thenThrow(new FileNotFoundException());
    // Which is nevertheless in the metadata cache
    TransactionMetadataCache cache = new TransactionMetadataCache(10);
    cache.cacheTransactionMetadata(10, new LogPosition(2, 130), 1, 1, 100, System.currentTimeMillis());
    LifeSupport life = new LifeSupport();
    final LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, cache, new VersionAwareLogEntryReader<>());
    try {
        life.start();
        // we ask for that transaction and forward
        try {
            txStore.getTransactions(10);
            fail();
        } catch (NoSuchTransactionException e) {
        // THEN
        // We don't get a FileNotFoundException but a NoSuchTransactionException instead
        }
    } finally {
        life.shutdown();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 48 with LifeSupport

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

the class PhysicalLogicalTransactionStoreTest method shouldOpenAndRecoverExistingData.

@Test
public void shouldOpenAndRecoverExistingData() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final int masterId = 2, authorId = 1;
    final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.start();
    try {
        addATransactionAndRewind(life, logFile, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    life = new LifeSupport();
    final AtomicBoolean recoveryRequired = new AtomicBoolean();
    FakeRecoveryVisitor visitor = new FakeRecoveryVisitor(additionalHeader, masterId, authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted);
    logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, positionCache, new VersionAwareLogEntryReader<>());
    life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH));
    life.add(new Recovery(new Recovery.SPI() {

        @Override
        public void forceEverything() {
        }

        @Override
        public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
            recoveryRequired.set(true);
            return visitor;
        }

        @Override
        public LogPosition getPositionToRecoverFrom() throws IOException {
            return LogPosition.start(0);
        }

        @Override
        public TransactionCursor getTransactions(LogPosition position) throws IOException {
            return txStore.getTransactions(position);
        }

        @Override
        public void allTransactionsRecovered(CommittedTransactionRepresentation lastRecoveredTransaction, LogPosition positionAfterLastRecoveredTransaction) throws Exception {
        }
    }, mock(Recovery.Monitor.class)));
    // WHEN
    try {
        life.start();
    } finally {
        life.shutdown();
    }
    // THEN
    assertEquals(1, visitor.getVisitedTransactions());
    assertTrue(recoveryRequired.get());
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Recovery(org.neo4j.kernel.recovery.Recovery) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 49 with LifeSupport

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

the class PhysicalLogicalTransactionStoreTest method shouldExtractMetadataFromExistingTransaction.

@Test
public void shouldExtractMetadataFromExistingTransaction() throws Exception {
    // GIVEN
    TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final int masterId = 2, authorId = 1;
    final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, txIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.start();
    try {
        addATransactionAndRewind(life, logFile, positionCache, txIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    life = new LifeSupport();
    logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, txIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFile, positionCache, new VersionAwareLogEntryReader<>());
    // WHEN
    life.start();
    try {
        verifyTransaction(txIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
    } finally {
        life.shutdown();
    }
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 50 with LifeSupport

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

the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.

@Test
public void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
    TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final int masterId = 2, authorId = 1;
    final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.start();
    try {
        addATransactionAndRewind(life, logFile, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    PhysicalLogFile emptyLogFile = new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache);
    // create empty transaction log file and clear transaction cache to force re-read
    fileSystemRule.get().create(logFiles.getLogFileForVersion(logFiles.getHighestLogVersion() + 1)).close();
    positionCache.clear();
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(emptyLogFile, positionCache, new VersionAwareLogEntryReader<>());
    verifyTransaction(transactionIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

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