Search in sources :

Example 11 with LongDiffSets

use of org.neo4j.storageengine.api.txstate.LongDiffSets in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesForRangeSeek.

// RANGE SEEK
static AddedAndRemoved indexUpdatesForRangeSeek(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, PropertyIndexQuery.RangePredicate<?> predicate, IndexOrder indexOrder) {
    NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return EMPTY_ADDED_AND_REMOVED;
    }
    int size = descriptor.schema().getPropertyIds().length;
    RangeFilterValues rangeFilter = predicate == null ? RangeFilterValues.fromExists(size, equalityPrefix) : RangeFilterValues.fromRange(size, equalityPrefix, predicate);
    MutableLongList added = LongLists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    Map<ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(rangeFilter.lower, true, rangeFilter.upper, true);
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : inRange.entrySet()) {
        ValueTuple values = entry.getKey();
        Value rangeKey = values.valueAt(equalityPrefix.length);
        LongDiffSets diffForSpecificValue = entry.getValue();
        // Needs to manually filter for if lower or upper should be included
        // since we only wants to compare the first value of the key and not all of them for composite indexes
        boolean allowed = rangeFilter.allowedEntry(rangeKey, equalityPrefix.length);
        // The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
        if (allowed && (predicate == null || predicate.isRegularOrder() || predicate.acceptsValue(rangeKey))) {
            added.addAll(diffForSpecificValue.getAdded());
            removed.addAll(diffForSpecificValue.getRemoved());
        }
    }
    return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 12 with LongDiffSets

use of org.neo4j.storageengine.api.txstate.LongDiffSets in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesWithValuesForRangeSeekByPrefix.

static AddedWithValuesAndRemoved indexUpdatesWithValuesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, TextValue prefix, IndexOrder indexOrder) {
    NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
    }
    int keySize = descriptor.schema().getPropertyIds().length;
    ValueTuple floor = getCompositeValueTuple(keySize, equalityPrefix, prefix, true);
    ValueTuple maxString = getCompositeValueTuple(keySize, equalityPrefix, Values.MAX_STRING, false);
    MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
        ValueTuple key = entry.getKey();
        Value prefixKey = key.valueAt(equalityPrefix.length);
        // Needs to check type since the subMap might include non-TextValue for composite index
        if (prefixKey.valueGroup() == ValueGroup.TEXT && ((TextValue) prefixKey).startsWith(prefix)) {
            LongDiffSets diffSets = entry.getValue();
            Value[] values = key.getValues();
            diffSets.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, values)));
            removed.addAll(diffSets.getRemoved());
        } else {
            break;
        }
    }
    return new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 13 with LongDiffSets

use of org.neo4j.storageengine.api.txstate.LongDiffSets in project neo4j by neo4j.

the class TxState method nodeDoDelete.

@Override
public void nodeDoDelete(long nodeId) {
    nodes().remove(nodeId);
    if (nodeStatesMap != null) {
        // Previously this node state was removed completely and its state cleared. Was that to reduce memory footprint for large deletions?
        // We have changed this so that it still keeps the removed relationships for this node so that they can be handed to command creation
        // grouped by type and direction.
        NodeStateImpl nodeState = nodeStatesMap.get(nodeId);
        if (nodeState != null) {
            final LongDiffSets diff = nodeState.labelDiffSets();
            diff.getAdded().each(label -> getOrCreateLabelStateNodeDiffSets(label).remove(nodeId));
            nodeState.markAsDeleted();
        }
    }
    dataChanged();
}
Also used : TrackableDiffSets.newMutableLongDiffSets(org.neo4j.kernel.impl.util.diffsets.TrackableDiffSets.newMutableLongDiffSets) MutableLongDiffSets(org.neo4j.kernel.impl.util.diffsets.MutableLongDiffSets) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Aggregations

LongDiffSets (org.neo4j.storageengine.api.txstate.LongDiffSets)13 ValueTuple (org.neo4j.values.storable.ValueTuple)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 TextValue (org.neo4j.values.storable.TextValue)6 Value (org.neo4j.values.storable.Value)6 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)4 MutableLongDiffSets (org.neo4j.kernel.impl.util.diffsets.MutableLongDiffSets)4 TrackableDiffSets.newMutableLongDiffSets (org.neo4j.kernel.impl.util.diffsets.TrackableDiffSets.newMutableLongDiffSets)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 NodeState (org.neo4j.storageengine.api.txstate.NodeState)2 Collections (java.util.Collections)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 LongSet (org.eclipse.collections.api.set.primitive.LongSet)1 Lists (org.eclipse.collections.impl.factory.Lists)1 LongLists (org.eclipse.collections.impl.factory.primitive.LongLists)1