Search in sources :

Example 6 with ValueTuple

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);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 7 with ValueTuple

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);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 8 with 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);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 9 with ValueTuple

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");
            }
        }
    }
}
Also used : ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 10 with ValueTuple

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());
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) InMemoryTokens(org.neo4j.test.InMemoryTokens) ValueType(org.neo4j.values.storable.ValueType) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) ValueTuple(org.neo4j.values.storable.ValueTuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ValueTuple (org.neo4j.values.storable.ValueTuple)16 Value (org.neo4j.values.storable.Value)11 LongDiffSets (org.neo4j.storageengine.api.txstate.LongDiffSets)8 Map (java.util.Map)7 NavigableMap (java.util.NavigableMap)7 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)7 UnmodifiableMap (org.eclipse.collections.impl.UnmodifiableMap)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 TextValue (org.neo4j.values.storable.TextValue)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)5 MemoryTracker (org.neo4j.memory.MemoryTracker)5 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)4 Test (org.junit.jupiter.api.Test)2 MutableLongDiffSets (org.neo4j.kernel.impl.util.diffsets.MutableLongDiffSets)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LongIterable (org.eclipse.collections.api.LongIterable)1 LongProcedure (org.eclipse.collections.api.block.procedure.primitive.LongProcedure)1 MutableList (org.eclipse.collections.api.list.MutableList)1