use of org.neo4j.storageengine.api.ValueIndexEntryUpdate 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());
}
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class NativeIndexAccessorTests method shouldIndexAdd.
@Test
void shouldIndexAdd() throws Exception {
// given
ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
// when
processAll(updater, updates);
}
// then
forceAndCloseAccessor();
valueUtil.verifyUpdates(updates, this::getTree);
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class NativeIndexAccessorTests method shouldHandleMultipleConsecutiveUpdaters.
@Test
void shouldHandleMultipleConsecutiveUpdaters() throws Exception {
// given
ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
// when
for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
updater.process(update);
}
}
// then
forceAndCloseAccessor();
valueUtil.verifyUpdates(updates, this::getTree);
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class NativeIndexAccessorTests method respectIndexOrder.
@Test
void respectIndexOrder() throws Exception {
// given
int nUpdates = 10000;
ValueType[] types = supportedTypesExcludingNonOrderable();
Iterator<ValueIndexEntryUpdate<IndexDescriptor>> randomUpdateGenerator = valueCreatorUtil.randomUpdateGenerator(random, types);
// noinspection unchecked
ValueIndexEntryUpdate<IndexDescriptor>[] someUpdates = new ValueIndexEntryUpdate[nUpdates];
for (int i = 0; i < nUpdates; i++) {
someUpdates[i] = randomUpdateGenerator.next();
}
processAll(someUpdates);
Value[] allValues = ValueCreatorUtil.extractValuesFromUpdates(someUpdates);
// when
try (var reader = accessor.newValueReader()) {
ValueGroup valueGroup = random.among(allValues).valueGroup();
PropertyIndexQuery.RangePredicate<?> supportedQuery = PropertyIndexQuery.range(0, valueGroup);
IndexOrderCapability supportedOrders = indexCapability().orderCapability(valueGroup.category());
if (supportedOrders.supportsAsc()) {
expectIndexOrder(allValues, valueGroup, reader, IndexOrder.ASCENDING, supportedQuery);
}
if (supportedOrders.supportsDesc()) {
expectIndexOrder(allValues, valueGroup, reader, IndexOrder.DESCENDING, supportedQuery);
}
}
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class NativeIndexAccessorTests method getValues.
@Test
void getValues() throws IndexEntryConflictException, IndexNotApplicableKernelException {
// given
int nUpdates = 10000;
Iterator<ValueIndexEntryUpdate<IndexDescriptor>> randomUpdateGenerator = valueCreatorUtil.randomUpdateGenerator(random);
// noinspection unchecked
ValueIndexEntryUpdate<IndexDescriptor>[] someUpdates = new ValueIndexEntryUpdate[nUpdates];
for (int i = 0; i < nUpdates; i++) {
someUpdates[i] = randomUpdateGenerator.next();
}
processAll(someUpdates);
Value[] allValues = ValueCreatorUtil.extractValuesFromUpdates(someUpdates);
// Pick one out of all added values and do a range query for the value group of that value
Value value = random.among(allValues);
ValueGroup valueGroup = value.valueGroup();
IndexValueCapability valueCapability = indexCapability().valueCapability(valueGroup.category());
if (!valueCapability.equals(IndexValueCapability.YES)) {
// We don't need to do this test
return;
}
PropertyIndexQuery.RangePredicate<?> supportedQuery;
List<Value> expectedValues;
if (Values.isGeometryValue(value)) {
// Unless it's a point value in which case we query for the specific coordinate reference system instead
CoordinateReferenceSystem crs = ((PointValue) value).getCoordinateReferenceSystem();
supportedQuery = PropertyIndexQuery.range(0, crs);
expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == ValueGroup.GEOMETRY).filter(v -> ((PointValue) v).getCoordinateReferenceSystem() == crs).collect(Collectors.toList());
} else {
supportedQuery = PropertyIndexQuery.range(0, valueGroup);
expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).collect(Collectors.toList());
}
// when
try (var reader = accessor.newValueReader()) {
SimpleEntityValueClient client = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, client, unorderedValues(), supportedQuery);
// then
while (client.next()) {
Value foundValue = client.values[0];
assertTrue(expectedValues.remove(foundValue), "found value that was not expected " + foundValue);
}
assertThat(expectedValues.size()).as("did not find all expected values").isEqualTo(0);
}
}
Aggregations