Search in sources :

Example 1 with ConsistencyFlags

use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method corruptionInCountsStore.

@Test
void corruptionInCountsStore() throws Exception {
    MutableObject<Long> rootNode = new MutableObject<>();
    Path countsStoreFile = countsStoreFile();
    final LayoutBootstrapper countsLayoutBootstrapper = (indexFile, pageCache, meta) -> new CountsLayout();
    corruptIndexes(fs, readOnly(), (tree, inspection) -> {
        rootNode.setValue(inspection.getRootNode());
        tree.unsafe(pageSpecificCorruption(rootNode.getValue(), GBPTreeCorruption.broken(GBPTreePointerType.leftSibling())), CursorContext.NULL);
    }, countsLayoutBootstrapper, countsStoreFile);
    ConsistencyFlags flags = new ConsistencyFlags(false, false, true);
    ConsistencyCheckService.Result result = runConsistencyCheck(NullLogProvider.getInstance(), flags);
    assertFalse(result.isSuccessful());
    assertResultContainsMessage(result, "Index inconsistency: Broken pointer found in tree node " + rootNode.getValue() + ", pointerType='left sibling'");
    assertResultContainsMessage(result, "Number of inconsistent COUNTS records: 1");
}
Also used : Path(java.nio.file.Path) BeforeEach(org.junit.jupiter.api.BeforeEach) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) GBPTreeCorruption.pageSpecificCorruption(org.neo4j.index.internal.gbptree.GBPTreeCorruption.pageSpecificCorruption) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Config(org.neo4j.configuration.Config) NullLogProvider(org.neo4j.logging.NullLogProvider) InspectingVisitor(org.neo4j.index.internal.gbptree.InspectingVisitor) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NATIVE30(org.neo4j.configuration.GraphDatabaseSettings.SchemaIndex.NATIVE30) BeforeAll(org.junit.jupiter.api.BeforeAll) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) String.format(java.lang.String.format) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) List(java.util.List) NATIVE_BTREE10(org.neo4j.configuration.GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Writer(java.io.Writer) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) IOUtils.readLines(org.apache.commons.io.IOUtils.readLines) NONE(org.neo4j.internal.helpers.progress.ProgressMonitorFactory.NONE) ImmutableLongList(org.eclipse.collections.api.list.primitive.ImmutableLongList) GBPTreeInspection(org.neo4j.index.internal.gbptree.GBPTreeInspection) Arrays(org.bouncycastle.util.Arrays) Label(org.neo4j.graphdb.Label) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) LogProvider(org.neo4j.logging.LogProvider) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) JobSchedulerFactory.createInitialisedScheduler(org.neo4j.kernel.impl.scheduler.JobSchedulerFactory.createInitialisedScheduler) GBPTreeBootstrapper(org.neo4j.index.internal.gbptree.GBPTreeBootstrapper) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) GBPTree(org.neo4j.index.internal.gbptree.GBPTree) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) SchemaLayouts(org.neo4j.kernel.impl.index.schema.SchemaLayouts) CountsLayout(org.neo4j.internal.counts.CountsLayout) GBPTreeCorruption(org.neo4j.index.internal.gbptree.GBPTreeCorruption) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobScheduler(org.neo4j.scheduler.JobScheduler) FileHandle(org.neo4j.io.fs.FileHandle) DEFAULT(org.neo4j.consistency.checking.full.ConsistencyFlags.DEFAULT) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StringWriter(java.io.StringWriter) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) IOException(java.io.IOException) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) GBPTreePointerType(org.neo4j.index.internal.gbptree.GBPTreePointerType) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) NO_FLUSH_ON_CLOSE(org.neo4j.index.internal.gbptree.GBPTreeOpenOptions.NO_FLUSH_ON_CLOSE) GraphDatabaseSettings.neo4j_home(org.neo4j.configuration.GraphDatabaseSettings.neo4j_home) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) LayoutBootstrapper(org.neo4j.index.internal.gbptree.LayoutBootstrapper) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LayoutBootstrapper(org.neo4j.index.internal.gbptree.LayoutBootstrapper) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) CountsLayout(org.neo4j.internal.counts.CountsLayout) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.jupiter.api.Test)

Example 2 with ConsistencyFlags

use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.

the class RelationshipCheckerWithRelationshipTypeIndexTest method doVerifyCorrectReport.

