Search in sources :

Example 16 with IndexSample

use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.

the class IndexRecoveryIT method shouldBeAbleToRecoverAndUpdateOnlineIndex.

@Test
public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception {
    // Given
    startDb();
    IndexPopulator populator = mock(IndexPopulator.class);
    when(mockedIndexProvider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    when(populator.sampleResult()).thenReturn(new IndexSample());
    IndexAccessor mockedAccessor = mock(IndexAccessor.class);
    when(mockedAccessor.newUpdater(any(IndexUpdateMode.class))).thenReturn(SwallowingIndexUpdater.INSTANCE);
    when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(mockedAccessor);
    createIndexAndAwaitPopulation(myLabel);
    // rotate logs
    rotateLogsAndCheckPoint();
    // make updates
    Set<IndexEntryUpdate> expectedUpdates = createSomeBananas(myLabel);
    // And Given
    killDb();
    when(mockedIndexProvider.getInitialState(anyLong(), any(NewIndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
    GatheringIndexWriter writer = new GatheringIndexWriter();
    when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(writer);
    // When
    startDb();
    // Then
    assertThat(getIndexes(db, myLabel), inTx(db, hasSize(1)));
    assertThat(getIndexes(db, myLabel), inTx(db, haveState(db, Schema.IndexState.ONLINE)));
    verify(mockedIndexProvider, times(1)).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    // once when we create the index, and once when we restart the db
    int onlineAccessorInvocationCount = 2;
    verify(mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    assertEquals(expectedUpdates, writer.batchedUpdates);
    for (IndexEntryUpdate update : writer.batchedUpdates) {
        assertTrue(writer.recoveredNodes.contains(update.getEntityId()));
    }
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Test(org.junit.Test)

Example 17 with IndexSample

use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.

the class UniqueDatabaseIndexSamplerTest method uniqueSamplingUseDocumentsNumber.

@Test
public void uniqueSamplingUseDocumentsNumber() throws IndexNotFoundKernelException {
    when(indexSearcher.getIndexReader().numDocs()).thenReturn(17);
    UniqueLuceneIndexSampler sampler = new UniqueLuceneIndexSampler(indexSearcher, taskControl.newInstance());
    IndexSample sample = sampler.sampleIndex();
    assertEquals(17, sample.indexSize());
}
Also used : IndexSample(org.neo4j.storageengine.api.schema.IndexSample) Test(org.junit.Test)

Example 18 with IndexSample

use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.

the class NonUniqueDatabaseIndexSamplerTest method samplingOfLargeNumericValues.

@Test
public void samplingOfLargeNumericValues() throws Exception {
    try (RAMDirectory dir = new RAMDirectory();
        WritableIndexPartition indexPartition = new WritableIndexPartition(new File("testPartition"), dir, IndexWriterConfigs.standard())) {
        insertDocument(indexPartition, 1, Long.MAX_VALUE);
        insertDocument(indexPartition, 2, Integer.MAX_VALUE);
        indexPartition.maybeRefreshBlocking();
        try (PartitionSearcher searcher = indexPartition.acquireSearcher()) {
            NonUniqueLuceneIndexSampler sampler = new NonUniqueLuceneIndexSampler(searcher.getIndexSearcher(), taskControl.newInstance(), new IndexSamplingConfig(Config.empty()));
            assertEquals(new IndexSample(2, 2, 2), sampler.sampleIndex());
        }
    }
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) Test(org.junit.Test)

Example 19 with IndexSample

use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.

the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.

@Test
public void sampleIncludedUpdates() throws Exception {
    populator = newPopulator();
    List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, labelSchemaDescriptor, "aaa"), IndexEntryUpdate.add(2, labelSchemaDescriptor, "bbb"), IndexEntryUpdate.add(3, labelSchemaDescriptor, "ccc"));
    updates.forEach(populator::includeSample);
    IndexSample sample = populator.sampleResult();
    assertEquals(new IndexSample(3, 3, 3), sample);
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) Test(org.junit.Test)

Example 20 with IndexSample

use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.

the class NonUniqueDatabaseIndexPopulatorTest method sampleEmptyIndex.

@Test
public void sampleEmptyIndex() throws IOException {
    populator = newPopulator();
    IndexSample sample = populator.sampleResult();
    assertEquals(new IndexSample(), sample);
}
Also used : IndexSample(org.neo4j.storageengine.api.schema.IndexSample) Test(org.junit.Test)

Aggregations

IndexSample (org.neo4j.storageengine.api.schema.IndexSample)21 Test (org.junit.Test)12 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)4 Before (org.junit.Before)2 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 File (java.io.File)1 IOException (java.io.IOException)1 Terms (org.apache.lucene.index.Terms)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)1 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)1 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)1 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)1 LuceneIndexAccessor (org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor)1 SchemaIndex (org.neo4j.kernel.api.impl.schema.SchemaIndex)1 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)1