use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class GenericAccessorPointsTest method exactMatchOnAllValues.
private void exactMatchOnAllValues(List<Value> values) throws IndexNotApplicableKernelException {
try (var indexReader = accessor.newValueReader()) {
SimpleEntityValueClient client = new SimpleEntityValueClient();
for (Value value : values) {
PropertyIndexQuery.ExactPredicate exact = PropertyIndexQuery.exact(descriptor.schema().getPropertyId(), value);
indexReader.query(QueryContext.NULL_CONTEXT, client, unorderedValues(), exact);
// then
assertTrue(client.next());
assertEquals(value, client.values[0]);
assertFalse(client.next());
}
}
}
use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class GenericAccessorPointsTest method shouldNotGetFalsePositivesForRangesSpanningMultipleTiles.
/**
* Given how the spatial index works, if a point is on a tile that intersect with the search area,
* but the point itself is outside the search area, it is a candidate for a false positive.
* The reason is that such a point is returned from the index itself,
* because a space index compares (and generally works with) only values of a space-filling curve
* and not the points themselves.
* Therefore {@link IndexReader} implementation must post-process raw index results and filter out such false positives.
*/
@Test
void shouldNotGetFalsePositivesForRangesSpanningMultipleTiles() throws IndexNotApplicableKernelException, IndexEntryConflictException {
PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
double[] searchStart = curve.centerPointFor(derivedValueForCenterPoint);
double xTileWidth = curve.getTileWidth(0, curve.getMaxLevel());
// to make it easier to imagine this, the search start is a center point of one tile and the limit is a center point of the next tile on the x-axis
PointValue limitPoint = Values.pointValue(WGS84, searchStart[0] + xTileWidth, searchStart[1]);
int nbrOfValues = 10_000;
List<PointValue> pointsInside = new ArrayList<>();
List<IndexEntryUpdate<?>> updates = new ArrayList<>();
for (int i = 0; i < nbrOfValues; i++) {
double distanceMultiplier = random.nextDouble() * 2;
PointValue point = Values.pointValue(WGS84, searchStart[0] + distanceMultiplier * xTileWidth, searchStart[1]);
updates.add(IndexEntryUpdate.add(0, descriptor, point));
if (distanceMultiplier <= 1) {
pointsInside.add(point);
}
}
processAll(updates);
try (var indexReader = accessor.newValueReader()) {
SimpleEntityValueClient client = new SimpleEntityValueClient();
var range = PropertyIndexQuery.range(descriptor.schema().getPropertyId(), Values.pointValue(WGS84, searchStart), true, limitPoint, true);
indexReader.query(QueryContext.NULL_CONTEXT, client, unorderedValues(), range);
List<Value> queryResult = new ArrayList<>();
while (client.next()) {
queryResult.add(client.values[0]);
}
assertThat(queryResult).containsExactlyInAnyOrderElementsOf(pointsInside);
}
}
use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class GenericBlockBasedIndexPopulatorTest method assertHasEntry.
private static void assertHasEntry(BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator, Value entry, int expectedId) {
try (NativeIndexReader<GenericKey, NativeIndexValue> reader = populator.newReader()) {
SimpleEntityValueClient valueClient = new SimpleEntityValueClient();
PropertyIndexQuery.ExactPredicate exact = PropertyIndexQuery.exact(INDEX_DESCRIPTOR.schema().getPropertyId(), entry);
reader.query(NULL_CONTEXT, valueClient, unconstrained(), exact);
assertTrue(valueClient.next());
long id = valueClient.reference;
assertEquals(expectedId, id);
}
}
use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class GenericBlockBasedIndexPopulatorTest method assertMatch.
private static void assertMatch(BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator, Value value, long id) {
try (NativeIndexReader<GenericKey, NativeIndexValue> reader = populator.newReader()) {
SimpleEntityValueClient cursor = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, cursor, unorderedValues(), PropertyIndexQuery.exact(INDEX_DESCRIPTOR.schema().getPropertyId(), value));
assertTrue(cursor.next());
assertEquals(id, cursor.reference);
assertEquals(value, cursor.values[0]);
assertFalse(cursor.next());
}
}
use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class IndexPopulationStressTest method stressIt.
@Test
void stressIt() throws Throwable {
Race race = new Race();
AtomicReferenceArray<List<ValueIndexEntryUpdate<?>>> lastBatches = new AtomicReferenceArray<>(THREADS);
Generator[] generators = new Generator[THREADS];
populator.create();
CountDownLatch insertersDone = new CountDownLatch(THREADS);
ReadWriteLock updateLock = new ReentrantReadWriteLock(true);
for (int i = 0; i < THREADS; i++) {
race.addContestant(inserter(lastBatches, generators, insertersDone, updateLock, i), 1);
}
Collection<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
race.addContestant(updater(lastBatches, insertersDone, updateLock, updates));
race.go();
populator.close(true, NULL);
// to let the after-method know that we've closed it ourselves
populator = null;
// then assert that a tree built by a single thread ends up exactly the same
buildReferencePopulatorSingleThreaded(generators, updates);
try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, samplingConfig, tokenNameLookup);
IndexAccessor referenceAccessor = indexProvider.getOnlineAccessor(descriptor2, samplingConfig, tokenNameLookup);
var reader = accessor.newValueReader();
var referenceReader = referenceAccessor.newValueReader()) {
SimpleEntityValueClient entries = new SimpleEntityValueClient();
SimpleEntityValueClient referenceEntries = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, entries, unordered(hasValues), PropertyIndexQuery.exists(0));
referenceReader.query(NULL_CONTEXT, referenceEntries, unordered(hasValues), PropertyIndexQuery.exists(0));
while (referenceEntries.next()) {
assertTrue(entries.next());
assertEquals(referenceEntries.reference, entries.reference);
if (hasValues) {
assertEquals(ValueTuple.of(referenceEntries.values), ValueTuple.of(entries.values));
}
}
assertFalse(entries.next());
}
}
Aggregations