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)));
}
}
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();
}
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()));
}
}
Aggregations