incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Hard] HugeGryoModule.java: ` — `EdgeLabelKryoSerializer.read()` returns null, unimpleme

Open bitflicker64 opened this issue 5 months ago • 1 comments

Source

  • File: hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/io/HugeGryoModule.java
  • References: L151-L152

Now I have a comprehensive picture of the issue. Let me summarize what I found:

  1. In HugeGryoModule.java, there are four Kryo serializer inner classes for schema types:

    • PropertyKeyKryoSerializer
    • VertexLabelKryoSerializer
    • EdgeLabelKryoSerializer
    • IndexLabelKryoSerializer
  2. Each of these has a write() method that is fully implemented (using GraphSONSchemaSerializer to convert the schema object to a Map<HugeKeys, Object>, then writing it via writeEntry()), and a read() method that is a stub returning null with a // TODO comment.

  3. The readEntry() helper method exists in HugeGryoModule but is marked @SuppressWarnings("unused") — it reads back the Map<HugeKeys, Object> from the Kryo stream, but is never called by any of the read() methods.

  4. GraphSONSchemaSerializer only has write* methods — there are no corresponding read* methods in it. The SchemaSerializer interface (in the backend serializer package) does have readEdgeLabel, readVertexLabel, etc., but those take a HugeGraph and a BackendEntry, not a Map<HugeKeys, Object>.

  5. The TODO affects all 4 schema serializer read() methods in the same file.

The issue is that Gryo (Kryo-based binary serialization used by TinkerPop) can serialize schema objects out but cannot deserialize them back. Any code path that tries to read a Gryo-serialized EdgeLabel, VertexLabel, PropertyKey, or IndexLabel from a binary stream will silently get null instead of the actual object.

The scope of the fix is confined to HugeGryoModule.java (1 file), but may also require adding read methods to GraphSONSchemaSerializer (1 file), for a total of 1-2 files affected.

The Issue

The TODO affects all four schema Kryo serializer inner classes in HugeGryoModule.java, not just EdgeLabelKryoSerializer. Each has a fully-implemented write() but a stub read() that unconditionally returns null:

PropertyKeyKryoSerializer.read()   → // TODO, return null  (line 151-154)
VertexLabelKryoSerializer.read()   → // TODO, return null  (line 165-168)
EdgeLabelKryoSerializer.read()     → // TODO, return null  (line 179-182)
IndexLabelKryoSerializer.read()    → // TODO, return null  (line 193-196)

What exactly is broken

The write() side works: it calls GraphSONSchemaSerializer.writeEdgeLabel() to produce a Map<HugeKeys, Object>, then serializes it to the Kryo binary stream via writeEntry().

The inverse path — readEntry() — already exists and correctly reads back the Map<HugeKeys, Object> from the stream, but it is annotated @SuppressWarnings("unused") because nothing calls it:

The missing piece is: after calling readEntry() to get the map back, there is no code to reconstruct an EdgeLabel (or any other schema object) from that map. GraphSONSchemaSerializer only has write* methods — it has no read* counterparts:

The backend SchemaSerializer interface does define readEdgeLabel(HugeGraph, BackendEntry) etc., but those operate on BackendEntry objects (storage-layer format), not on the Map<HugeKeys, Object> that the Gryo path produces:

Consequence

Any Gryo (TinkerPop binary) deserialization of schema objects — e.g. reading an EdgeLabel back from a Gryo stream — silently returns null. This would cause NPEs or incorrect behavior in any code path that round-trips schema objects through Gryo I/O (e.g. Gremlin result serialization over the binary protocol, graph export/import via Gryo).

What code needs to change

1 primary file needs changes:

  • hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/io/HugeGryoModule.java — The four read() stubs must be implemented. Each should call readEntry() to recover the Map<HugeKeys, Object>, then reconstruct the schema object from that map.

1 supporting file likely also needs changes:

  • hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/io/GraphSONSchemaSerializer.java — Needs readEdgeLabel(Map<HugeKeys,Object>, HugeGraph), readVertexLabel(...), readPropertyKey(...), and readIndexLabel(...) methods added, mirroring the existing write* methods in reverse. (The HugeGryoModule serializers need a HugeGraph reference to reconstruct schema objects, which is a complication — the Kryo Serializer API does not pass one in, so the serializer classes would need to hold a graph reference injected at registration time.)

Total: 2 files directly affected, with the core logic gap being the missing read* methods in GraphSONSchemaSerializer and the unimplemented read() bodies in HugeGryoModule.

bitflicker64 avatar Jun 23 '26 06:06 bitflicker64

This was created accidentally during testing ....closing. Sorry for the noise.

bitflicker64 avatar Jun 23 '26 07:06 bitflicker64