use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class SimpleIndexAccessorCompatibility method testIndexRangeSeek.
private void testIndexRangeSeek(Supplier<? extends Value> generator) throws Exception {
int count = random.nextInt(5, 10);
List<Value> values = new ArrayList<>();
List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
Set<Value> duplicateCheck = new HashSet<>();
for (int i = 0; i < count; i++) {
Value value;
do {
value = generator.get();
} while (!duplicateCheck.add(value));
values.add(value);
}
values.sort(Values.COMPARATOR);
for (int i = 0; i < count; i++) {
updates.add(add(i + 1, descriptor.schema(), values.get(i)));
}
// <- Don't rely on insert order
Collections.shuffle(updates);
updateAndCommit(updates);
for (int f = 0; f < values.size(); f++) {
for (int t = f; t < values.size(); t++) {
Value from = values.get(f);
Value to = values.get(t);
for (boolean fromInclusive : new boolean[] { true, false }) {
for (boolean toInclusive : new boolean[] { true, false }) {
assertThat(query(range(1, from, fromInclusive, to, toInclusive))).isEqualTo(ids(f, fromInclusive, t, toInclusive));
}
}
}
}
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class SimpleIndexPopulatorCompatibility method shouldPopulateAndUpdate.
@Test
public void shouldPopulateAndUpdate() throws Exception {
// GIVEN
withPopulator(indexProvider.getPopulator(descriptor, indexSamplingConfig, heapBufferFactory(1024), INSTANCE, tokenNameLookup), p -> p.add(updates(valueSet1), NULL));
try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, indexSamplingConfig, tokenNameLookup)) {
// WHEN
try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
List<ValueIndexEntryUpdate<?>> updates = updates(valueSet2);
for (ValueIndexEntryUpdate<?> update : updates) {
updater.process(update);
}
}
// THEN
try (ValueIndexReader reader = accessor.newValueReader()) {
int propertyKeyId = descriptor.schema().getPropertyId();
for (NodeAndValue entry : Iterables.concat(valueSet1, valueSet2)) {
try (NodeValueIterator nodes = new NodeValueIterator()) {
reader.query(NULL_CONTEXT, nodes, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, entry.value));
assertEquals(entry.nodeId, nodes.next());
assertFalse(nodes.hasNext());
}
}
}
}
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class BlockBasedIndexPopulator method newPopulatingUpdater.
@Override
public IndexUpdater newPopulatingUpdater(CursorContext cursorContext) {
if (scanCompleted) {
// Will need the reader from newReader, which a sub-class of this class implements
return new DelegatingIndexUpdater(super.newPopulatingUpdater(cursorContext)) {
@Override
public void process(IndexEntryUpdate<?> update) throws IndexEntryConflictException {
ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
validateUpdate(valueUpdate);
numberOfIndexUpdatesSinceSample.incrementAndGet();
super.process(valueUpdate);
}
};
}
return new IndexUpdater() {
private volatile boolean closed;
@Override
public void process(IndexEntryUpdate<?> update) {
assertOpen();
ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
try {
validateUpdate(valueUpdate);
externalUpdates.add(valueUpdate);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public void close() {
closed = true;
}
private void assertOpen() {
if (closed) {
throw new IllegalStateException("Updater has been closed");
}
}
};
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodesThatAreNotIndexed.
@ParameterizedTest
@EnumSource(IndexSize.class)
void shouldReportNodesThatAreNotIndexed(IndexSize indexSize) throws Exception {
indexSize.createAdditionalData(fixture);
// given
Iterator<IndexDescriptor> indexDescriptorIterator = getValueIndexDescriptors();
while (indexDescriptorIterator.hasNext()) {
IndexDescriptor indexDescriptor = indexDescriptorIterator.next();
IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexDescriptor);
try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
for (long nodeId : indexedNodes) {
EntityUpdates updates = fixture.nodeAsUpdates(nodeId);
for (IndexEntryUpdate<?> update : updates.valueUpdatesForIndexKeys(singletonList(indexDescriptor))) {
updater.process(IndexEntryUpdate.remove(nodeId, indexDescriptor, ((ValueIndexEntryUpdate<?>) update).values()));
}
}
}
}
// when
ConsistencySummaryStatistics stats = check();
// then
// 1 node missing from 1 index + 1 node missing from 2 indexes
on(stats).verify(RecordType.NODE, 3).andThatsAllFolks();
}
use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.
the class IndexUpdateStorage method add.
@Override
public void add(IndexEntryUpdate<?> update, PageCursor pageCursor) throws IOException {
ValueIndexEntryUpdate<?> valueUpdate = (ValueIndexEntryUpdate<?>) update;
int entrySize = TYPE_SIZE;
UpdateMode updateMode = valueUpdate.updateMode();
switch(updateMode) {
case ADDED:
initializeKeyAndValueFromUpdate(key1, value, valueUpdate.getEntityId(), valueUpdate.values());
entrySize += BlockEntry.entrySize(layout, key1, value);
break;
case REMOVED:
initializeKeyFromUpdate(key1, valueUpdate.getEntityId(), valueUpdate.values());
entrySize += BlockEntry.keySize(layout, key1);
break;
case CHANGED:
initializeKeyFromUpdate(key1, valueUpdate.getEntityId(), valueUpdate.beforeValues());
initializeKeyAndValueFromUpdate(key2, value, valueUpdate.getEntityId(), valueUpdate.values());
entrySize += BlockEntry.keySize(layout, key1) + BlockEntry.entrySize(layout, key2, value);
break;
default:
throw new IllegalArgumentException("Unknown update mode " + updateMode);
}
prepareWrite(entrySize);
pageCursor.putByte((byte) updateMode.ordinal());
IndexUpdateEntry.write(pageCursor, layout, updateMode, key1, key2, value);
}
Aggregations