Skip to content

Commit

Permalink
Fix io step read path for string-type vertex ID
Browse files Browse the repository at this point in the history
g.io(path).read() would fail if the vertex contains
custom string-type vertex ID due to a bug in JanusGraphVertexFeatures.
This fixes this bug and adds two unit tests for gryo
and graphson format.

Signed-off-by: Boxuan Li <[email protected]>
  • Loading branch information
li-boxuan committed Mar 1, 2024
1 parent 0310ba4 commit 8f16731
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.janusgraph.graphdb;

import com.google.common.base.Preconditions;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
Expand Down Expand Up @@ -49,7 +50,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.nio.file.Path;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
Expand Down Expand Up @@ -561,4 +565,44 @@ public void removeGhostVertices() throws Exception {
assertEquals(0, result.getCustom(GhostVertexRemover.REMOVED_RELATION_COUNT));
assertEquals(0, result.getCustom(GhostVertexRemover.SKIPPED_GHOST_LIMIT_COUNT));
}

@Test
public void testWriteAndReadWithJanusGraphIoRegistryWithGryo(@TempDir Path tempDir) {
open(true, true);
final Path file = tempDir.resolve("testgraph_" + this.getClass().getCanonicalName() + ".kryo");
testWritingAndReading(file.toFile());
}

@Test
public void testWriteAndReadWithJanusGraphIoRegistryWithGraphson(@TempDir Path tempDir) {
open(true, true);
final Path file = tempDir.resolve("testgraph_" + this.getClass().getCanonicalName() + ".json");
testWritingAndReading(file.toFile());
}

private void testWritingAndReading(File f) {
GraphTraversalSource g = graph.traversal();
Vertex fromV = g.addV().property("name", f.getName()).property(T.id, "custom_id").next();
Vertex toV = g.addV().property(T.id, "another_vertex").next();
g.addE("connect").from(fromV).to(toV).next();
g.tx().commit();
assertEquals(0, f.length());

g.io(f.getAbsolutePath()).write().iterate();

assertTrue(f.length() > 0, "File " + f.getAbsolutePath() + " was expected to be not empty, but is");

open(true, true);
g = graph.traversal();
g.V().drop().iterate();
g.tx().commit();

g.io(f.getAbsolutePath()).read().iterate();

assertEquals(1, g.V().has("name", f.getName()).count().next());
assertEquals(1, g.V("custom_id").count().next());
assertEquals(2, g.V().count().next());
assertEquals("connect", g.E().label().next());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public boolean supportsUuidIds() {
@Override
public boolean supportsStringIds()
{
return false;
return JanusGraphFeatures.this.graph.getConfiguration().allowCustomVertexIdType();
}

@Override
Expand Down

1 comment on commit 8f16731

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 8f16731 Previous: b3b1dce Ratio
org.janusgraph.JanusGraphSpeedBenchmark.basicAddAndDelete 12224.451419958928 ms/op 12588.356749218838 ms/op 0.97
org.janusgraph.GraphCentricQueryBenchmark.getVertices 897.9392822267544 ms/op 909.6536269981073 ms/op 0.99
org.janusgraph.MgmtOlapJobBenchmark.runClearIndex 216.48304869166668 ms/op 216.2122553036232 ms/op 1.00
org.janusgraph.MgmtOlapJobBenchmark.runReindex 338.2740798808333 ms/op 331.69258417333333 ms/op 1.02
org.janusgraph.JanusGraphSpeedBenchmark.basicCount 240.3478315776463 ms/op 232.18271938462192 ms/op 1.04
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 4658.317353249839 ms/op 4879.715514269294 ms/op 0.95
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingEmitRepeatSteps 18100.282411561027 ms/op 16802.960996767306 ms/op 1.08
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithSmallBatch 19615.484407081818 ms/op 20381.521295766215 ms/op 0.96
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.vertexCentricPropertiesFetching 56124.3861435 ms/op 56975.635432099996 ms/op 0.99
org.janusgraph.CQLMultiQueryBenchmark.getAllElementsTraversedFromOuterVertex 8570.321831257039 ms/op 8054.207605035429 ms/op 1.06
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithDoubleUnion 378.80194999519415 ms/op 384.59161986127697 ms/op 0.98
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithUnlimitedBatch 4030.100992483259 ms/op 4115.273814482223 ms/op 0.98
org.janusgraph.CQLMultiQueryBenchmark.getNames 9533.438098868417 ms/op 8351.268976093337 ms/op 1.14
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesThreePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 5535.617836616562 ms/op 5906.676911188075 ms/op 0.94
org.janusgraph.CQLMultiQueryBenchmark.getLabels 8240.330937621815 ms/op 7066.74864075568 ms/op 1.17
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFilteredByAndStep 435.85182223697706 ms/op 414.6146026161681 ms/op 1.05
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFromMultiNestedRepeatStepStartingFromSingleVertex 13063.773657194643 ms/op 12388.279266927844 ms/op 1.05
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithCoalesceUsage 365.12307307394536 ms/op 377.3701223197372 ms/op 0.97
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 13404.947268287691 ms/op 14176.706682158057 ms/op 0.95
org.janusgraph.CQLMultiQueryBenchmark.getIdToOutVerticesProjection 267.5271221883553 ms/op 252.47136720355698 ms/op 1.06
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithUnlimitedBatch 13627.471829506405 ms/op 14549.732634626294 ms/op 0.94
org.janusgraph.CQLMultiQueryBenchmark.getNeighborNames 9366.919350857384 ms/op 8236.090879343183 ms/op 1.14
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingRepeatUntilSteps 9875.68999987767 ms/op 8988.754509413187 ms/op 1.10
org.janusgraph.CQLMultiQueryBenchmark.getAdjacentVerticesLocalCounts 9290.486975524458 ms/op 8459.285187558502 ms/op 1.10

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.