Skip to content

Commit

Permalink
Reindex test
Browse files Browse the repository at this point in the history
Signed-off-by: ntisseyre <[email protected]>
  • Loading branch information
ntisseyre committed Oct 17, 2024
1 parent ef678e2 commit ce8e897
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Vertex> 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<Vertex> 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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ public Collection<IndexUpdate> getIndexUpdates(InternalRelation relation, IndexA
}

public Stream<IndexUpdate> getIndexUpdates(InternalVertex vertex,

Check warning on line 244 in janusgraph-core/src/main/java/org/janusgraph/graphdb/database/IndexSerializer.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

janusgraph-core/src/main/java/org/janusgraph/graphdb/database/IndexSerializer.java#L244

The method 'getIndexUpdates(InternalVertex, Collection, IndexAppliesToFunction, TypeInspector)' has an NPath complexity of 376, current threshold is 200
Collection<InternalRelation> updatedProperties,
IndexAppliesToFunction indexFilter,
TypeInspector typeInspector) {
Collection<InternalRelation> updatedProperties,
IndexAppliesToFunction indexFilter,
TypeInspector typeInspector) {

if (updatedProperties.isEmpty()) return Stream.empty();
final Map<Object, IndexUpdateContainer> updates = new HashMap<>();
Expand Down

0 comments on commit ce8e897

Please sign in to comment.