From ce8e897370fde374b2b4a1f453d0854f0ff2bb35 Mon Sep 17 00:00:00 2001 From: ntisseyre Date: Wed, 16 Oct 2024 21:46:46 -0700 Subject: [PATCH] Reindex test Signed-off-by: ntisseyre --- .../graphdb/JanusGraphIndexTest.java | 64 +++++++++++++++++++ .../graphdb/database/IndexSerializer.java | 6 +- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphIndexTest.java b/janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphIndexTest.java index f3bf9fef89..d66707855d 100644 --- a/janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphIndexTest.java +++ b/janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphIndexTest.java @@ -70,6 +70,7 @@ import org.janusgraph.diskstorage.indexing.IndexInformation; import org.janusgraph.diskstorage.indexing.IndexProvider; import org.janusgraph.diskstorage.indexing.IndexTransaction; +import org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture; import org.janusgraph.diskstorage.log.kcvs.KCVSLog; import org.janusgraph.diskstorage.util.time.TimestampProvider; import org.janusgraph.example.GraphOfTheGodsFactory; @@ -1487,6 +1488,69 @@ public void testIndexInlineProperties() throws NoSuchMethodException { assertEquals(city, v.value("city")); } + @Test + public void testIndexInlinePropertiesReindex() throws NoSuchMethodException, InterruptedException { + clopen(option(FORCE_INDEX_USAGE), true); + + PropertyKey idKey = makeKey("id", Integer.class); + PropertyKey nameKey = makeKey("name", String.class); + PropertyKey cityKey = makeKey("city", String.class); + + mgmt.buildIndex("composite", Vertex.class) + .addKey(cityKey) + .buildCompositeIndex(); + + finishSchema(); + + String city = "Chicago"; + for (int i = 0; i < 3; i++) { + tx.addVertex("id", i, "name", "name" + i, "city", city); + } + + tx.commit(); + + tx = graph.buildTransaction() + .propertyPrefetching(false) //this is important + .start(); + + Method m = VertexCentricQueryBuilder.class.getSuperclass().getDeclaredMethod("constructQuery", RelationCategory.class); + m.setAccessible(true); + + List vertices = tx.traversal().V().has("city", city).toList(); + vertices.stream() + .map(v -> (CacheVertex) v) + .forEach(v -> verifyPropertyLoaded(v, "name", false, m)); + + tx.commit(); + + //Include inlined property + JanusGraphIndex index = mgmt.getGraphIndex("composite"); + nameKey = mgmt.getPropertyKey("name"); + mgmt.addInlinePropertyKey(index, nameKey); + finishSchema(); + + //Reindex + index = mgmt.getGraphIndex("composite"); + ScanJobFuture scanJobFuture = mgmt.updateIndex(index, SchemaAction.REINDEX); + finishSchema(); + + while (!scanJobFuture.isDone()) { + Thread.sleep(1000); + } + + //Try query now + tx = graph.buildTransaction() + .propertyPrefetching(false) //this is important + .start(); + + List vertices2 = tx.traversal().V().has("city", city).toList(); + vertices2.stream() + .map(v -> (CacheVertex) v) + .forEach(v -> verifyPropertyLoaded(v, "name", true, m)); + + tx.commit(); + } + @Test public void testIndexInlinePropertiesUpdate() { diff --git a/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/IndexSerializer.java b/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/IndexSerializer.java index 00a43f83be..8f7b571784 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/IndexSerializer.java +++ b/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/IndexSerializer.java @@ -242,9 +242,9 @@ public Collection getIndexUpdates(InternalRelation relation, IndexA } public Stream getIndexUpdates(InternalVertex vertex, - Collection updatedProperties, - IndexAppliesToFunction indexFilter, - TypeInspector typeInspector) { + Collection updatedProperties, + IndexAppliesToFunction indexFilter, + TypeInspector typeInspector) { if (updatedProperties.isEmpty()) return Stream.empty(); final Map updates = new HashMap<>();