use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogsTest method shouldReportRelationshipInconsistenciesFromDifferentLogs.
@Test
public void shouldReportRelationshipInconsistenciesFromDifferentLogs() throws IOException {
// Given
File log1 = logFile(1);
File log2 = logFile(2);
File log3 = logFile(3);
writeTxContent(log1, 0, new Command.RelationshipCommand(new RelationshipRecord(42, false, -1, -1, -1, -1, -1, -1, -1, false, false), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.RelationshipCommand(new RelationshipRecord(21, true, 1, 2, 3, 4, 5, 6, 7, true, true), new RelationshipRecord(21, false, -1, -1, -1, -1, -1, -1, -1, false, false)));
writeTxContent(log2, 0, new Command.RelationshipCommand(new RelationshipRecord(42, true, 1, 2, 3, 9, 5, 6, 7, true, true), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true)));
writeTxContent(log3, 0, new Command.RelationshipCommand(new RelationshipRecord(53, true, 1, 2, 3, 4, 5, 6, 7, true, true), new RelationshipRecord(53, true, 1, 2, 30, 4, 14, 6, 7, true, true)), new Command.RelationshipCommand(new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, false, true), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, false, true)));
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// When
checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, RELATIONSHIP);
// Then
assertEquals(2, handler.recordInconsistencies.size());
RelationshipRecord seenRecord1 = (RelationshipRecord) handler.recordInconsistencies.get(0).committed.record();
RelationshipRecord currentRecord1 = (RelationshipRecord) handler.recordInconsistencies.get(0).current.record();
assertEquals(42, seenRecord1.getId());
assertEquals(4, seenRecord1.getFirstPrevRel());
assertEquals(42, currentRecord1.getId());
assertEquals(9, currentRecord1.getFirstPrevRel());
RelationshipRecord seenRecord2 = (RelationshipRecord) handler.recordInconsistencies.get(1).committed.record();
RelationshipRecord currentRecord2 = (RelationshipRecord) handler.recordInconsistencies.get(1).current.record();
assertEquals(42, seenRecord2.getId());
assertTrue(seenRecord2.isFirstInFirstChain());
assertEquals(42, currentRecord2.getId());
assertFalse(currentRecord2.isFirstInFirstChain());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogs method checkAll.
// used in other projects do not remove!
public boolean checkAll(File storeDirectory) throws IOException {
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDirectory, fs);
InconsistenciesHandler handler = new PrintingInconsistenciesHandler(out);
boolean success = scan(logFiles, handler, CheckTypes.CHECK_TYPES);
success &= validateCheckPoints(logFiles, handler);
return success;
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogs method main.
public static void main(String[] args) throws Exception {
PrintStream out = System.out;
Args arguments = Args.withFlags(HELP_FLAG, VALIDATE_CHECKPOINTS_FLAG).parse(args);
if (arguments.getBoolean(HELP_FLAG)) {
printUsageAndExit(out);
}
boolean validateCheckPoints = arguments.getBoolean(VALIDATE_CHECKPOINTS_FLAG);
CheckType<?, ?>[] checkTypes = parseChecks(arguments);
File dir = parseDir(out, arguments);
boolean success = false;
try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
PhysicalLogFiles logFiles = new PhysicalLogFiles(dir, fs);
int numberOfLogFilesFound = (int) (logFiles.getHighestLogVersion() - logFiles.getLowestLogVersion() + 1);
out.println("Found " + numberOfLogFilesFound + " log files to verify in " + dir.getCanonicalPath());
CheckTxLogs tool = new CheckTxLogs(out, fs);
PrintingInconsistenciesHandler handler = new PrintingInconsistenciesHandler(out);
success = tool.scan(logFiles, handler, checkTypes);
if (validateCheckPoints) {
success &= tool.validateCheckPoints(logFiles, handler);
}
}
if (!success) {
System.exit(1);
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldBeAbleToDownloadANewStoreAfterPruning.
@Test
public void shouldBeAbleToDownloadANewStoreAfterPruning() throws Exception {
// given
Map<String, String> params = stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "keep_none", GraphDatabaseSettings.logical_log_rotation_threshold.name(), "1M", GraphDatabaseSettings.check_point_interval_time.name(), "100ms");
Cluster cluster = clusterRule.withSharedCoreParams(params).startCluster();
cluster.coreTx((db, tx) -> {
createData(db, 10);
tx.success();
});
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
ReadReplica readReplica = cluster.getReadReplicaById(0);
long highestReadReplicaLogVersion = physicalLogFiles(readReplica).getHighestLogVersion();
// when
readReplica.shutdown();
CoreClusterMember core;
do {
core = cluster.coreTx((db, tx) -> {
createData(db, 1_000);
tx.success();
});
} while (physicalLogFiles(core).getLowestLogVersion() <= highestReadReplicaLogVersion);
readReplica.start();
// then
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
assertEventually("The read replica has the same data as the core members", () -> DbRepresentation.of(readReplica.database()), equalTo(DbRepresentation.of(cluster.awaitLeader().database())), 10, TimeUnit.SECONDS);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class RecoveryRequiredChecker method isRecoveryRequiredAt.
public boolean isRecoveryRequiredAt(File dataDir) throws IOException {
File neoStore = new File(dataDir, MetaDataStore.DEFAULT_NAME);
boolean noStoreFound = !NeoStores.isStorePresent(pageCache, dataDir);
// We need config to determine where the logical log files are
if (noStoreFound) {
// No database in the specified directory.
return false;
}
long logVersion = MetaDataStore.getRecord(pageCache, neoStore, MetaDataStore.Position.LOG_VERSION);
PhysicalLogFiles logFiles = new PhysicalLogFiles(dataDir, fs);
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fs, reader);
return new PositionToRecoverFrom(finder, NO_MONITOR).apply(logVersion) != LogPosition.UNSPECIFIED;
}
Aggregations