Search in sources :

Example 26 with Monitors

use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.

the class ConstraintRecoveryIT method shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails.

@Test
void shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails() {
    // given
    Path pathToDb = testDirectory.homePath();
    TestDatabaseManagementServiceBuilder dbFactory = new TestDatabaseManagementServiceBuilder(pathToDb);
    dbFactory.setFileSystem(fs);
    final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
    final AtomicBoolean monitorCalled = new AtomicBoolean(false);
    Monitors monitors = new Monitors();
    monitors.addMonitorListener(new IndexingService.MonitorAdapter() {

        @Override
        public void indexPopulationScanComplete() {
            monitorCalled.set(true);
            db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush(NULL);
            storeInNeedOfRecovery[0] = fs.snapshot();
        }
    });
    dbFactory.setMonitors(monitors);
    // This test relies on behaviour that is specific to the Lucene populator, where uniqueness is controlled
    // after index has been populated, which is why we're using NATIVE20 and index booleans (they end up in Lucene)
    DatabaseManagementService managementService = configure(dbFactory.impermanent().setConfig(default_schema_provider, NATIVE30.providerName())).build();
    db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        for (int i = 0; i < 2; i++) {
            tx.createNode(LABEL).setProperty(KEY, "true");
        }
        tx.commit();
    }
    assertThrows(ConstraintViolationException.class, () -> {
        try (Transaction tx = db.beginTx()) {
            tx.schema().constraintFor(LABEL).assertPropertyIsUnique(KEY).create();
        }
    });
    managementService.shutdown();
    assertTrue(monitorCalled.get());
    // when
    dbFactory = new TestDatabaseManagementServiceBuilder(pathToDb);
    dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
    DatabaseManagementService secondManagementService = configure(dbFactory.impermanent()).build();
    db = (GraphDatabaseAPI) secondManagementService.database(DEFAULT_DATABASE_NAME);
    // then
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
    }
    try (Transaction transaction = db.beginTx()) {
        assertEquals(2, Iterables.count(transaction.getAllNodes()));
    }
    try (Transaction tx = db.beginTx()) {
        assertEquals(0, Iterables.count(Iterables.asList(tx.schema().getConstraints())));
    }
    try (Transaction tx = db.beginTx()) {
        IndexDefinition orphanedConstraintIndex = single(tx.schema().getIndexes(LABEL));
        assertEquals(LABEL.name(), single(orphanedConstraintIndex.getLabels()).name());
        assertEquals(KEY, single(orphanedConstraintIndex.getPropertyKeys()));
    }
    secondManagementService.shutdown();
}
Also used : Path(java.nio.file.Path) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Monitors(org.neo4j.monitoring.Monitors) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 27 with Monitors

use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.

the class GenericIndexProviderCompatibilitySuiteTest method createIndexProvider.

@Override
protected IndexProvider createIndexProvider(PageCache pageCache, FileSystemAbstraction fs, Path graphDbDir, Config config) {
    Monitors monitors = new Monitors();
    String monitorTag = "";
    RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = RecoveryCleanupWorkCollector.immediate();
    var readOnlyChecker = new DatabaseReadOnlyChecker.Default(config, DEFAULT_DATABASE_NAME);
    return GenericNativeIndexProviderFactory.create(pageCache, graphDbDir, fs, monitors, monitorTag, config, readOnlyChecker, recoveryCleanupWorkCollector, PageCacheTracer.NULL, DEFAULT_DATABASE_NAME);
}
Also used : Monitors(org.neo4j.monitoring.Monitors) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)

Example 28 with Monitors

use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.

the class IndexCleanupIT method mustClearIndexDirectoryOnDropWhilePopulating.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void mustClearIndexDirectoryOnDropWhilePopulating(SchemaIndex schemaIndex) throws InterruptedException, IOException {
    // given
    Barrier.Control midPopulation = new Barrier.Control();
    IndexingService.MonitorAdapter trappingMonitor = new IndexingService.MonitorAdapter() {

        @Override
        public void indexPopulationScanStarting() {
            midPopulation.reached();
        }
    };
    configureDb(schemaIndex);
    createSomeData();
    Monitors monitors = db.getDependencyResolver().resolveDependency(Monitors.class);
    monitors.addMonitorListener(trappingMonitor);
    createIndex(db, false);
    midPopulation.await();
    Path[] providerDirectories = providerDirectories(fs, db);
    for (Path providerDirectory : providerDirectories) {
        assertTrue(fs.listFiles(providerDirectory).length > 0, "expected there to be at least one index per existing provider map");
    }
    // when
    dropAllIndexes();
    midPopulation.release();
    assertNoIndexFilesExisting(providerDirectories);
}
Also used : Path(java.nio.file.Path) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Monitors(org.neo4j.monitoring.Monitors) Barrier(org.neo4j.test.Barrier) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with Monitors

use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.

the class TokenIndexProviderCompatibilitySuiteTest method createIndexProvider.

@Override
protected IndexProvider createIndexProvider(PageCache pageCache, FileSystemAbstraction fs, Path graphDbDir, Config config) {
    Monitors monitors = new Monitors();
    String monitorTag = "";
    RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = RecoveryCleanupWorkCollector.immediate();
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(graphDbDir);
    var readOnlyChecker = new DatabaseReadOnlyChecker.Default(config, databaseLayout.getDatabaseName());
    return TokenIndexProviderFactory.create(pageCache, graphDbDir, fs, monitors, monitorTag, config, readOnlyChecker, recoveryCleanupWorkCollector, databaseLayout, PageCacheTracer.NULL);
}
Also used : Monitors(org.neo4j.monitoring.Monitors) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)

Example 30 with Monitors

use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.

the class StringLengthIndexValidationIT method configure.

@ExtensionCallback
void configure(TestDatabaseManagementServiceBuilder builder) {
    Monitors monitors = new Monitors();
    IndexingService.MonitorAdapter trappingMonitor = new IndexingService.MonitorAdapter() {

        @Override
        public void indexPopulationScanComplete() {
            if (trapPopulation.get()) {
                populationScanFinished.reached();
            }
        }
    };
    monitors.addMonitorListener(trappingMonitor);
    builder.setMonitors(monitors);
    builder.setConfig(default_schema_provider, schemaIndex.providerName());
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Monitors(org.neo4j.monitoring.Monitors) ExtensionCallback(org.neo4j.test.extension.ExtensionCallback)

Aggregations

Monitors (org.neo4j.monitoring.Monitors)45 Test (org.junit.jupiter.api.Test)13 Path (java.nio.file.Path)7 Config (org.neo4j.configuration.Config)7 RecoveryCleanupWorkCollector (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)7 Dependencies (org.neo4j.collection.Dependencies)6 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)5 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)5 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)5 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)5 BoltKernelDatabaseManagementServiceProvider (org.neo4j.bolt.dbapi.impl.BoltKernelDatabaseManagementServiceProvider)4 DatabaseReadOnlyChecker (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker)4 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)4 Log (org.neo4j.logging.Log)4 MemoryTracker (org.neo4j.memory.MemoryTracker)4 IOException (java.io.IOException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3