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();
}
}
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();
}
}
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);
}
}
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);
}
});
}
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);
}
Aggregations