use of org.neo4j.storageengine.api.txstate.RelationshipState in project neo4j by neo4j.
the class TxStateTransactionDataSnapshot method takeSnapshot.
private void takeSnapshot() {
try {
for (long nodeId : state.addedAndRemovedNodes().getRemoved()) {
try (Cursor<NodeItem> node = storeStatement.acquireSingleNodeCursor(nodeId)) {
if (node.next()) {
Lock lock = node.get().lock();
try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(node.get().nextPropertyId(), lock)) {
while (properties.next()) {
removedNodeProperties.add(new NodePropertyEntryView(nodeId, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
}
}
node.get().labels().visitKeys(labelId -> {
removedLabels.add(new LabelEntryView(nodeId, store.labelGetName(labelId)));
return false;
});
}
}
}
for (long relId : state.addedAndRemovedRelationships().getRemoved()) {
Relationship relationshipProxy = relationship(relId);
try (Cursor<RelationshipItem> relationship = storeStatement.acquireSingleRelationshipCursor(relId)) {
if (relationship.next()) {
Lock lock = relationship.get().lock();
try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(relationship.get().nextPropertyId(), lock)) {
while (properties.next()) {
removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationshipProxy, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
}
}
}
}
}
for (NodeState nodeState : state.modifiedNodes()) {
Iterator<StorageProperty> added = nodeState.addedAndChangedProperties();
while (added.hasNext()) {
DefinedProperty property = (DefinedProperty) added.next();
assignedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(nodeState, property.propertyKeyId())));
}
Iterator<Integer> removed = nodeState.removedProperties();
while (removed.hasNext()) {
Integer property = removed.next();
removedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property), null, committedValue(nodeState, property)));
}
ReadableDiffSets<Integer> labels = nodeState.labelDiffSets();
for (Integer label : labels.getAdded()) {
assignedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
}
for (Integer label : labels.getRemoved()) {
removedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
}
}
for (RelationshipState relState : state.modifiedRelationships()) {
Relationship relationship = relationship(relState.getId());
Iterator<StorageProperty> added = relState.addedAndChangedProperties();
while (added.hasNext()) {
DefinedProperty property = (DefinedProperty) added.next();
assignedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(relState, property.propertyKeyId())));
}
Iterator<Integer> removed = relState.removedProperties();
while (removed.hasNext()) {
Integer property = removed.next();
removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property), null, committedValue(relState, property)));
}
}
} catch (PropertyKeyIdNotFoundKernelException | LabelNotFoundKernelException e) {
throw new IllegalStateException("An entity that does not exist was modified.", e);
}
}
use of org.neo4j.storageengine.api.txstate.RelationshipState in project neo4j by neo4j.
the class TxState method accept.
@Override
public void accept(final TxStateVisitor visitor) throws KernelException {
if (nodes != null) {
nodes.getAdded().each(visitor::visitCreatedNode);
}
if (relationships != null) {
try (HeapTrackingArrayList<NodeRelationshipIds> sortedNodeRelState = HeapTrackingArrayList.newArrayList(nodeStatesMap.size(), memoryTracker)) {
nodeStatesMap.forEachValue(nodeState -> {
if (nodeState.isDeleted() && nodeState.isAddedInThisTx()) {
return;
}
if (nodeState.hasAddedRelationships() || nodeState.hasRemovedRelationships()) {
sortedNodeRelState.add(StateNodeRelationshipIds.createStateNodeRelationshipIds(nodeState, this::relationshipVisit, memoryTracker));
}
});
sortedNodeRelState.sort(Comparator.comparingLong(NodeRelationshipIds::nodeId));
// Visit relationships, this will grab all the locks needed to do the updates
visitor.visitRelationshipModifications(new RelationshipModifications() {
@Override
public void forEachSplit(IdsVisitor visitor) {
sortedNodeRelState.forEach(visitor);
}
@Override
public RelationshipBatch creations() {
return idsAsBatch(relationships.getAdded(), TxState.this::relationshipVisit);
}
@Override
public RelationshipBatch deletions() {
return idsAsBatch(relationships.getRemoved());
}
});
}
}
if (nodes != null) {
nodes.getRemoved().each(visitor::visitDeletedNode);
}
for (NodeState node : modifiedNodes()) {
if (node.hasPropertyChanges()) {
visitor.visitNodePropertyChanges(node.getId(), node.addedProperties(), node.changedProperties(), node.removedProperties());
}
final LongDiffSets labelDiffSets = node.labelDiffSets();
if (!labelDiffSets.isEmpty()) {
visitor.visitNodeLabelChanges(node.getId(), labelDiffSets.getAdded(), labelDiffSets.getRemoved());
}
}
for (RelationshipState rel : modifiedRelationships()) {
visitor.visitRelPropertyChanges(rel.getId(), rel.addedProperties(), rel.changedProperties(), rel.removedProperties());
}
if (indexChanges != null) {
for (IndexDescriptor indexDescriptor : indexChanges.getAdded()) {
visitor.visitAddedIndex(indexDescriptor);
}
indexChanges.getRemoved().forEach(visitor::visitRemovedIndex);
}
if (constraintsChanges != null) {
for (ConstraintDescriptor added : constraintsChanges.getAdded()) {
visitor.visitAddedConstraint(added);
}
constraintsChanges.getRemoved().forEach(visitor::visitRemovedConstraint);
}
if (createdLabelTokens != null) {
createdLabelTokens.forEachKeyValue((id, token) -> visitor.visitCreatedLabelToken(id, token.name, token.internal));
}
if (createdPropertyKeyTokens != null) {
createdPropertyKeyTokens.forEachKeyValue((id, token) -> visitor.visitCreatedPropertyKeyToken(id, token.name, token.internal));
}
if (createdRelationshipTypeTokens != null) {
createdRelationshipTypeTokens.forEachKeyValue((id, token) -> visitor.visitCreatedRelationshipTypeToken(id, token.name, token.internal));
}
}
use of org.neo4j.storageengine.api.txstate.RelationshipState in project neo4j by neo4j.
the class TxStateTransactionDataSnapshot method snapshotModifiedRelationships.
private void snapshotModifiedRelationships(MemoryTracker memoryTracker, StoragePropertyCursor properties, TokenRead tokenRead) throws PropertyKeyIdNotFoundKernelException {
for (RelationshipState relState : state.modifiedRelationships()) {
Relationship relationship = relationship(relState.getId());
Iterator<StorageProperty> added = relState.addedAndChangedProperties();
while (added.hasNext()) {
StorageProperty property = added.next();
assignedRelationshipProperties.add(createRelationshipPropertyEntryView(memoryTracker, tokenRead, relationship, property.propertyKeyId(), property.value(), committedValue(relState, property.propertyKeyId(), this.relationship, properties)));
}
relState.removedProperties().each(id -> {
try {
var entryView = createRelationshipPropertyEntryView(memoryTracker, tokenRead, relationship, id, null, committedValue(relState, id, this.relationship, properties));
removedRelationshipProperties.add(entryView);
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Not existing properties was modified for relationship " + relState.getId(), e);
}
});
}
}
Aggregations