forked from JanusGraph/janusgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes: relations cannot be removed after update
This commit includes fixes for three bugs: 1) Caused by the optimization in StandardJanusGraphTx::addProperty, which saves a database read (and delete) operation for vertex property upsert. If a vertex property (or the vertex as a whole) is removed after the property is modified in the same transaction, then the old value in database will not be deleted after the transaction commits. Reported by JanusGraph#1981. 2) Caused by CacheVertexProperty::remove method which does nothing if it finds the given vertex property is already in the deletedRelations map. If the user deletes a vertex property after they update a nested property of that vertex property in the same transaction, then the old value will be removed from database but the new value will be saved into database after the transaction commits. 3) Caused by CacheEdge::remove method which does nothing if it finds the given edge is already in the deletedRelations map. If the user deletes an edge after they update a property of that edge in the same transaction, then the old value will be removed from database but the new value will be saved into database after the transaction commits. Signed-off-by: Boxuan Li <[email protected]>
- Loading branch information
Showing
7 changed files
with
251 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,10 @@ | |
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Lists; | ||
import org.apache.tinkerpop.gremlin.structure.VertexProperty; | ||
import org.janusgraph.core.JanusGraphElement; | ||
import org.janusgraph.core.JanusGraphRelation; | ||
import org.janusgraph.core.JanusGraphVertexProperty; | ||
import org.janusgraph.core.PropertyKey; | ||
import org.janusgraph.graphdb.internal.ElementLifeCycle; | ||
import org.janusgraph.graphdb.internal.InternalVertex; | ||
|
@@ -25,6 +29,7 @@ | |
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* @author Matthias Broecheler ([email protected]) | ||
|
@@ -37,14 +42,22 @@ public StandardVertexProperty(long id, PropertyKey type, InternalVertex vertex, | |
this.lifecycle = lifecycle; | ||
} | ||
|
||
//############## SAME CODE AS StandardEdge ############################# | ||
|
||
private static final Map<PropertyKey, Object> EMPTY_PROPERTIES = ImmutableMap.of(); | ||
|
||
private boolean isUpsert; | ||
private byte lifecycle; | ||
private long previousID = 0; | ||
private volatile Map<PropertyKey, Object> properties = EMPTY_PROPERTIES; | ||
|
||
/** | ||
* Mark this property as 'upsert', i.e. the old property value is not read from DB and marked as | ||
* deleted in the transaction | ||
* @param upsert | ||
*/ | ||
public void setUpsert(final boolean upsert) { | ||
isUpsert = upsert; | ||
} | ||
|
||
@Override | ||
public long getPreviousID() { | ||
return previousID; | ||
|
@@ -101,6 +114,11 @@ public synchronized void remove() { | |
if (!ElementLifeCycle.isRemoved(lifecycle)) { | ||
tx().removeRelation(this); | ||
lifecycle = ElementLifeCycle.update(lifecycle, ElementLifeCycle.Event.REMOVED); | ||
if (isUpsert) { | ||
VertexProperty.Cardinality cardinality = ((PropertyKey) type).cardinality().convert(); | ||
Consumer<JanusGraphVertexProperty> propertyRemover = JanusGraphVertexProperty.getRemover(cardinality, value()); | ||
element().query().types(type.name()).properties().forEach(propertyRemover); | ||
} | ||
} //else throw InvalidElementException.removedException(this); | ||
} | ||
|
||
|
Oops, something went wrong.