Search in sources :

Example 36 with Monitors

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

the class RecoveryIT method cancelRecoveryInTheMiddle.

@Test
void cancelRecoveryInTheMiddle() throws Throwable {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(databaseLayout, fileSystem);
    assertTrue(isRecoveryRequired(layout));
    Monitors monitors = new Monitors();
    var guardExtensionFactory = new GlobalGuardConsumerTestExtensionFactory();
    var recoveryMonitor = new RecoveryMonitor() {

        private final AtomicBoolean reverseCompleted = new AtomicBoolean();

        private final AtomicBoolean recoveryCompleted = new AtomicBoolean();

        @Override
        public void reverseStoreRecoveryCompleted(long lowestRecoveredTxId) {
            try {
                guardExtensionFactory.getProvidedGuardConsumer().globalGuard.stop();
            } catch (Exception e) {
            // do nothing
            }
            reverseCompleted.set(true);
        }

        @Override
        public void recoveryCompleted(int numberOfRecoveredTransactions, long recoveryTimeInMilliseconds) {
            recoveryCompleted.set(true);
        }

        public boolean isReverseCompleted() {
            return reverseCompleted.get();
        }

        public boolean isRecoveryCompleted() {
            return recoveryCompleted.get();
        }
    };
    monitors.addMonitorListener(recoveryMonitor);
    var service = new TestDatabaseManagementServiceBuilder(layout.getNeo4jLayout()).addExtension(guardExtensionFactory).setMonitors(monitors).build();
    try {
        var database = service.database(layout.getDatabaseName());
        assertTrue(recoveryMonitor.isReverseCompleted());
        assertFalse(recoveryMonitor.isRecoveryCompleted());
        assertFalse(guardExtensionFactory.getProvidedGuardConsumer().globalGuard.isAvailable());
        assertFalse(database.isAvailable(0));
        var e = assertThrows(Exception.class, database::beginTx);
        assertThat(getRootCause(e)).isInstanceOf(DatabaseStartAbortedException.class);
    } finally {
        service.shutdown();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Monitors(org.neo4j.monitoring.Monitors) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 37 with Monitors

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

the class NonUniqueLuceneIndexPopulatingUpdaterIT method createIndexProvider.

private LuceneIndexProvider createIndexProvider() {
    var directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory();
    var directoryStructureFactory = directoriesByProvider(testDir.homePath());
    return new LuceneIndexProvider(fileSystem, directoryFactory, directoryStructureFactory, new Monitors(), Config.defaults(), writable());
}
Also used : Monitors(org.neo4j.monitoring.Monitors) LuceneIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneIndexProvider)

Example 38 with Monitors

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

the class DefaultBoltConnectionFactoryTest method shouldInstallKeepAliveHandler.

@Test
void shouldInstallKeepAliveHandler() {
    var schedulerProvider = mock(BoltSchedulerProvider.class);
    var config = Config.newBuilder().set(BoltConnectorInternalSettings.connection_keep_alive_type, BoltConnectorInternalSettings.KeepAliveRequestType.ALL).build();
    var logService = mock(LogService.class);
    var pipeline = mock(ChannelPipeline.class);
    var channel = mock(Channel.class, RETURNS_MOCKS);
    var protector = mock(ChannelProtector.class);
    var boltChannel = new BoltChannel("bolt123", "joffrey", channel, protector);
    var stateMachine = mock(BoltStateMachine.class);
    var messageWriter = mock(BoltResponseMessageWriter.class);
    when(channel.pipeline()).thenReturn(pipeline);
    var connectionFactory = new DefaultBoltConnectionFactory(schedulerProvider, config, logService, Clock.systemUTC(), new Monitors());
    connectionFactory.newConnection(boltChannel, stateMachine, messageWriter);
    verify(channel).pipeline();
    verify(pipeline).addLast(Mockito.any(KeepAliveHandler.class));
    verifyNoMoreInteractions(pipeline);
}
Also used : BoltChannel(org.neo4j.bolt.BoltChannel) Monitors(org.neo4j.monitoring.Monitors) KeepAliveHandler(org.neo4j.bolt.transport.pipeline.KeepAliveHandler) Test(org.junit.jupiter.api.Test)

Example 39 with Monitors

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

the class ConsistencyCheckService method runFullConsistencyCheck.

public Result runFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, final LogProvider logProvider, final FileSystemAbstraction fileSystem, final PageCache pageCache, DebugContext debugContext, Path reportDir, ConsistencyFlags consistencyFlags, PageCacheTracer pageCacheTracer, MemoryTracker memoryTracker) throws ConsistencyCheckIncompleteException {
    assertRecovered(databaseLayout, config, fileSystem, memoryTracker);
    Log outLog = logProvider.getLog(getClass());
    config.set(GraphDatabaseSettings.pagecache_warmup_enabled, false);
    LifeSupport life = new LifeSupport();
    final DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    DatabaseReadOnlyChecker readOnlyChecker = readOnly();
    StoreFactory factory = new StoreFactory(databaseLayout, config, idGeneratorFactory, pageCache, fileSystem, logProvider, pageCacheTracer, readOnlyChecker);
    // Don't start the counts stores here as part of life, instead only shut down. This is because it's better to let FullCheck
    // start it and add its missing/broken detection where it can report to user.
    ConsistencySummaryStatistics summary;
    final Path reportFile = chooseReportPath(reportDir);
    Log4jLogProvider reportLogProvider = new Log4jLogProvider(LogConfig.createBuilder(fileSystem, reportFile, Level.INFO).createOnDemand().withCategory(false).build());
    Log reportLog = reportLogProvider.getLog(getClass());
    Log log = new DuplicatingLog(outLog, reportLog);
    // Bootstrap kernel extensions
    Monitors monitors = new Monitors();
    JobScheduler jobScheduler = life.add(JobSchedulerFactory.createInitialisedScheduler());
    TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_RELATIONSHIP_TYPE));
    final RecoveryCleanupWorkCollector workCollector = RecoveryCleanupWorkCollector.ignore();
    DatabaseExtensions extensions = life.add(instantiateExtensions(databaseLayout, fileSystem, config, new SimpleLogService(logProvider), pageCache, jobScheduler, workCollector, // We use TOOL context because it's true, and also because it uses the 'single' operational mode, which is important.
    TOOL, monitors, tokenHolders, pageCacheTracer, readOnlyChecker));
    DefaultIndexProviderMap indexes = life.add(new DefaultIndexProviderMap(extensions, config));
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        long lastCommittedTransactionId = neoStores.getMetaDataStore().getLastCommittedTransactionId();
        CountsStoreManager countsStoreManager = life.add(new CountsStoreManager(pageCache, fileSystem, databaseLayout, pageCacheTracer, memoryTracker, lastCommittedTransactionId));
        RelationshipGroupDegreesStoreManager groupDegreesStoreManager = life.add(new RelationshipGroupDegreesStoreManager(pageCache, fileSystem, databaseLayout, pageCacheTracer, memoryTracker, lastCommittedTransactionId));
        // Load tokens before starting extensions, etc.
        try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(CONSISTENCY_TOKEN_READER_TAG))) {
            tokenHolders.setInitialTokens(StoreTokens.allReadableTokens(neoStores), cursorContext);
        }
        life.start();
        IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(pageCache, databaseLayout, workCollector, readOnlyChecker, pageCacheTracer);
        life.add(indexStatisticsStore);
        int numberOfThreads = defaultConsistencyCheckThreadsNumber();
        DirectStoreAccess stores = new DirectStoreAccess(neoStores, indexes, tokenHolders, indexStatisticsStore, idGeneratorFactory);
        double memoryLimitLeewayFactor = config.get(GraphDatabaseInternalSettings.consistency_check_memory_limit_factor);
        FullCheck check = new FullCheck(progressFactory, numberOfThreads, consistencyFlags, config, debugContext, NodeBasedMemoryLimiter.defaultWithLeeway(memoryLimitLeewayFactor));
        summary = check.execute(pageCache, stores, countsStoreManager, groupDegreesStoreManager, null, pageCacheTracer, memoryTracker, log);
    } finally {
        life.shutdown();
        reportLogProvider.close();
    }
    if (!summary.isConsistent()) {
        log.warn("See '%s' for a detailed consistency report.", reportFile);
        return Result.failure(reportFile, summary);
    }
    return Result.success(reportFile, summary);
}
Also used : SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DuplicatingLog(org.neo4j.logging.DuplicatingLog) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Path(java.nio.file.Path) JobScheduler(org.neo4j.scheduler.JobScheduler) Log(org.neo4j.logging.Log) DuplicatingLog(org.neo4j.logging.DuplicatingLog) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) DatabaseExtensions(org.neo4j.kernel.extension.DatabaseExtensions) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) FullCheck(org.neo4j.consistency.checking.full.FullCheck) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Monitors(org.neo4j.monitoring.Monitors) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator)

Example 40 with Monitors

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

the class FulltextProceduresTestSupport 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(GraphDatabaseSettings.store_internal_log_level, Level.DEBUG);
}
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