bitflicker64 commented on code in PR #3275:
URL: https://github.com/apache/hugegraph/pull/3275#discussion_r4201888836
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java:
##########
@@ -1557,13 +1557,27 @@ private static void validateIndexLabel(IndexLabel
indexLabel) {
indexLabel, indexLabel.status());
}
- private static boolean hasNullableProp(HugeElement element, Id key) {
- return element.schemaLabel().nullableKeys().contains(key);
+ private boolean hasNullableProp(HugeElement element, Id key) {
+ return
this.currentSchemaLabel(element.schemaLabel()).nullableKeys().contains(key);
}
- private static Set<IndexLabel> relatedIndexLabels(HugeElement element) {
+ Set<Id> indexLabelIds(SchemaLabel label) {
+ return this.currentSchemaLabel(label).indexLabels();
+ }
+
+ private SchemaLabel currentSchemaLabel(SchemaLabel label) {
+ // Elements can outlive schema cache eviction. Resolve the current
index
+ // membership rather than using the schema object retained by an
element.
+ ISchemaTransaction schema = this.params().schemaTransaction();
+ SchemaLabel current = label.type() == HugeType.VERTEX_LABEL ?
+ schema.getVertexLabel(label.id()) :
schema.getEdgeLabel(label.id());
+ E.checkArgument(current != null, "Not exist schema label with id
'%s'", label.id());
Review Comment:
Important: `currentSchemaLabel()` now rejects any element whose label no
longer exists in the schema, so deleting a left record fails where it used to
work. The serializers build such elements on purpose: `vertexLabelOrNone()` /
`edgeLabelOrNone()` return `VertexLabel.undefined(graph, id)` /
`EdgeLabel.undefined(graph, id)` when the schema lookup returns null.
`GraphTransaction.warnLeftRecord()` shows these rows reach users, and its TODO
says they still have to be removed by hand. For one of these elements,
`schema.getVertexLabel(label.id())` (or `getEdgeLabel`) returns null by
definition, so `E.checkArgument(current != null, ...)` throws
`IllegalArgumentException: Not exist schema label with id ...`.
This is now hit on every write path that calls `indexLabelIds()`:
- `g.V(leftId).drop()` / `DELETE /graph/vertices/{id}`:
`HugeVertex.remove()` -> `GraphTransaction.removeVertex()` ->
`this.indexTx.indexLabelIds(vertex.schemaLabel())` throws before the vertex is
queued.
- Dropping a normal vertex that still has a left edge: `prepareDeletions()`
collects the edge from `queryEdgesFromBackend()`, then `updateEdgeIndex(edge,
true)` throws and the whole vertex delete fails.
Before this change, an undefined label had an empty `indexLabels()`, so both
deletes succeeded and cleared the leftover rows. Users therefore lose the only
way to clean up left vertices and edges, and they cannot delete ordinary
vertices next to one.
Please fall back to the element's own label when the lookup misses, so
existing behaviour is kept for deleted labels. For example:
```java
SchemaLabel current = ...;
return current != null ? current : label;
```
Please also add a regression test that removes a vertex built with
`VertexLabel.undefined(graph, id)` and a vertex whose adjacent edge has an
undefined edge label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]