Search in sources :

Example 46 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class NonUniqueLuceneIndexPopulatingUpdaterIT method shouldSampleAdditions.

@Test
void shouldSampleAdditions() throws Exception {
    // Given
    var provider = createIndexProvider();
    var populator = getPopulator(provider, SCHEMA_DESCRIPTOR);
    // When
    try (var updater = populator.newPopulatingUpdater(mock(NodePropertyAccessor.class), NULL)) {
        updater.process(add(1, SCHEMA_DESCRIPTOR, "foo"));
        updater.process(add(2, SCHEMA_DESCRIPTOR, "bar"));
        updater.process(add(3, SCHEMA_DESCRIPTOR, "baz"));
        updater.process(add(4, SCHEMA_DESCRIPTOR, "bar"));
    }
    // Then
    assertThat(populator.sample(NULL)).isEqualTo(new IndexSample(4, 3, 4));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) Test(org.junit.jupiter.api.Test)

Example 47 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class UniqueDatabaseIndexPopulatorTest method sampleEmptyIndex.

@Test
void sampleEmptyIndex() {
    populator = newPopulator();
    IndexSample sample = populator.sample(NULL);
    assertEquals(new IndexSample(), sample);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 48 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class IndexRecoveryIT method shouldBeAbleToRecoverAndUpdateOnlineIndex.

@Test
void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception {
    // Given
    startDb();
    IndexPopulator populator = mock(IndexPopulator.class);
    when(mockedIndexProvider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(populator);
    when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
    IndexAccessor mockedAccessor = mock(IndexAccessor.class);
    when(mockedAccessor.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(SwallowingIndexUpdater.INSTANCE);
    when(mockedIndexProvider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(mockedAccessor);
    createIndexAndAwaitPopulation(myLabel);
    // rotate logs
    rotateLogsAndCheckPoint();
    // make updates
    Set<IndexEntryUpdate<?>> expectedUpdates = createSomeBananas(myLabel);
    // And Given
    killDb();
    when(mockedIndexProvider.getInitialState(any(IndexDescriptor.class), any(CursorContext.class))).thenReturn(ONLINE);
    GatheringIndexWriter writer = new GatheringIndexWriter();
    when(mockedIndexProvider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(writer);
    // When
    startDb();
    // Then
    try (Transaction transaction = db.beginTx()) {
        assertThat(transaction.schema().getIndexes(myLabel)).hasSize(1);
        assertThat(transaction.schema().getIndexes(myLabel)).extracting(i -> transaction.schema().getIndexState(i)).containsOnly(Schema.IndexState.ONLINE);
    }
    verify(mockedIndexProvider).getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
    // once when we create the index, and once when we restart the db
    int onlineAccessorInvocationCount = 3;
    verify(mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class));
    assertEquals(expectedUpdates, writer.batchedUpdates);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SchemaIndexTestHelper.singleInstanceIndexProviderFactory(org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.singleInstanceIndexProviderFactory) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Future(java.util.concurrent.Future) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Monitors(org.neo4j.monitoring.Monitors) Arrays.asList(java.util.Arrays.asList) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) RecoveryMonitor(org.neo4j.kernel.recovery.RecoveryMonitor) PageCache(org.neo4j.io.pagecache.PageCache) TokenIndexProviderFactory(org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory) Recovery(org.neo4j.kernel.recovery.Recovery) Set(java.util.Set) FileUtils(org.neo4j.io.fs.FileUtils) TestDirectory(org.neo4j.test.rule.TestDirectory) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Schema(org.neo4j.graphdb.schema.Schema) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) GraphDatabaseSettings.default_schema_provider(org.neo4j.configuration.GraphDatabaseSettings.default_schema_provider) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) PROVIDER_DESCRIPTOR(org.neo4j.kernel.impl.api.index.TestIndexProviderDescriptor.PROVIDER_DESCRIPTOR) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CollectingIndexUpdater(org.neo4j.kernel.impl.index.schema.CollectingIndexUpdater) Label(org.neo4j.graphdb.Label) Config.defaults(org.neo4j.configuration.Config.defaults) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) MINUTES(java.util.concurrent.TimeUnit.MINUTES) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Node(org.neo4j.graphdb.Node) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Inject(org.neo4j.test.extension.Inject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ONLINE(org.neo4j.internal.kernel.api.InternalIndexState.ONLINE) ExecutorService(java.util.concurrent.ExecutorService) IndexSample(org.neo4j.kernel.api.index.IndexSample) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) LogAppendEvent(org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) Mockito.when(org.mockito.Mockito.when) Label.label(org.neo4j.graphdb.Label.label) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) AfterEach(org.junit.jupiter.api.AfterEach) ExtensionFactory(org.neo4j.kernel.extension.ExtensionFactory) Mockito.never(org.mockito.Mockito.never) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexSample(org.neo4j.kernel.api.index.IndexSample) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.jupiter.api.Test)

Example 49 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class ControlledPopulationIndexProvider method installPopulationJobCompletionLatch.

public DoubleLatch installPopulationJobCompletionLatch() {
    final DoubleLatch populationCompletionLatch = new DoubleLatch();
    mockedPopulator = new IndexPopulator.Adapter() {

        @Override
        public void create() {
            populationCompletionLatch.startAndWaitForAllToStartAndFinish();
            super.create();
        }

        @Override
        public IndexSample sample(CursorContext cursorContext) {
            return new IndexSample();
        }
    };
    return populationCompletionLatch;
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSample(org.neo4j.kernel.api.index.IndexSample) DoubleLatch(org.neo4j.test.DoubleLatch) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 50 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class FusionIndexSampler method sampleIndex.

@Override
public IndexSample sampleIndex(CursorContext cursorContext) throws IndexNotFoundKernelException {
    List<IndexSample> samples = new ArrayList<>();
    Exception exception = null;
    for (IndexSampler sampler : samplers) {
        try {
            samples.add(sampler.sampleIndex(cursorContext));
        } catch (IndexNotFoundKernelException | RuntimeException e) {
            exception = Exceptions.chain(exception, e);
        }
    }
    if (exception != null) {
        throwIfUnchecked(exception);
        throwIfInstanceOf(exception, IndexNotFoundKernelException.class);
        throw new RuntimeException(exception);
    }
    return combineSamples(samples);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) ArrayList(java.util.ArrayList) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexSampler(org.neo4j.kernel.api.index.IndexSampler)

Aggregations

IndexSample (org.neo4j.kernel.api.index.IndexSample)56 Test (org.junit.jupiter.api.Test)43 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)14 CursorContext (org.neo4j.io.pagecache.context.CursorContext)13 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)8 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)8 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)8 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)7 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)7 ArrayList (java.util.ArrayList)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Config (org.neo4j.configuration.Config)6 Transaction (org.neo4j.graphdb.Transaction)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 Arrays.asList (java.util.Arrays.asList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4