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