use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class IndexSamplingControllerFactory method createIndexRecoveryCondition.
private RecoveryCondition createIndexRecoveryCondition(final LogProvider logProvider, final TokenNameLookup tokenNameLookup) {
return new RecoveryCondition() {
private final Log log = logProvider.getLog(IndexSamplingController.class);
@Override
public boolean test(IndexDescriptor descriptor) {
IndexSample indexSample = indexStatisticsStore.indexSample(descriptor.getId());
long samples = indexSample.sampleSize();
long size = indexSample.indexSize();
boolean empty = (samples == 0) || (size == 0);
if (empty) {
log.debug("Recovering index sampling for index %s", descriptor.schema().userDescription(tokenNameLookup));
}
return empty;
}
};
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NativeIndexAccessorTests method shouldSampleIndex.
@Test
void shouldSampleIndex() throws Exception {
// given
ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
processAll(updates);
try (var reader = accessor.newValueReader();
IndexSampler sampler = reader.createSampler()) {
// when
IndexSample sample = sampler.sampleIndex(NULL);
// then
assertEquals(updates.length, sample.indexSize());
assertEquals(updates.length, sample.sampleSize());
assertEquals(countUniqueValues(updates), sample.uniqueValues());
}
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class FusionIndexProviderTest method mustCombineSamples.
@Test
void mustCombineSamples() {
// given
int sumIndexSize = 0;
int sumUniqueValues = 0;
int sumSampleSize = 0;
IndexSample[] samples = new IndexSample[providers.size()];
for (int i = 0; i < samples.length; i++) {
int indexSize = random.nextInt(0, 1_000_000);
int uniqueValues = random.nextInt(0, 1_000_000);
int sampleSize = random.nextInt(0, 1_000_000);
samples[i] = new IndexSample(indexSize, uniqueValues, sampleSize);
sumIndexSize += indexSize;
sumUniqueValues += uniqueValues;
sumSampleSize += sampleSize;
}
// when
IndexSample fusionSample = FusionIndexSampler.combineSamples(Arrays.asList(samples));
// then
assertEquals(sumIndexSize, fusionSample.indexSize());
assertEquals(sumUniqueValues, fusionSample.uniqueValues());
assertEquals(sumSampleSize, fusionSample.sampleSize());
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NativeNonUniqueIndexPopulatorTest method shouldSampleUpdatesIfConfiguredForOnlineSampling.
@Test
void shouldSampleUpdatesIfConfiguredForOnlineSampling() throws Exception {
// GIVEN
try {
populator.create();
ValueIndexEntryUpdate<IndexDescriptor>[] scanUpdates = valueCreatorUtil.someUpdates(random);
populator.add(asList(scanUpdates), NULL);
Iterator<ValueIndexEntryUpdate<IndexDescriptor>> generator = valueCreatorUtil.randomUpdateGenerator(random);
Value[] updates = new Value[5];
updates[0] = generator.next().values()[0];
updates[1] = generator.next().values()[0];
updates[2] = updates[1];
updates[3] = generator.next().values()[0];
updates[4] = updates[3];
try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
long nodeId = 1000;
for (Value value : updates) {
ValueIndexEntryUpdate<IndexDescriptor> update = valueCreatorUtil.add(nodeId++, value);
updater.process(update);
}
}
// WHEN
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
IndexSample sample = populator.sample(NULL);
// THEN
assertEquals(scanUpdates.length, sample.sampleSize());
assertEquals(countUniqueValues(scanUpdates), sample.uniqueValues());
assertEquals(scanUpdates.length, sample.indexSize());
assertEquals(updates.length, sample.updates());
} finally {
populator.close(true, NULL);
}
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NonUniqueLuceneIndexPopulatingUpdaterIT method shouldSampleUpdates.
@Test
void shouldSampleUpdates() 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, "initial1"));
updater.process(add(2, SCHEMA_DESCRIPTOR, "initial2"));
updater.process(add(3, SCHEMA_DESCRIPTOR, "new2"));
updater.process(change(1, SCHEMA_DESCRIPTOR, "initial1", "new1"));
updater.process(change(1, SCHEMA_DESCRIPTOR, "initial2", "new2"));
}
// Then samples calculated with documents pending merge
assertThat(populator.sample(NULL)).isEqualTo(new IndexSample(3, 4, 5));
}
Aggregations