Search in sources :

Example 16 with Monitors

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

the class CancelIndexPopulationIT method shouldKeepIndexInPopulatingStateBetweenRestarts.

@Test
void shouldKeepIndexInPopulatingStateBetweenRestarts() throws InterruptedException {
    DatabaseManagementService dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        // given
        Monitors monitors = db.getDependencyResolver().resolveDependency(Monitors.class);
        Barrier.Control barrier = new Barrier.Control();
        monitors.addMonitorListener(populationCompletionBlocker(barrier));
        // when
        createRelevantNode(db);
        createIndex(db);
        barrier.await();
    } finally {
        // This call to shutdown will eventually make a call to populationCancelled on the monitor below
        dbms.shutdown();
    }
    dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        // then
        assertEquals(Schema.IndexState.ONLINE, awaitAndGetIndexState(db));
    } finally {
        dbms.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Monitors(org.neo4j.monitoring.Monitors) Barrier(org.neo4j.test.Barrier) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 17 with Monitors

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

the class RecoveryIT method shouldForceRecoveryEvenThoughNotSeeminglyRequired.

@Test
void shouldForceRecoveryEvenThoughNotSeeminglyRequired() throws Exception {
    // given
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    assertFalse(isRecoveryRequired(layout));
    // Make an ID generator, say for the node store, dirty
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), "my db");
    try (IdGenerator idGenerator = idGeneratorFactory.open(pageCache, layout.idNodeStore(), IdType.NODE, () -> 0L, /*will not be used*/
    10_000, writable(), Config.defaults(), NULL, Sets.immutable.empty())) {
        // Merely opening a marker will make the backing GBPTree dirty
        idGenerator.marker(NULL).close();
    }
    assertFalse(isRecoveryRequired(layout));
    assertTrue(idGeneratorIsDirty(layout.idNodeStore(), IdType.NODE));
    // when
    MutableBoolean recoveryRunEvenThoughNoCommitsAfterLastCheckpoint = new MutableBoolean();
    RecoveryStartInformationProvider.Monitor monitor = new RecoveryStartInformationProvider.Monitor() {

        @Override
        public void noCommitsAfterLastCheckPoint(LogPosition logPosition) {
            recoveryRunEvenThoughNoCommitsAfterLastCheckpoint.setTrue();
        }
    };
    Monitors monitors = new Monitors();
    monitors.addMonitorListener(monitor);
    Recovery.performRecovery(fileSystem, pageCache, EMPTY, Config.defaults(), layout, defaultStorageEngine(), true, nullLogProvider(), monitors, Iterables.cast(Services.loadAll(ExtensionFactory.class)), Optional.empty(), null, INSTANCE, Clock.systemUTC());
    // then
    assertFalse(idGeneratorIsDirty(layout.idNodeStore(), IdType.NODE));
    assertTrue(recoveryRunEvenThoughNoCommitsAfterLastCheckpoint.booleanValue());
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Monitors(org.neo4j.monitoring.Monitors) IdGenerator(org.neo4j.internal.id.IdGenerator) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 18 with Monitors

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

the class RecoveryCleanupIT method setMonitor.

private void setMonitor(Object monitor) {
    Monitors monitors = new Monitors();
    monitors.addMonitorListener(monitor);
    factory.setMonitors(monitors);
}
Also used : Monitors(org.neo4j.monitoring.Monitors)

Example 19 with Monitors

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

the class TransactionStateMachineSPIProviderV4Test method newSpiProvider.

private TransactionStateMachineSPIProvider newSpiProvider(DatabaseManagementService managementService) {
    var clock = mock(SystemNanoClock.class);
    var dbProvider = new BoltKernelDatabaseManagementServiceProvider(managementService, new Monitors(), clock, Duration.ZERO);
    return new TransactionStateMachineSPIProviderV4(dbProvider, mockBoltChannel, clock, mock(MemoryTracker.class, RETURNS_MOCKS));
}
Also used : BoltKernelDatabaseManagementServiceProvider(org.neo4j.bolt.dbapi.impl.BoltKernelDatabaseManagementServiceProvider) Monitors(org.neo4j.monitoring.Monitors) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 20 with Monitors

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

the class TransactionStateMachineSPIProviderV4Test method shouldAllocateMemoryForTransactionStateMachineSPI.

@Test
void shouldAllocateMemoryForTransactionStateMachineSPI() throws BoltProtocolBreachFatality, BoltIOException {
    String databaseName = "neo4j";
    var clock = mock(SystemNanoClock.class);
    DatabaseManagementService managementService = managementService(databaseName);
    var memoryTracker = mock(MemoryTracker.class);
    var scopedMemoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    when(mockBoltChannel.defaultDatabase()).thenReturn("neo4j");
    when(memoryTracker.getScopedMemoryTracker()).thenReturn(scopedMemoryTracker);
    var dbProvider = new BoltKernelDatabaseManagementServiceProvider(managementService, new Monitors(), clock, Duration.ZERO);
    var spiProvider = new TransactionStateMachineSPIProviderV4(dbProvider, mockBoltChannel, clock, memoryTracker);
    spiProvider.getTransactionStateMachineSPI("", mock(StatementProcessorReleaseManager.class));
    verify(memoryTracker).getScopedMemoryTracker();
    verify(scopedMemoryTracker).allocateHeap(TransactionStateMachineV4SPI.SHALLOW_SIZE);
    verify(scopedMemoryTracker).allocateHeap(BoltKernelGraphDatabaseServiceProvider.SHALLOW_SIZE);
    verify(scopedMemoryTracker).getScopedMemoryTracker();
    verifyNoMoreInteractions(memoryTracker);
    verifyNoMoreInteractions(scopedMemoryTracker);
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) BoltKernelDatabaseManagementServiceProvider(org.neo4j.bolt.dbapi.impl.BoltKernelDatabaseManagementServiceProvider) Monitors(org.neo4j.monitoring.Monitors) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

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