@SafeVarargs
private void doVerifyCorrectReport(Density density, ThrowingConsumer<IndexUpdater, IndexEntryConflictException> targetRelationshipAction, Consumer<ConsistencyReport.RelationshipTypeScanConsistencyReport>... expectedCalls) throws Exception {
    double recordFrequency = densityAsFrequency(density);
    int nbrOfRelationships = random.nextInt(1, 2 * IDS_PER_CHUNK);
    int targetRelationshipRelationship = random.nextInt(nbrOfRelationships);
    // given
    try (Transaction tx = db.beginTx();
        IndexUpdater writer = relationshipTypeIndexWriter()) {
        for (int i = 0; i < nbrOfRelationships; i++) {
            if (i == targetRelationshipRelationship) {
                targetRelationshipAction.accept(writer);
            } else {
                if (random.nextDouble() < recordFrequency) {
                    createCompleteEntry(writer, type);
                } else {
                    notInUse(createStoreEntry(type));
                }
            }
        }
        tx.commit();
    }
    // when
    ConsistencyFlags flags = new ConsistencyFlags(true, true, true);
    check(context(flags));
    // then
    if (expectedCalls != null) {
        for (Consumer<ConsistencyReport.RelationshipTypeScanConsistencyReport> expectedCall : expectedCalls) {
            expect(ConsistencyReport.RelationshipTypeScanConsistencyReport.class, expectedCall);
        }
    } else {
        verifyNoInteractions(monitor);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport)

Example 3 with ConsistencyFlags

use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.

the class LabelScanStoreTxApplyRaceIT method shouldStressIt.

/**
 * The test case is basically loads of concurrent CREATE/DELETE NODE or sometimes just CREATE, keeping the created node in an array
 * for dedicated deleter threads to pick up and delete as fast as they can see them. This concurrently with large creation transactions.
 */
@Test
void shouldStressIt() throws Throwable {
    // given
    Race race = new Race().withMaxDuration(5, TimeUnit.SECONDS);
    AtomicReferenceArray<Node> nodeHeads = new AtomicReferenceArray<>(NUMBER_OF_CREATORS);
    for (int i = 0; i < NUMBER_OF_CREATORS; i++) {
        race.addContestant(creator(nodeHeads, i));
    }
    race.addContestants(NUMBER_OF_DELETORS, deleter(nodeHeads));
    // when
    race.go();
    // then
    DatabaseLayout dbLayout = db.databaseLayout();
    managementService.shutdown();
    assertTrue(new ConsistencyCheckService().runFullConsistencyCheck(dbLayout, defaults(GraphDatabaseSettings.neo4j_home, testDirectory.homePath()), NONE, new Log4jLogProvider(System.out), false, new ConsistencyFlags(true, true, true)).isSuccessful());
}
Also used : ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Race(org.neo4j.test.Race) Node(org.neo4j.graphdb.Node) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 4 with ConsistencyFlags

use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.

the class CheckConsistencyCommandIT method passesOnCheckParameters.

@Test
void passesOnCheckParameters() throws Exception {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    when(consistencyCheckService.runFullConsistencyCheck(any(), any(), any(), any(), any(), anyBoolean(), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.success(null, null));
    CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--check-graph=false", "--check-indexes=false", "--check-index-structure=true");
    checkConsistencyCommand.execute();
    verify(consistencyCheckService).runFullConsistencyCheck(any(), any(), any(), any(), any(), anyBoolean(), any(), eq(new ConsistencyFlags(false, false, true)));
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) Test(org.junit.jupiter.api.Test)

Example 5 with ConsistencyFlags

use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method shouldNotCheckIndexesIfConfiguredNotTo.

@Test
void shouldNotCheckIndexesIfConfiguredNotTo() throws Exception {
    MutableObject<Long> targetNode = new MutableObject<>();
    Path[] indexFiles = schemaIndexFiles();
    corruptIndexes(readOnly(), (tree, inspection) -> {
        targetNode.setValue(inspection.getRootNode());
        tree.unsafe(pageSpecificCorruption(targetNode.getValue(), GBPTreeCorruption.notATreeNode()), CursorContext.NULL);
    }, indexFiles);
    ConsistencyFlags flags = new ConsistencyFlags(true, false, false);
    ConsistencyCheckService.Result result = runConsistencyCheck(NullLogProvider.getInstance(), flags);
    assertTrue(result.isSuccessful(), "Expected store to be consistent when not checking indexes.");
}
Also used : Path(java.nio.file.Path) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.jupiter.api.Test)

Aggregations

ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)9 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)5 MutableObject (org.apache.commons.lang3.mutable.MutableObject)5 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)4 IOException (java.io.IOException)3 Config (org.neo4j.configuration.Config)3 ConsistencyCheckIncompleteException (org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException)3 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 String.format (java.lang.String.format)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Consumer (java.util.function.Consumer)2 IOUtils.readLines (org.apache.commons.io.IOUtils.readLines)2 Arrays (org.bouncycastle.util.Arrays)2 ImmutableLongList (org.eclipse.collections.api.list.primitive.ImmutableLongList)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2