use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanGraphTest method testGotGIndexRemoval.
@Test
public void testGotGIndexRemoval() throws InterruptedException, ExecutionException {
clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ZERO, option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
final String name = "name";
// Load Graph of the Gods
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, // True makes the index on names unique. Test fails when this is true.
true);
// Change to false and test will pass.
newTx();
finishSchema();
TitanGraphIndex gindex = mgmt.getGraphIndex(name);
// Sanity checks on the index that we assume GraphOfTheGodsFactory created
assertNotNull(gindex);
assertEquals(1, gindex.getFieldKeys().length);
assertEquals(name, gindex.getFieldKeys()[0].name());
assertEquals("internalindex", gindex.getBackingIndex());
assertEquals(SchemaStatus.ENABLED, gindex.getIndexStatus(gindex.getFieldKeys()[0]));
finishSchema();
// Disable name index
gindex = mgmt.getGraphIndex(name);
mgmt.updateIndex(gindex, SchemaAction.DISABLE_INDEX);
mgmt.commit();
tx.commit();
ManagementUtil.awaitGraphIndexUpdate(graph, name, 5, ChronoUnit.SECONDS);
finishSchema();
// Remove name index
gindex = mgmt.getGraphIndex(name);
mgmt.updateIndex(gindex, SchemaAction.REMOVE_INDEX);
TitanManagement.IndexJobFuture gmetrics = mgmt.getIndexJobStatus(gindex);
finishSchema();
// Should have deleted at least one record
assertNotEquals(0, gmetrics.get().getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanIndexTest method testConditionalIndexing.
/**
* Tests conditional indexing and the different management features
*/
@Test
public void testConditionalIndexing() {
PropertyKey name = makeKey("name", String.class);
PropertyKey weight = makeKey("weight", Double.class);
PropertyKey text = makeKey("text", String.class);
VertexLabel person = mgmt.makeVertexLabel("person").make();
VertexLabel org = mgmt.makeVertexLabel("org").make();
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name, getStringMapping()).buildMixedIndex(INDEX);
TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).indexOnly(person).addKey(text, getTextMapping()).addKey(weight).buildMixedIndex(INDEX);
TitanGraphIndex index3 = mgmt.buildIndex("index3", Vertex.class).indexOnly(org).addKey(text, getTextMapping()).addKey(weight).buildMixedIndex(INDEX);
// ########### INSPECTION & FAILURE ##############
assertTrue(mgmt.containsGraphIndex("index1"));
assertFalse(mgmt.containsGraphIndex("index"));
assertCount(3, mgmt.getGraphIndexes(Vertex.class));
assertNull(mgmt.getGraphIndex("indexx"));
name = mgmt.getPropertyKey("name");
weight = mgmt.getPropertyKey("weight");
text = mgmt.getPropertyKey("text");
person = mgmt.getVertexLabel("person");
org = mgmt.getVertexLabel("org");
index1 = mgmt.getGraphIndex("index1");
index2 = mgmt.getGraphIndex("index2");
index3 = mgmt.getGraphIndex("index3");
assertTrue(Vertex.class.isAssignableFrom(index1.getIndexedElement()));
assertEquals("index2", index2.name());
assertEquals(INDEX, index3.getBackingIndex());
assertFalse(index2.isUnique());
assertEquals(2, index3.getFieldKeys().length);
assertEquals(1, index1.getFieldKeys().length);
assertEquals(3, index3.getParametersFor(text).length);
assertEquals(2, index3.getParametersFor(weight).length);
try {
//Already exists
mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildMixedIndex(INDEX);
fail();
} catch (IllegalArgumentException e) {
}
try {
//Already exists
mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//Key is already added
mgmt.addIndexKey(index2, weight);
fail();
} catch (IllegalArgumentException e) {
}
finishSchema();
clopen();
// ########### INSPECTION & FAILURE (copied from above) ##############
assertTrue(mgmt.containsGraphIndex("index1"));
assertFalse(mgmt.containsGraphIndex("index"));
assertCount(3, mgmt.getGraphIndexes(Vertex.class));
assertNull(mgmt.getGraphIndex("indexx"));
name = mgmt.getPropertyKey("name");
weight = mgmt.getPropertyKey("weight");
text = mgmt.getPropertyKey("text");
person = mgmt.getVertexLabel("person");
org = mgmt.getVertexLabel("org");
index1 = mgmt.getGraphIndex("index1");
index2 = mgmt.getGraphIndex("index2");
index3 = mgmt.getGraphIndex("index3");
assertTrue(Vertex.class.isAssignableFrom(index1.getIndexedElement()));
assertEquals("index2", index2.name());
assertEquals(INDEX, index3.getBackingIndex());
assertFalse(index2.isUnique());
assertEquals(2, index3.getFieldKeys().length);
assertEquals(1, index1.getFieldKeys().length);
assertEquals(3, index3.getParametersFor(text).length);
assertEquals(2, index3.getParametersFor(weight).length);
try {
//Already exists
mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildMixedIndex(INDEX);
fail();
} catch (IllegalArgumentException e) {
}
try {
//Already exists
mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//Key is already added
mgmt.addIndexKey(index2, weight);
fail();
} catch (IllegalArgumentException e) {
}
// ########### TRANSACTIONAL ##############
weight = tx.getPropertyKey("weight");
final int numV = 200;
String[] strs = { "houseboat", "humanoid", "differential", "extraordinary" };
String[] strs2 = new String[strs.length];
for (int i = 0; i < strs.length; i++) strs2[i] = strs[i] + " " + strs[i];
final int modulo = 5;
assert numV % (modulo * strs.length * 2) == 0;
for (int i = 0; i < numV; i++) {
TitanVertex v = tx.addVertex(i % 2 == 0 ? "person" : "org");
v.property("name", strs[i % strs.length]);
v.property("text", strs[i % strs.length]);
v.property("weight", (i % modulo) + 0.5);
}
//########## QUERIES ################
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index2.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", decr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, weight, Order.DESC, index2.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has(LABEL_NAME, Cmp.EQUAL, "org"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index3.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[1]).has(LABEL_NAME, Cmp.EQUAL, "org").orderBy("weight", decr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, weight, Order.DESC, index3.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("weight", Cmp.EQUAL, 2.5).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / (modulo * strs.length), new boolean[] { true, true }, index2.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true }, index1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[3]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, 0, new boolean[] { false, true }, index1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[2]).has("text", Text.CONTAINS, strs[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index1.name(), index2.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("text", Text.CONTAINS, strs[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", incr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, weight, Order.ASC, index1.name(), index2.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).orderBy("weight", incr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, false }, weight, Order.ASC);
clopen();
weight = tx.getPropertyKey("weight");
//########## QUERIES (copied from above) ################
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index2.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", decr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, weight, Order.DESC, index2.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has(LABEL_NAME, Cmp.EQUAL, "org"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index3.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[1]).has(LABEL_NAME, Cmp.EQUAL, "org").orderBy("weight", decr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, weight, Order.DESC, index3.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("weight", Cmp.EQUAL, 2.5).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / (modulo * strs.length), new boolean[] { true, true }, index2.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true }, index1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[3]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, 0, new boolean[] { false, true }, index1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[2]).has("text", Text.CONTAINS, strs[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, index1.name(), index2.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("text", Text.CONTAINS, strs[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", incr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, weight, Order.ASC, index1.name(), index2.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).orderBy("weight", incr), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, false }, weight, Order.ASC);
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanIndexTest method testDualMapping.
@Test
public void testDualMapping() {
if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING))
return;
PropertyKey name = makeKey("name", String.class);
TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX);
mixed.name();
finishSchema();
tx.addVertex("name", "Long John Don");
tx.addVertex("name", "Long Little Lewis");
tx.addVertex("name", "Middle Sister Mabel");
clopen();
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS_PREFIX, "Lon"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS_REGEX, "Lit*le"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.REGEX, "Long.*"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
for (Vertex u : tx.getVertices()) {
String n = u.<String>value("name");
if (n.endsWith("Don")) {
u.remove();
} else if (n.endsWith("Lewis")) {
u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
} else if (n.endsWith("Mabel")) {
u.property("name").remove();
}
}
clopen();
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Big"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.PREFIX, "Big"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mixed");
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanOperationCountingTest method checkPropertyLockingAndIndex.
@Test
public void checkPropertyLockingAndIndex() {
PropertyKey uid = makeKey("uid", String.class);
TitanGraphIndex index = mgmt.buildIndex("uid", Vertex.class).unique().addKey(uid).buildCompositeIndex();
mgmt.setConsistency(index, ConsistencyModifier.LOCK);
mgmt.makePropertyKey("name").dataType(String.class).make();
mgmt.makePropertyKey("age").dataType(Integer.class).make();
finishSchema();
metricsPrefix = "checkPropertyLockingAndIndex";
TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john");
assertEquals(25, v.property("age").value());
tx.commit();
verifyStoreMetrics(EDGESTORE_NAME);
verifyLockingOverwrite(INDEXSTORE_NAME, 1);
verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));
resetMetrics();
tx = graph.buildTransaction().groupName(metricsPrefix).start();
v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices());
assertEquals(25, v.property("age").value());
tx.commit();
verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE, 1l));
verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE, 1l));
verifyStoreMetrics(METRICS_STOREMANAGER_NAME);
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanGraphBaseTest method getExternalIndex.
public TitanGraphIndex getExternalIndex(Class<? extends Element> clazz, String backingIndex) {
String prefix;
if (Vertex.class.isAssignableFrom(clazz))
prefix = "v";
else if (Edge.class.isAssignableFrom(clazz))
prefix = "e";
else if (TitanVertexProperty.class.isAssignableFrom(clazz))
prefix = "p";
else
throw new AssertionError(clazz.toString());
String indexName = prefix + backingIndex;
TitanGraphIndex index = mgmt.getGraphIndex(indexName);
if (index == null) {
index = mgmt.buildIndex(indexName, clazz).buildMixedIndex(backingIndex);
}
return index;
}
Aggregations