Search in sources :

Example 1 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class StoreMigratorTest method extractTransactionalInformationFromLogs.

private void extractTransactionalInformationFromLogs(Path customLogsLocation) throws IOException {
    Config config = Config.defaults(transaction_logs_root_path, customLogsLocation);
    LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(transaction_logs_root_path, customLogsLocation).build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    StorageEngineFactory storageEngineFactory = database.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
    for (int i = 0; i < 10; i++) {
        try (Transaction transaction = database.beginTx()) {
            transaction.createNode();
            transaction.commit();
        }
    }
    DatabaseLayout databaseLayout = database.databaseLayout();
    Path neoStore = databaseLayout.metadataStore();
    managementService.shutdown();
    MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT, databaseLayout.getDatabaseName(), NULL);
    RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
    LogPosition logPosition = migrator.extractTransactionLogPosition(neoStore, databaseLayout, 100, NULL);
    LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(databaseLayout, fileSystem, pageCache).withConfig(config).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
    assertEquals(0, logPosition.getLogVersion());
    assertEquals(Files.size(logFiles.getLogFile().getHighestLogFile()), logPosition.getByteOffset());
}
Also used : Path(java.nio.file.Path) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Config(org.neo4j.configuration.Config) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 2 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class VersionAwareLogEntryReaderIT method correctlyResetPositionOfObservedZeroWhenChannelSwitchOnExactlyCheckedByte.

@Test
void correctlyResetPositionOfObservedZeroWhenChannelSwitchOnExactlyCheckedByte() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(entryReader).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).withKernelVersionProvider(() -> KernelVersion.V4_0).build();
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        LogPositionMarker positionMarker = new LogPositionMarker();
        LogFile logFile = logFiles.getLogFile();
        long initialPosition = getLastReadablePosition(logFiles);
        long checkpointsEndDataOffset = DEFAULT_READ_AHEAD_SIZE + initialPosition;
        TransactionLogWriter logWriter = logFile.getTransactionLogWriter();
        do {
            logWriter.legacyCheckPoint(new LogPosition(4, 5));
            logWriter.getCurrentPosition(positionMarker);
        } while (positionMarker.getByteOffset() <= checkpointsEndDataOffset);
        logFile.flush();
        logFiles.getLogFile().rotate();
        fs.truncate(logFiles.getLogFile().getLogFileForVersion(0), checkpointsEndDataOffset);
        try (StoreChannel storeChannel = fs.write(logFiles.getLogFile().getLogFileForVersion(1))) {
            storeChannel.position(CURRENT_FORMAT_LOG_HEADER_SIZE);
            storeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0 }));
        }
        try (ReadableLogChannel logChannel = logFiles.getLogFile().getReader(new LogPosition(0, initialPosition))) {
            LogEntry logEntry = entryReader.readLogEntry(logChannel);
            // we reading expected checkpoint records
            assertThat(logEntry).isInstanceOf(LogEntryInlinedCheckPoint.class);
            LogEntryInlinedCheckPoint checkPoint = (LogEntryInlinedCheckPoint) logEntry;
            LogPosition logPosition = checkPoint.getLogPosition();
            assertEquals(4, logPosition.getLogVersion());
            assertEquals(5, logPosition.getByteOffset());
            // set position to the end of the buffer to cause channel switch on next byte read
            ((PositionableChannel) logChannel).setCurrentPosition(checkpointsEndDataOffset);
            while (entryReader.readLogEntry(logChannel) != null) {
            // read to the end
            }
            // channel should be switched now and position should be just after the header
            LogPosition position = entryReader.lastPosition();
            assertEquals(CURRENT_FORMAT_LOG_HEADER_SIZE, position.getByteOffset());
            assertEquals(1, position.getLogVersion());
        }
    }
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) StoreChannel(org.neo4j.io.fs.StoreChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) PositionableChannel(org.neo4j.io.fs.PositionableChannel) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 3 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class CheckPointerIntegrationTest method checkPointInTxLog.

private static List<CheckpointInfo> checkPointInTxLog(GraphDatabaseService db) throws IOException {
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) db).getDependencyResolver();
    LogFiles logFiles = dependencyResolver.resolveDependency(LogFiles.class);
    return logFiles.getCheckpointFile().reachableCheckpoints();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 4 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class StoreUpgraderTest method removeCheckPointFromTxLog.

public static void removeCheckPointFromTxLog(FileSystemAbstraction fileSystem, Path databaseDirectory) throws IOException {
    LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, fileSystem).withCommandReaderFactory(RecordStorageCommandReaderFactory.INSTANCE).build();
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    if (logTailInformation.commitsAfterLastCheckpoint()) {
        // done already
        return;
    }
    // let's assume there is at least a checkpoint
    assertNotNull(logTailInformation.lastCheckPoint);
    LogPosition logPosition = logTailInformation.lastCheckPoint.getTransactionLogPosition();
    Path logFile = logFiles.getLogFile().getLogFileForVersion(logPosition.getLogVersion());
    long byteOffset = logPosition.getByteOffset();
    fileSystem.truncate(logFile, byteOffset);
}
Also used : Path(java.nio.file.Path) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 5 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class LogsUpgrader method assertCleanlyShutDown.

public void assertCleanlyShutDown(DatabaseLayout layout) {
    Throwable suppressibleException = null;
    try {
        // we should not use provided database layout here since transaction log location is different compare to previous versions
        // and that's why we need to use custom transaction logs locator and database layout
        DatabaseLayout oldDatabaseLayout = buildLegacyLogsLayout(layout);
        LogFiles logFiles = buildLogFiles(oldDatabaseLayout);
        LogTailInformation tail = logFiles.getTailInformation();
        if (!tail.isRecoveryRequired()) {
            // All good
            return;
        }
        if (tail.logsMissing()) {
            // There are no log files in the legacy logs location.
            // Either log files are missing entirely, or they are already in their correct place.
            logFiles = buildLogFiles(layout);
            tail = logFiles.getTailInformation();
            if (!tail.isRecoveryRequired()) {
                // Log file is already in its new location, and looks good.
                return;
            }
            if (tail.logsMissing() && !config.get(fail_on_missing_files)) {
                // We don't have any log files, but we were told to ignore this.
                return;
            }
        }
    } catch (Throwable throwable) {
        // ignore exception and throw db not cleanly shutdown
        suppressibleException = throwable;
    }
    StoreUpgrader.DatabaseNotCleanlyShutDownException exception = new StoreUpgrader.DatabaseNotCleanlyShutDownException();
    if (suppressibleException != null) {
        exception.addSuppressed(suppressibleException);
    }
    throw exception;
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles)

Aggregations

LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)61 Test (org.junit.jupiter.api.Test)33 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)21 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)16 Path (java.nio.file.Path)13 IOException (java.io.IOException)10 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)10 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 StoreChannel (org.neo4j.io.fs.StoreChannel)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)4 UncheckedIOException (java.io.UncheckedIOException)3