Search in sources :

Example 36 with PhysicalLogFiles

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());
}
Also used : Command(org.neo4j.kernel.impl.transaction.command.Command) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 37 with PhysicalLogFiles

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;
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 38 with PhysicalLogFiles

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);
    }
}
Also used : PrintStream(java.io.PrintStream) Args(org.neo4j.helpers.Args) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) CheckType(org.neo4j.tools.txlog.checktypes.CheckType) File(java.io.File) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 39 with PhysicalLogFiles

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);
}
Also used : ResourceIterator(org.neo4j.graphdb.ResourceIterator) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Log(org.neo4j.logging.Log) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) ThrowingSupplier(org.neo4j.function.ThrowingSupplier) HighLimit(org.neo4j.kernel.impl.store.format.highlimit.HighLimit) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) PageCache(org.neo4j.io.pagecache.PageCache) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) Set(java.util.Set) BinaryOperator(java.util.function.BinaryOperator) UnsatisfiedDependencyException(org.neo4j.kernel.impl.util.UnsatisfiedDependencyException) Cluster(org.neo4j.causalclustering.discovery.Cluster) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TransactionIdTracker(org.neo4j.kernel.api.txtracking.TransactionIdTracker) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Predicates.awaitEx(org.neo4j.function.Predicates.awaitEx) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) Role(org.neo4j.causalclustering.core.consensus.roles.Role) ClusterMember(org.neo4j.causalclustering.discovery.ClusterMember) Label(org.neo4j.graphdb.Label) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Iterables.count(org.neo4j.helpers.collection.Iterables.count) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) MINUTES(java.util.concurrent.TimeUnit.MINUTES) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) Duration.ofSeconds(java.time.Duration.ofSeconds) Function(java.util.function.Function) Node(org.neo4j.graphdb.Node) HashSet(java.util.HashSet) CatchupPollingProcess(org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TIME(org.neo4j.kernel.impl.store.MetaDataStore.Position.TIME) BiConsumer(java.util.function.BiConsumer) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) FileNames(org.neo4j.causalclustering.core.consensus.log.segmented.FileNames) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) FileCopyMonitor(org.neo4j.causalclustering.catchup.tx.FileCopyMonitor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DbRepresentation(org.neo4j.test.DbRepresentation) Clock(java.time.Clock) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 40 with PhysicalLogFiles

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;
}
Also used : LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) PositionToRecoverFrom(org.neo4j.kernel.recovery.PositionToRecoverFrom) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) File(java.io.File) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Aggregations

PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)53 File (java.io.File)38 Test (org.junit.Test)29 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)29 Command (org.neo4j.kernel.impl.transaction.command.Command)15 IOException (java.io.IOException)14 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)12 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)11 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)7 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)6 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)6 Function (java.util.function.Function)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Rule (org.junit.Rule)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5