use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyChange.
private void onPropertyChange(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value beforeValue, Value afterValue) {
assert noSchemaChangedInTx();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
int[] propertyIds = schema.getPropertyIds();
Value[] valuesAfter = getValueTuple(entity, propertyCursor, propertyKeyId, afterValue, propertyIds, materializedProperties, memoryTracker);
// The valuesBefore tuple is just like valuesAfter, except is has the afterValue instead of the beforeValue
Value[] valuesBefore = Arrays.copyOf(valuesAfter, valuesAfter.length);
int k = ArrayUtils.indexOf(propertyIds, propertyKeyId);
valuesBefore[k] = beforeValue;
indexingService.validateBeforeCommit(index, valuesAfter, entity.reference());
ValueTuple valuesTupleBefore = ValueTuple.of(valuesBefore);
ValueTuple valuesTupleAfter = ValueTuple.of(valuesAfter);
// They are copies and same shallow size
memoryTracker.allocateHeap(valuesTupleBefore.getShallowSize() * 2);
read.txState().indexDoUpdateEntry(schema, entity.reference(), valuesTupleBefore, valuesTupleAfter);
});
}
}
use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyAdd.
private void onPropertyAdd(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value value) {
assert noSchemaChangedInTx();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
Value[] values = getValueTuple(entity, propertyCursor, propertyKeyId, value, schema.getPropertyIds(), materializedProperties, memoryTracker);
indexingService.validateBeforeCommit(index, values, entity.reference());
ValueTuple valueTuple = ValueTuple.of(values);
memoryTracker.allocateHeap(valueTuple.getShallowSize());
read.txState().indexDoUpdateEntry(schema, entity.reference(), null, valueTuple);
});
}
}
use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyRemove.
private void onPropertyRemove(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value value) {
assert noSchemaChangedInTx();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
Value[] values = getValueTuple(entity, propertyCursor, propertyKeyId, value, schema.getPropertyIds(), materializedProperties, memoryTracker);
ValueTuple valueTuple = ValueTuple.of(values);
memoryTracker.allocateHeap(valueTuple.getShallowSize());
read.txState().indexDoUpdateEntry(schema, entity.reference(), valueTuple, null);
});
}
}
use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.
the class IndexTxStateUpdater method onLabelChange.
/**
* A label has been changed, figure out what updates are needed to tx state.
*
* @param labelId The id of the changed label
* @param existingPropertyKeyIds all property key ids the node has, sorted by id
* @param node cursor to the node where the change was applied
* @param propertyCursor cursor to the properties of node
* @param changeType The type of change event
*/
void onLabelChange(int labelId, int[] existingPropertyKeyIds, NodeCursor node, PropertyCursor propertyCursor, LabelChangeType changeType) {
assert noSchemaChangedInTx();
// Check all indexes of the changed label
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(new long[] { labelId }, existingPropertyKeyIds, NODE);
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
for (IndexDescriptor index : indexes) {
MemoryTracker memoryTracker = read.txState().memoryTracker();
int[] indexPropertyIds = index.schema().getPropertyIds();
Value[] values = getValueTuple(new NodeCursorWrapper(node), propertyCursor, NO_SUCH_PROPERTY_KEY, NO_VALUE, indexPropertyIds, materializedProperties, memoryTracker);
ValueTuple valueTuple = ValueTuple.of(values);
memoryTracker.allocateHeap(valueTuple.getShallowSize());
switch(changeType) {
case ADDED_LABEL:
indexingService.validateBeforeCommit(index, values, node.nodeReference());
read.txState().indexDoUpdateEntry(index.schema(), node.nodeReference(), null, valueTuple);
break;
case REMOVED_LABEL:
read.txState().indexDoUpdateEntry(index.schema(), node.nodeReference(), valueTuple, null);
break;
default:
throw new IllegalStateException(changeType + " is not a supported event");
}
}
}
}
use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method testExactMatchOnRandomCompositeValues.
@Test
public void testExactMatchOnRandomCompositeValues() throws Exception {
// given
ValueType[] types = randomSetOfSupportedTypes();
List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
Set<ValueTuple> duplicateChecker = new HashSet<>();
for (long id = 0; id < 10_000; id++) {
ValueIndexEntryUpdate<SchemaDescriptor> update;
do {
update = add(id, descriptor.schema(), random.randomValues().nextValueOfTypes(types), random.randomValues().nextValueOfTypes(types));
} while (!duplicateChecker.add(ValueTuple.of(update.values())));
updates.add(update);
}
updateAndCommit(updates);
// when
InMemoryTokens tokenNameLookup = new InMemoryTokens();
for (ValueIndexEntryUpdate<?> update : updates) {
// then
List<Long> hits = query(exact(0, update.values()[0]), exact(1, update.values()[1]));
assertEquals(update.describe(tokenNameLookup) + " " + hits, 1, hits.size());
assertThat(single(hits)).isEqualTo(update.getEntityId());
}
}
Aggregations