Search in sources :

Example 1 with CheckpointInfo

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

the class CheckPointerIntegrationTest method shouldCheckPointBasedOnTxCount.

@Test
void shouldCheckPointBasedOnTxCount() throws Throwable {
    // given
    DatabaseManagementService managementService = builder.setConfig(check_point_interval_time, ofMillis(300)).setConfig(check_point_interval_tx, 1).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
    int counter;
    try {
        GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
        // when
        try (Transaction tx = db.beginTx()) {
            tx.createNode();
            tx.commit();
        }
        // Instead of waiting 10s for the background job to do this check, perform the check right here
        triggerCheckPointAttempt(db);
        List<CheckpointInfo> checkpoints = checkPointsInTxLog(db);
        assertThat(checkpoints).isNotEmpty();
        counter = checkpoints.size();
    } finally {
        managementService.shutdown();
    }
    managementService = builder.build();
    try {
        // then - checkpoints + shutdown checkpoint have been written in the log
        var checkpointInfos = checkPointsInTxLog(managementService.database(DEFAULT_DATABASE_NAME));
        // Use greater-than-or-equal-to in order to accommodate the following data-race:
        // Since the `threshold.isCheckPointingNeeded()` call in CheckPointerImpl is done outside of the `mutex.checkPoint()` lock,
        // and also the `check_point_interval_time` is 300 milliseconds, it means that our direct `triggerCheckPointAttempt( db )` call
        // can race with the scheduled checkpoints, and both can decide that a checkpoint is needed. They will then coordinate via the
        // lock to do two checkpoints, one after the other. If our direct call wins the race and goes first, then the scheduled
        // checkpoint will race with our `checkPointInTxLog( db )` call, which can then count only one checkpoint in the log when there
        // are actually two.
        assertThat(checkpointInfos.size()).isGreaterThanOrEqualTo(counter + 1);
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) Test(org.junit.jupiter.api.Test)

Example 2 with CheckpointInfo

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

the class CheckPointerIntegrationTest method shouldCheckPointBasedOnTime.

@Test
void shouldCheckPointBasedOnTime() throws Throwable {
    // given
    long millis = 200;
    DatabaseManagementService managementService = builder.setConfig(check_point_interval_time, ofMillis(millis)).setConfig(check_point_interval_tx, 10000).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // when
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    // The scheduled job checking whether or not checkpoints are needed runs more frequently
    // now that we've set the time interval so low, so we can simply wait for it here
    long endTime = currentTimeMillis() + SECONDS.toMillis(30);
    while (checkPointInTxLog(db).isEmpty()) {
        Thread.sleep(millis);
        assertTrue(currentTimeMillis() < endTime, "Took too long to produce a checkpoint");
    }
    managementService.shutdown();
    managementService = builder.build();
    try {
        // then - 2 check points have been written in the log
        List<CheckpointInfo> checkPoints = checkPointsInTxLog(managementService.database(DEFAULT_DATABASE_NAME));
        assertTrue(checkPoints.size() >= 2, "Expected at least two (at least one for time interval and one for shutdown), was " + checkPoints.toString());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) Test(org.junit.jupiter.api.Test)

Example 3 with CheckpointInfo

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

the class RelationshipTypeIndexIT method removeLastCheckpointRecordFromLastLogFile.

private void removeLastCheckpointRecordFromLastLogFile() {
    try {
        LogFiles logFiles = buildLogFiles();
        Optional<CheckpointInfo> latestCheckpoint = logFiles.getCheckpointFile().findLatestCheckpoint();
        if (latestCheckpoint.isPresent()) {
            try (StoreChannel storeChannel = fs.write(logFiles.getCheckpointFile().getCurrentFile())) {
                storeChannel.truncate(latestCheckpoint.get().getCheckpointEntryPosition().getByteOffset());
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) IOException(java.io.IOException) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo)

Example 4 with CheckpointInfo

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

the class RecoveryHelpers method removeLastCheckpointRecordFromLastLogFile.

public static void removeLastCheckpointRecordFromLastLogFile(DatabaseLayout dbLayout, FileSystemAbstraction fs) throws IOException {
    LogFiles logFiles = buildLogFiles(dbLayout, fs);
    var checkpointFile = logFiles.getCheckpointFile();
    Optional<CheckpointInfo> latestCheckpoint = checkpointFile.findLatestCheckpoint();
    latestCheckpoint.ifPresent(checkpointInfo -> {
        LogPosition entryPosition = checkpointInfo.getCheckpointEntryPosition();
        try (StoreChannel storeChannel = fs.write(checkpointFile.getCurrentFile())) {
            storeChannel.truncate(entryPosition.getByteOffset());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 5 with CheckpointInfo

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

the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs.

@Test
void shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs() throws Exception {
    // GIVEN
    long txLogLowVersion = 2;
    long txLogHighVersion = 10;
    long checkpointLogLowVersion = 0;
    long checkpointLogHighVersion = 3;
    StoreId storeId = new StoreId(12345);
    LogPosition checkpointLogPosition = new LogPosition(checkpointLogHighVersion, 34);
    Database database = databaseWithLogFilesContainingLowestTxId(logs(transactionLogsWithTransaction(txLogLowVersion, txLogHighVersion, 42), checkpointLogsWithLastCheckpoint(checkpointLogLowVersion, checkpointLogHighVersion, new CheckpointInfo(new LogEntryDetachedCheckpoint(KernelVersion.LATEST, checkpointLogPosition, 1234, storeId, "testing"), checkpointLogPosition))));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("existing transaction log versions " + txLogLowVersion + "-" + txLogHighVersion).containsMessages("existing checkpoint log versions " + checkpointLogLowVersion + "-" + checkpointLogHighVersion);
}
Also used : LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) StoreId(org.neo4j.storageengine.api.StoreId) Log(org.neo4j.logging.Log) Database(org.neo4j.kernel.database.Database) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

CheckpointInfo (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo)8 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)5 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)2 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 StoreChannel (org.neo4j.io.fs.StoreChannel)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)2 UncheckedIOException (java.io.UncheckedIOException)1 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)1 Database (org.neo4j.kernel.database.Database)1 LogEntryDetachedCheckpoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 Log (org.neo4j.logging.Log)1 StoreId (org.neo4j.storageengine.api.StoreId)1