Search in sources :

Example 1 with IndexSamplingMode

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode in project neo4j by neo4j.

the class IndexProcedures method resampleOutdatedIndexes.

void resampleOutdatedIndexes(long timeOutSeconds) {
    long millis = TimeUnit.SECONDS.toMillis(timeOutSeconds);
    IndexSamplingMode mode = foregroundRebuildUpdated(millis);
    indexingService.triggerIndexSampling(mode);
}
Also used : IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode)

Example 2 with IndexSamplingMode

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode in project neo4j by neo4j.

the class BuiltInProceduresIT method prepareForReplanningShouldTriggerIndexesSampling.

@Test
void prepareForReplanningShouldTriggerIndexesSampling() {
    // Given
    ReplanMonitor monitor = replanMonitor();
    // When
    try (org.neo4j.graphdb.Transaction transaction = db.beginTx()) {
        transaction.execute("CALL db.prepareForReplanning()").close();
        transaction.commit();
    }
    // Then
    IndexSamplingMode mode = monitor.samplingMode();
    assertNotEquals(IndexSamplingMode.NO_WAIT, mode.millisToWaitForCompletion());
    assertThat(mode.millisToWaitForCompletion()).isGreaterThan(0L);
}
Also used : IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) Test(org.junit.jupiter.api.Test)

Example 3 with IndexSamplingMode

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogTriggerSamplingOnAllIndexes.

@Test
void shouldLogTriggerSamplingOnAllIndexes() throws Exception {
    // given
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
    IndexSamplingMode mode = backgroundRebuildAll();
    // when
    indexingService.triggerIndexSampling(mode);
    // then
    assertThat(internalLogProvider).forLevel(INFO).containsMessages("Manual trigger for sampling all indexes [" + mode + "]");
}
Also used : IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) Test(org.junit.jupiter.api.Test)

Example 4 with IndexSamplingMode

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode in project neo4j by neo4j.

the class Schema method sampleIndexes.

private void sampleIndexes(Label[] labels, String property, boolean sampleAll, boolean forceSample) throws ShellException {
    IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency(IndexingService.class);
    if (indexingService == null) {
        throw new ShellException("Internal error: failed to resolve IndexingService");
    }
    IndexSamplingMode samplingMode = getSamplingMode(forceSample);
    // Trigger sampling for all indices
    if (sampleAll) {
        indexingService.triggerIndexSampling(samplingMode);
        return;
    }
    validateLabelsAndProperty(labels, property);
    Statement statement = getServer().getStatement();
    int labelKey = statement.readOperations().labelGetForName(labels[0].name());
    int propertyKey = statement.readOperations().propertyKeyGetForName(property);
    if (labelKey == -1) {
        throw new ShellException("No label associated with '" + labels[0].name() + "' was found");
    }
    if (propertyKey == -1) {
        throw new ShellException("No property associated with '" + property + "' was found");
    }
    try {
        indexingService.triggerIndexSampling(SchemaDescriptorFactory.forLabel(labelKey, propertyKey), samplingMode);
    } catch (IndexNotFoundKernelException e) {
        throw new ShellException(e.getMessage());
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Statement(org.neo4j.kernel.api.Statement) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ShellException(org.neo4j.shell.ShellException)

Example 5 with IndexSamplingMode

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogTriggerSamplingOnAnIndexes.

@Test
void shouldLogTriggerSamplingOnAnIndexes() throws Exception {
    // given
    long indexId = 0;
    IndexSamplingMode mode = backgroundRebuildAll();
    IndexPrototype prototype = forSchema(forLabel(0, 1)).withIndexProvider(PROVIDER_DESCRIPTOR).withName("index");
    IndexDescriptor index = prototype.materialise(indexId);
    when(accessor.newValueReader()).thenReturn(ValueIndexReader.EMPTY);
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), index);
    life.init();
    life.start();
    // when
    indexingService.triggerIndexSampling(index, mode);
    // then
    String userDescription = index.userDescription(nameLookup);
    assertThat(internalLogProvider).forLevel(INFO).containsMessages("Manual trigger for sampling index " + userDescription + " [" + mode + "]");
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IndexSamplingMode (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode)5 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)1 Statement (org.neo4j.kernel.api.Statement)1 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)1 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)1 ShellException (org.neo4j.shell.ShellException)1