use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testConcurrentConsistencyEnforcement.
@Test
public void testConcurrentConsistencyEnforcement() throws Exception {
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
JanusGraphIndex nameIndex = mgmt.buildIndex("name", Vertex.class).addKey(name).unique().buildCompositeIndex();
mgmt.setConsistency(nameIndex, ConsistencyModifier.LOCK);
EdgeLabel married = mgmt.makeEdgeLabel("married").multiplicity(Multiplicity.ONE2ONE).make();
mgmt.setConsistency(married, ConsistencyModifier.LOCK);
mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make();
finishSchema();
JanusGraphVertex baseV = tx.addVertex("name", "base");
newTx();
final long baseVid = getId(baseV);
final String nameA = "a", nameB = "b";
final int parallelThreads = 4;
int numSuccess = executeParallelTransactions(tx -> {
final JanusGraphVertex a = tx.addVertex();
final JanusGraphVertex base = getV(tx, baseVid);
base.addEdge("married", a);
}, parallelThreads);
assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
numSuccess = executeParallelTransactions(tx -> {
tx.addVertex("name", nameA);
final JanusGraphVertex b = tx.addVertex("name", nameB);
b.addEdge("friend", b);
}, parallelThreads);
newTx();
final long numA = Iterables.size(tx.query().has("name", nameA).vertices());
final long numB = Iterables.size(tx.query().has("name", nameB).vertices());
// System.out.println(numA + " - " + numB);
assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
assertTrue(numA <= 1);
assertTrue(numB <= 1);
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testTinkerPopCardinality.
@Test
public void testTinkerPopCardinality() {
PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make();
PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make();
mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex();
finishSchema();
GraphTraversalSource gts;
Vertex v;
v = graph.addVertex("id", 1);
v.property(single, "name", "t1");
graph.addVertex("id", 2, "names", "n1", "names", "n2");
graph.tx().commit();
gts = graph.traversal();
v = gts.V().has("id", 1).next();
v.property(single, "name", "t2");
v = gts.V().has("id", 1).next();
v.property(single, "name", "t3");
assertCount(1, gts.V(v).properties("name"));
assertCount(2, gts.V().has("id", 2).properties("names"));
assertCount(2, gts.V().hasLabel("vertex"));
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testLimitWithMixedIndexCoverage.
@Test
public void testLimitWithMixedIndexCoverage() {
final String vt = "vt";
final String fn = "firstname";
final String user = "user";
final String alice = "alice";
final String bob = "bob";
PropertyKey vtk = makeVertexIndexedKey(vt, String.class);
PropertyKey fnk = makeKey(fn, String.class);
finishSchema();
JanusGraphVertex a = tx.addVertex(vt, user, fn, "alice");
JanusGraphVertex b = tx.addVertex(vt, user, fn, "bob");
JanusGraphVertex v;
v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, bob).limit(1).vertices());
assertEquals(bob, v.value(fn));
assertEquals(user, v.value(vt));
v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, alice).limit(1).vertices());
assertEquals(alice, v.value(fn));
assertEquals(user, v.value(vt));
tx.commit();
tx = graph.newTransaction();
v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, bob).limit(1).vertices());
assertEquals(bob, v.value(fn));
assertEquals(user, v.value(vt));
v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, alice).limit(1).vertices());
assertEquals(alice, v.value(fn));
assertEquals(user, v.value(vt));
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testIndexUpdatesWithReindexAndRemove.
@Test
public void testIndexUpdatesWithReindexAndRemove() throws InterruptedException, ExecutionException {
clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
// Types without index
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make();
EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make();
PropertyKey sensor = mgmt.makePropertyKey("sensor").dataType(Double.class).cardinality(Cardinality.LIST).make();
finishSchema();
RelationTypeIndex pindex, eindex;
JanusGraphIndex graphIndex;
// Add some sensor & friend data
JanusGraphVertex v = tx.addVertex();
for (int i = 0; i < 10; i++) {
v.property("sensor", i, "time", i);
v.property("name", "v" + i);
JanusGraphVertex o = tx.addVertex();
v.addEdge("friend", o, "time", i);
}
newTx();
// Indexes should not yet be in use
v = getV(tx, v);
evaluateQuery(v.query().keys("sensor").interval("time", 1, 5).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().keys("sensor").interval("time", 101, 105).orderBy("time", decr), PROPERTY, 0, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 1, 5).orderBy("time", decr), EDGE, 4, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 0, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(tx.query().has("name", "v5"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("name", "v105"), ElementCategory.VERTEX, 0, new boolean[] { false, true });
newTx();
// Create indexes after the fact
finishSchema();
sensor = mgmt.getPropertyKey("sensor");
time = mgmt.getPropertyKey("time");
name = mgmt.getPropertyKey("name");
friend = mgmt.getEdgeLabel("friend");
mgmt.buildPropertyIndex(sensor, "byTime", decr, time);
mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time);
mgmt.buildIndex("bySensorReading", Vertex.class).addKey(name).buildCompositeIndex();
finishSchema();
newTx();
// Add some sensor & friend data that should already be indexed even though index is not yet enabled
v = getV(tx, v);
for (int i = 100; i < 110; i++) {
v.property("sensor", i, "time", i);
v.property("name", "v" + i);
JanusGraphVertex o = tx.addVertex();
v.addEdge("friend", o, "time", i);
}
tx.commit();
// Should not yet be able to enable since not yet registered
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime");
graphIndex = mgmt.getGraphIndex("bySensorReading");
try {
mgmt.updateIndex(pindex, SchemaAction.ENABLE_INDEX);
fail();
} catch (IllegalArgumentException ignored) {
}
try {
mgmt.updateIndex(eindex, SchemaAction.ENABLE_INDEX);
fail();
} catch (IllegalArgumentException ignored) {
}
try {
mgmt.updateIndex(graphIndex, SchemaAction.ENABLE_INDEX);
fail();
} catch (IllegalArgumentException ignored) {
}
mgmt.commit();
ManagementUtil.awaitVertexIndexUpdate(graph, "byTime", "sensor", 10, ChronoUnit.SECONDS);
ManagementUtil.awaitGraphIndexUpdate(graph, "bySensorReading", 5, ChronoUnit.SECONDS);
finishSchema();
// Verify new status
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime");
graphIndex = mgmt.getGraphIndex("bySensorReading");
assertEquals(SchemaStatus.REGISTERED, pindex.getIndexStatus());
assertEquals(SchemaStatus.REGISTERED, eindex.getIndexStatus());
assertEquals(SchemaStatus.REGISTERED, graphIndex.getIndexStatus(graphIndex.getFieldKeys()[0]));
finishSchema();
// Simply enable without reindex
eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime");
mgmt.updateIndex(eindex, SchemaAction.ENABLE_INDEX);
finishSchema();
assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "byTime", "friend").status(SchemaStatus.ENABLED).timeout(10L, ChronoUnit.SECONDS).call().getSucceeded());
// Reindex the other two
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
ScanMetrics reindexSensorByTime = mgmt.updateIndex(pindex, SchemaAction.REINDEX).get();
finishSchema();
graphIndex = mgmt.getGraphIndex("bySensorReading");
ScanMetrics reindexBySensorReading = mgmt.updateIndex(graphIndex, SchemaAction.REINDEX).get();
finishSchema();
assertNotEquals(0, reindexSensorByTime.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
assertNotEquals(0, reindexBySensorReading.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
// Every index should now be enabled
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime");
graphIndex = mgmt.getGraphIndex("bySensorReading");
assertEquals(SchemaStatus.ENABLED, eindex.getIndexStatus());
assertEquals(SchemaStatus.ENABLED, pindex.getIndexStatus());
assertEquals(SchemaStatus.ENABLED, graphIndex.getIndexStatus(graphIndex.getFieldKeys()[0]));
// Add some more sensor & friend data
newTx();
v = getV(tx, v);
for (int i = 200; i < 210; i++) {
v.property("sensor", i, "time", i);
v.property("name", "v" + i);
JanusGraphVertex o = tx.addVertex();
v.addEdge("friend", o, "time", i);
}
newTx();
// Use indexes now but only see new data for property and graph index
v = getV(tx, v);
evaluateQuery(v.query().keys("sensor").interval("time", 1, 5).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().keys("sensor").interval("time", 101, 105).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().keys("sensor").interval("time", 201, 205).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 1, 5).orderBy("time", decr), EDGE, 0, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(tx.query().has("name", "v5"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "bySensorReading");
evaluateQuery(tx.query().has("name", "v105"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "bySensorReading");
evaluateQuery(tx.query().has("name", "v205"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "bySensorReading");
finishSchema();
eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime");
ScanMetrics reindexFriendByTime = mgmt.updateIndex(eindex, SchemaAction.REINDEX).get();
finishSchema();
assertNotEquals(0, reindexFriendByTime.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
finishSchema();
newTx();
// It should now have all the answers
v = getV(tx, v);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 1, 5).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
graphIndex = mgmt.getGraphIndex("bySensorReading");
mgmt.updateIndex(pindex, SchemaAction.DISABLE_INDEX);
mgmt.updateIndex(graphIndex, SchemaAction.DISABLE_INDEX);
mgmt.commit();
tx.commit();
ManagementUtil.awaitVertexIndexUpdate(graph, "byTime", "sensor", 10, ChronoUnit.SECONDS);
ManagementUtil.awaitGraphIndexUpdate(graph, "bySensorReading", 5, ChronoUnit.SECONDS);
finishSchema();
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
graphIndex = mgmt.getGraphIndex("bySensorReading");
assertEquals(SchemaStatus.DISABLED, pindex.getIndexStatus());
assertEquals(SchemaStatus.DISABLED, graphIndex.getIndexStatus(graphIndex.getFieldKeys()[0]));
finishSchema();
newTx();
// The two disabled indexes should force full scans
v = getV(tx, v);
evaluateQuery(v.query().keys("sensor").interval("time", 1, 5).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().keys("sensor").interval("time", 101, 105).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().keys("sensor").interval("time", 201, 205).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { false, false }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 1, 5).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
evaluateQuery(tx.query().has("name", "v5"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("name", "v105"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("name", "v205"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
tx.commit();
finishSchema();
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime");
graphIndex = mgmt.getGraphIndex("bySensorReading");
ScanMetrics pmetrics = mgmt.updateIndex(pindex, SchemaAction.REMOVE_INDEX).get();
ScanMetrics graphIndexMetrics = mgmt.updateIndex(graphIndex, SchemaAction.REMOVE_INDEX).get();
finishSchema();
assertEquals(30, pmetrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
assertEquals(30, graphIndexMetrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testStaleVertex.
@Test
public void testStaleVertex() {
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
mgmt.makePropertyKey("age").dataType(Integer.class).make();
mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex();
finishSchema();
JanusGraphVertex cartman = graph.addVertex("name", "cartman", "age", 10);
graph.addVertex("name", "stan", "age", 8);
graph.tx().commit();
cartman = Iterables.getOnlyElement(graph.query().has("name", "cartman").vertices());
graph.tx().commit();
JanusGraphVertexProperty p = (JanusGraphVertexProperty) cartman.properties().next();
assertTrue((p.longId()) > 0);
graph.tx().commit();
}
Aggregations