Skip to content

Commit

Permalink
Improve check for getting vertex when create edge (#1477)
Browse files Browse the repository at this point in the history
Change-Id: I86b7ac068154c52faf0d0d7f035cbf08178bf0d8
  • Loading branch information
Linary authored Jun 9, 2021
1 parent 23e3c31 commit 9f62e6f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public String create(@Context GraphManager manager,
"Invalid target vertex label '%s'");
}

Vertex srcVertex = getVertex(g, jsonEdge.source, null);
Vertex tgtVertex = getVertex(g, jsonEdge.target, null);
Vertex srcVertex = getVertex(g, jsonEdge.source, jsonEdge.sourceLabel);
Vertex tgtVertex = getVertex(g, jsonEdge.target, jsonEdge.targetLabel);

Edge edge = commit(g, () -> {
return srcVertex.addEdge(jsonEdge.label, tgtVertex,
Expand Down Expand Up @@ -275,7 +275,8 @@ public String list(@Context GraphManager manager,
@QueryParam("limit") @DefaultValue("100") long limit) {
LOG.debug("Graph [{}] query edges by vertex: {}, direction: {}, " +
"label: {}, properties: {}, offset: {}, page: {}, limit: {}",
vertexId, direction, label, properties, offset, page, limit);
graph, vertexId, direction,
label, properties, offset, page, limit);

Map<String, Object> props = parseProperties(properties);
if (page != null) {
Expand Down Expand Up @@ -402,6 +403,12 @@ private static Vertex getVertex(HugeGraph graph,
throw new IllegalArgumentException(String.format(
"Invalid vertex id '%s'", id));
}
if (!vertex.label().equals(label)) {
throw new IllegalArgumentException(String.format(
"The label of vertex '%s' is unmatched, users expect " +
"label '%s', actual label stored is '%s'",
id, label, vertex.label()));
}
// Clone a new vertex to support multi-thread access
return vertex.copy();
}
Expand Down

0 comments on commit 9f62e6f

Please sign in to comment.