Search in sources :

Example 11 with IndexAccessor

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

the class NonUniqueIndexTests method nodeIdsInIndex.

private List<Long> nodeIdsInIndex(int indexId, String value) throws Exception {
    Config config = Config.empty();
    SchemaIndexProvider indexProvider = new LuceneSchemaIndexProvider(fileSystemRule.get(), DirectoryFactory.PERSISTENT, directory.graphDbDir(), NullLogProvider.getInstance(), Config.empty(), OperationalMode.single);
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(config);
    try (IndexAccessor accessor = indexProvider.getOnlineAccessor(indexId, NewIndexDescriptorFactory.forLabel(0, 0), samplingConfig);
        IndexReader reader = accessor.newReader()) {
        return PrimitiveLongCollections.asList(reader.query(IndexQuery.exact(1, value)));
    }
}
Also used : LuceneSchemaIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) LuceneSchemaIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) Config(org.neo4j.kernel.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexReader(org.neo4j.storageengine.api.schema.IndexReader)

Example 12 with IndexAccessor

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

the class LuceneSchemaIndexProviderTest method shouldCreateReadOnlyAccessorInReadOnlyMode.

@Test
public void shouldCreateReadOnlyAccessorInReadOnlyMode() throws Exception {
    DirectoryFactory directoryFactory = DirectoryFactory.PERSISTENT;
    createEmptySchemaIndex(directoryFactory);
    Config readOnlyConfig = Config.embeddedDefaults(stringMap(GraphDatabaseSettings.read_only.name(), Settings.TRUE));
    LuceneSchemaIndexProvider readOnlyIndexProvider = getLuceneSchemaIndexProvider(readOnlyConfig, directoryFactory, fs, graphDbDir);
    IndexAccessor onlineAccessor = getIndexAccessor(readOnlyConfig, readOnlyIndexProvider);
    expectedException.expect(UnsupportedOperationException.class);
    onlineAccessor.drop();
}
Also used : Config(org.neo4j.kernel.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) Test(org.junit.Test)

Example 13 with IndexAccessor

use of org.neo4j.kernel.api.index.IndexAccessor 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)

Aggregations

IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)13 Test (org.junit.Test)8 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)7 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)5 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)3 Config (org.neo4j.kernel.configuration.Config)3 DoubleLongRegister (org.neo4j.register.Register.DoubleLongRegister)3 Registers.newDoubleLongRegister (org.neo4j.register.Registers.newDoubleLongRegister)3 File (java.io.File)2 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)2 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Iterators.asCollection (org.neo4j.helpers.collection.Iterators.asCollection)1 DirectoryFactory (org.neo4j.kernel.api.impl.index.storage.DirectoryFactory)1