use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class BatchInsertTest method shouldRunConstraintPopulationJobAtShutdown.
@ParameterizedTest
@MethodSource("params")
void shouldRunConstraintPopulationJobAtShutdown(int denseNodeThreshold) throws Throwable {
// GIVEN
IndexPopulator populator = mock(IndexPopulator.class);
IndexProvider provider = mock(IndexProvider.class);
IndexAccessor accessor = mock(IndexAccessor.class);
when(provider.getProviderDescriptor()).thenReturn(DESCRIPTOR);
when(provider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(populator);
when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
when(provider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor);
when(provider.completeConfiguration(any(IndexDescriptor.class))).then(inv -> inv.getArgument(0));
BatchInserter inserter = newBatchInserterWithIndexProvider(singleInstanceIndexProviderFactory(KEY, provider), provider.getProviderDescriptor(), denseNodeThreshold);
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
// WHEN
inserter.shutdown();
// THEN
verify(provider).init();
verify(provider).start();
verify(provider).getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
verify(populator).create();
verify(populator).add(argThat(c -> c.contains(add(nodeId, internalUniqueIndex.schema(), Values.of("Jakewins")))), any(CursorContext.class));
verify(populator).verifyDeferredConstraints(any(NodePropertyAccessor.class));
verify(populator).close(eq(true), any());
verify(provider).stop();
verify(provider).shutdown();
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class FullScanNonUniqueIndexSampler method sample.
@Override
public IndexSample sample(CursorContext cursorContext) {
KEY lowest = layout.newKey();
lowest.initialize(Long.MIN_VALUE);
lowest.initValuesAsLowest();
KEY highest = layout.newKey();
highest.initialize(Long.MAX_VALUE);
highest.initValuesAsHighest();
KEY prev = layout.newKey();
try (Seeker<KEY, VALUE> seek = gbpTree.seek(lowest, highest, cursorContext)) {
long sampledValues = 0;
long uniqueValues = 0;
// Get the first one so that prev gets initialized
if (seek.next()) {
prev = layout.copyKey(seek.key(), prev);
sampledValues++;
uniqueValues++;
// Then do the rest
while (seek.next()) {
if (layout.compareValue(prev, seek.key()) != 0) {
uniqueValues++;
layout.copyKey(seek.key(), prev);
}
// else this is a duplicate of the previous one
sampledValues++;
}
}
return new IndexSample(sampledValues, uniqueValues, sampledValues);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.
@Test
void sampleIncludedUpdates() {
populator = newPopulator();
List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, labelSchemaDescriptor, "aaa"), add(2, labelSchemaDescriptor, "bbb"), add(3, labelSchemaDescriptor, "ccc"));
populator.add(updates, NULL);
IndexSample sample = populator.sample(NULL);
assertEquals(new IndexSample(3, 3, 3), sample);
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NonUniqueLuceneIndexPopulatingUpdaterIT method shouldSampleRemovals.
@Test
void shouldSampleRemovals() 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, "qux"));
updater.process(remove(1, SCHEMA_DESCRIPTOR, "foo"));
updater.process(remove(2, SCHEMA_DESCRIPTOR, "bar"));
updater.process(remove(4, SCHEMA_DESCRIPTOR, "qux"));
}
// Then samples calculated with documents pending merge
assertThat(populator.sample(NULL)).isEqualTo(new IndexSample(1, 4, 4));
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NonUniqueLuceneIndexPopulatingUpdaterIT method shouldSampleCompositeIndex.
@Test
void shouldSampleCompositeIndex() throws Exception {
// Given
var provider = createIndexProvider();
var populator = getPopulator(provider, COMPOSITE_SCHEMA_DESCRIPTOR);
// When
try (var updater = populator.newPopulatingUpdater(mock(NodePropertyAccessor.class), NULL)) {
updater.process(add(1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "foo"));
updater.process(add(2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar"));
updater.process(add(3, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "baz"));
updater.process(add(4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux"));
updater.process(remove(1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "foo"));
updater.process(remove(2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar"));
updater.process(change(3, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[] { "bit", "baz" }, new Object[] { "foo", "bar" }));
}
// Then samples calculated with documents pending merge
assertThat(populator.sample(NULL)).isEqualTo(new IndexSample(2, 5, 10));
}
Aggregations