Search in sources :

Example 16 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method tracePageCacheAccessOnConsistencyCheck.

@Test
void tracePageCacheAccessOnConsistencyCheck() throws ConsistencyCheckIncompleteException {
    prepareDbWithDeletedRelationshipPartOfTheChain();
    ConsistencyCheckService service = new ConsistencyCheckService(new Date());
    var pageCacheTracer = new DefaultPageCacheTracer();
    fixture.close();
    JobScheduler jobScheduler = JobSchedulerFactory.createScheduler();
    ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(testDirectory.getFileSystem(), Config.defaults(GraphDatabaseSettings.pagecache_memory, "8m"), pageCacheTracer, NullLog.getInstance(), jobScheduler, Clocks.nanoClock(), new MemoryPools(false));
    try (Lifespan life = new Lifespan(jobScheduler);
        PageCache pageCache = pageCacheFactory.getOrCreatePageCache()) {
        var result = service.runFullConsistencyCheck(fixture.databaseLayout(), Config.defaults(settings()), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), testDirectory.getFileSystem(), pageCache, false, ConsistencyFlags.DEFAULT, pageCacheTracer, INSTANCE);
        assertFalse(result.isSuccessful());
        assertThat(pageCacheTracer.pins()).isGreaterThanOrEqualTo(74);
        assertThat(pageCacheTracer.unpins()).isGreaterThanOrEqualTo(74);
        assertThat(pageCacheTracer.hits()).isGreaterThanOrEqualTo(35);
        assertThat(pageCacheTracer.faults()).isGreaterThanOrEqualTo(39);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryPools(org.neo4j.memory.MemoryPools) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Date(java.util.Date) PageCache(org.neo4j.io.pagecache.PageCache) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 17 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class IndexPopulationJobTest method before.

@BeforeEach
void before() throws Exception {
    kernel = db.getDependencyResolver().resolveDependency(Kernel.class);
    tokens = db.getDependencyResolver().resolveDependency(TokenNameLookup.class);
    tokenHolders = db.getDependencyResolver().resolveDependency(TokenHolders.class);
    stateHolder = new DatabaseSchemaState(NullLogProvider.getInstance());
    IndexingService indexingService = db.getDependencyResolver().resolveDependency(IndexingService.class);
    indexStoreView = db.getDependencyResolver().resolveDependency(IndexStoreViewFactory.class).createTokenIndexStoreView(indexingService::getIndexProxy);
    indexStatisticsStore = db.getDependencyResolver().resolveDependency(IndexStatisticsStore.class);
    jobScheduler = db.getDependencyResolver().resolveDependency(JobScheduler.class);
    try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, LoginContext.AUTH_DISABLED)) {
        labelId = tx.tokenWrite().labelGetOrCreateForName(FIRST.name());
        tx.tokenWrite().labelGetOrCreateForName(SECOND.name());
        tx.commit();
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenNameLookup(org.neo4j.common.TokenNameLookup) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) TokenHolders(org.neo4j.token.TokenHolders) Kernel(org.neo4j.kernel.api.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class FullCheckFulltextIndexEmptyDocs method check.

private ConsistencyCheckService.Result check(Config config, DatabaseLayout layout) throws Exception {
    JobScheduler jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
    ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(fs, config, NULL, NullLog.getInstance(), jobScheduler, Clocks.nanoClock(), new MemoryPools(config.get(memory_tracking)));
    PageCache pageCache = pageCacheFactory.getOrCreatePageCache();
    ConsistencyCheckService.Result result;
    try {
        result = new ConsistencyCheckService().runFullConsistencyCheck(layout, config, NONE, NullLogProvider.getInstance(), fs, pageCache, DebugContext.NO_DEBUG, layout.databaseDirectory(), DEFAULT, NULL, INSTANCE);
    } finally {
        pageCache.close();
        jobScheduler.close();
    }
    return result;
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryPools(org.neo4j.memory.MemoryPools) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) PageCache(org.neo4j.io.pagecache.PageCache)

Example 19 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class GBPTreeBootstrapperTest method shouldBootstrapTreeOfDifferentPageSizes.

@ParameterizedTest
@MethodSource("testSetupStream")
void shouldBootstrapTreeOfDifferentPageSizes(TestSetup testSetup) throws Exception {
    setupTest(testSetup);
    ZipUtils.unzipResource(getClass(), zipName, storeFile);
    LayoutBootstrapper layoutBootstrapper = (indexFile, pageCache, meta) -> layout;
    try (JobScheduler scheduler = new ThreadPoolJobScheduler();
        GBPTreeBootstrapper bootstrapper = new GBPTreeBootstrapper(fs, scheduler, layoutBootstrapper, readOnly(), PageCacheTracer.NULL)) {
        GBPTreeBootstrapper.Bootstrap bootstrap = bootstrapper.bootstrapTree(storeFile);
        assertTrue(bootstrap.isTree());
        try (GBPTree<?, ?> tree = bootstrap.getTree()) {
            assertTrue(tree.consistencyCheck(CursorContext.NULL));
        }
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) SimpleLongLayout.longLayout(org.neo4j.index.internal.gbptree.SimpleLongLayout.longLayout) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ZipUtils(org.neo4j.io.compress.ZipUtils) Disabled(org.junit.jupiter.api.Disabled) Inject(org.neo4j.test.extension.Inject) MutableLong(org.apache.commons.lang3.mutable.MutableLong) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) JobScheduler(org.neo4j.scheduler.JobScheduler) TestDirectoryExtension(org.neo4j.test.extension.testdirectory.TestDirectoryExtension) Path(java.nio.file.Path) MethodSource(org.junit.jupiter.params.provider.MethodSource) PageCache(org.neo4j.io.pagecache.PageCache) ByteUnit(org.neo4j.io.ByteUnit) StandalonePageCacheFactory(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 20 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class IndexingServiceTest method shouldNotHaveToWaitForOrphanedUniquenessIndexInRecovery.

@Test
void shouldNotHaveToWaitForOrphanedUniquenessIndexInRecovery() throws Exception {
    // given that we have a uniqueness index that needs to be recovered and that doesn't have a constraint attached to it
    IndexDescriptor descriptor = uniqueIndex.materialise(10);
    Iterable<IndexDescriptor> schemaRules = Collections.singletonList(descriptor);
    IndexProvider indexProvider = mock(IndexProvider.class);
    when(indexProvider.getInitialState(any(), any())).thenReturn(POPULATING);
    IndexProviderMap indexProviderMap = mock(IndexProviderMap.class);
    when(indexProviderMap.lookup(anyString())).thenReturn(indexProvider);
    when(indexProviderMap.lookup(any(IndexProviderDescriptor.class))).thenReturn(indexProvider);
    when(indexProviderMap.getDefaultProvider()).thenReturn(indexProvider);
    NullLogProvider logProvider = NullLogProvider.getInstance();
    IndexMapReference indexMapReference = new IndexMapReference();
    IndexProxyCreator indexProxyCreator = mock(IndexProxyCreator.class);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexProxy.getDescriptor()).thenReturn(descriptor);
    // Eventually return ONLINE so that this test won't hang if the product code changes in this regard.
    // This test should still fail below when verifying interactions with the proxy and monitor tho.
    when(indexProxy.getState()).thenReturn(POPULATING, POPULATING, POPULATING, POPULATING, ONLINE);
    when(indexProxyCreator.createRecoveringIndexProxy(any())).thenReturn(indexProxy);
    when(indexProxyCreator.createFailedIndexProxy(any(), any())).thenReturn(indexProxy);
    when(indexProxyCreator.createPopulatingIndexProxy(any(), anyBoolean(), any(), any())).thenReturn(indexProxy);
    JobScheduler scheduler = mock(JobScheduler.class);
    IndexSamplingController samplingController = mock(IndexSamplingController.class);
    IndexingService.Monitor monitor = mock(IndexingService.Monitor.class);
    IndexStoreViewFactory storeViewFactory = mock(IndexStoreViewFactory.class);
    when(storeViewFactory.createTokenIndexStoreView(any())).thenReturn(storeView);
    when(storeView.newPropertyAccessor(any(), any())).thenReturn(propertyAccessor);
    IndexingService indexingService = new IndexingService(indexProxyCreator, indexProviderMap, indexMapReference, storeViewFactory, schemaRules, samplingController, nameLookup, scheduler, null, logProvider, logProvider, monitor, mock(IndexStatisticsStore.class), PageCacheTracer.NULL, INSTANCE, "", writable(), Config.defaults());
    // and where index population starts
    indexingService.init();
    // when starting the indexing service
    indexingService.start();
    // then it should be able to start without awaiting the completion of the population of the index
    verify(indexProxy, never()).awaitStoreScanCompleted(anyLong(), any());
    verify(monitor, never()).awaitingPopulationOfRecoveredIndex(any());
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) IndexSamplingController(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingController) NullLogProvider(org.neo4j.logging.NullLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

JobScheduler (org.neo4j.scheduler.JobScheduler)44 Test (org.junit.jupiter.api.Test)22 PageCache (org.neo4j.io.pagecache.PageCache)17 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)16 Config (org.neo4j.configuration.Config)15 Path (java.nio.file.Path)12 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)11 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)9 IOException (java.io.IOException)8 TokenHolders (org.neo4j.token.TokenHolders)7 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)6 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)5 IndexImporterFactoryImpl (org.neo4j.kernel.impl.index.schema.IndexImporterFactoryImpl)5 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)5 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)4 DatabasePageCache (org.neo4j.dbms.database.DatabasePageCache)4 RecoveryCleanupWorkCollector (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)4 BatchImporter (org.neo4j.internal.batchimport.BatchImporter)4 Input (org.neo4j.internal.batchimport.input.Input)4 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)4