public void testBatchLoadingLocking(boolean batchloading) { PropertyKey uid = makeKey("uid",Long.class); TitanGraphIndex uidIndex = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex(); mgmt.setConsistency(uid, ConsistencyModifier.LOCK); mgmt.setConsistency(uidIndex,ConsistencyModifier.LOCK); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.setConsistency(knows,ConsistencyModifier.LOCK); finishSchema(); TestLockerManager.ERROR_ON_LOCKING=true; clopen(option(GraphDatabaseConfiguration.STORAGE_BATCH),batchloading, option(GraphDatabaseConfiguration.LOCK_BACKEND),"test"); int numV = 10000; long start = System.currentTimeMillis(); for (int i=0;i<numV;i++) { TitanVertex v = tx.addVertex("uid",i+1); v.addEdge("knows",v); } clopen(); // System.out.println("Time: " + (System.currentTimeMillis()-start)); for (int i=0;i<Math.min(numV,300);i++) { assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices())); TitanVertex v = Iterables.<TitanVertex>getOnlyElement(graph.query().has("uid", i + 1).vertices()); assertEquals(1, Iterables.size(v.query().direction(OUT).labels("knows").edges())); } }
@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); }
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); TitanGraphIndex nameIndex = mgmt.buildIndex("name", Vertex.class) .addKey(name).unique().buildCompositeIndex(); mgmt.setConsistency(nameIndex, ConsistencyModifier.LOCK); EdgeLabel married = mgmt.makeEdgeLabel("married").multiplicity(Multiplicity.ONE2ONE).make();
private void createSchema() { final TitanManagement mgmt = titanGraph.getManagementSystem(); if (!titanGraph.getIndexedKeys(Vertex.class).contains(NODE_ID)) { final PropertyKey key = mgmt.makePropertyKey(NODE_ID).dataType(Integer.class).make(); mgmt.buildIndex(NODE_ID, Vertex.class).addKey(key).unique().buildCompositeIndex(); } if (!titanGraph.getIndexedKeys(Vertex.class).contains(COMMUNITY)) { final PropertyKey key = mgmt.makePropertyKey(COMMUNITY).dataType(Integer.class).make(); mgmt.buildIndex(COMMUNITY, Vertex.class).addKey(key).buildCompositeIndex(); } if (!titanGraph.getIndexedKeys(Vertex.class).contains(NODE_COMMUNITY)) { final PropertyKey key = mgmt.makePropertyKey(NODE_COMMUNITY).dataType(Integer.class).make(); mgmt.buildIndex(NODE_COMMUNITY, Vertex.class).addKey(key).buildCompositeIndex(); } if (mgmt.getEdgeLabel(SIMILAR) == null) { mgmt.makeEdgeLabel(SIMILAR).multiplicity(Multiplicity.MULTI).directed().make(); } mgmt.commit(); }
@Test public void testIndexQueryWithLabelsAndContainsIN() { // This test is based on the steps to reproduce #882 String labelName = "labelName"; VertexLabel label = mgmt.makeVertexLabel(labelName).make(); PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make(); TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex(); mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK); finishSchema(); Vertex foo = graph.addVertexWithLabel(labelName); Vertex bar = graph.addVertexWithLabel(labelName); foo.setProperty("uid", "foo"); bar.setProperty("uid", "bar"); graph.commit(); Iterable<Vertex> vertexes = graph.query() .has("uid", Contain.IN, ImmutableList.of("foo", "bar")) .has("label", labelName) .vertices(); assertEquals(2, Iterables.size(vertexes)); for (Vertex v : vertexes) { assertEquals(labelName, ((TitanVertex)v).getLabel()); } }
private static void makeIndicesComposite(TitanManagement management){ ResourceBundle keys = ResourceBundle.getBundle("indices-composite"); Set<String> keyString = keys.keySet(); for(String propertyKeyLabel : keyString){ String indexLabel = "by" + propertyKeyLabel; TitanIndex index = management.getGraphIndex(indexLabel); if(index == null) { boolean isUnique = Boolean.parseBoolean(keys.getString(propertyKeyLabel)); PropertyKey key = management.getPropertyKey(propertyKeyLabel); TitanManagement.IndexBuilder indexBuilder = management.buildIndex(indexLabel, Vertex.class).addKey(key); if (isUnique) indexBuilder.unique(); indexBuilder.buildCompositeIndex(); } } } }
private static void makeIndicesComposite(TitanManagement management){ ResourceBundle keys = ResourceBundle.getBundle("indices-composite"); Set<String> keyString = keys.keySet(); for(String indexLabel : keyString){ TitanIndex index = management.getGraphIndex(indexLabel); if(index == null) { String[] indexComponents = keys.getString(indexLabel).split(","); String propertyKey = indexComponents[0]; boolean isUnique = Boolean.parseBoolean(indexComponents[1]); PropertyKey key = management.getPropertyKey(propertyKey); TitanManagement.IndexBuilder indexBuilder = management.buildIndex(indexLabel, Vertex.class).addKey(key); if (isUnique) indexBuilder.unique(); indexBuilder.buildCompositeIndex(); } } } }
@Test public void testStaleVertex() { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make(); mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex(); finishSchema(); TitanVertex cartman = graph.addVertex(null); ElementHelper.setProperties(cartman,"name","cartman", "age", 10); TitanVertex stan = graph.addVertex(null); ElementHelper.setProperties(stan,"name","stan","age",8); graph.commit(); cartman = (TitanVertex)graph.getVertices("name", "cartman").iterator().next(); graph.commit(); //TitanProperty p = (TitanProperty) ((Iterable)graph.multiQuery(cartman).properties().values().iterator().next()).iterator().next(); TitanProperty p = cartman.getProperties().iterator().next(); System.out.println(p.getLongId()); graph.commit(); }
@Override public void createExactMatchIndex(String propertyName, boolean enforceUniqueness, List<AtlasPropertyKey> propertyKeys) { TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class); for(AtlasPropertyKey key : propertyKeys) { PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key); indexBuilder.addKey(titanKey); } if (enforceUniqueness) { indexBuilder.unique(); } indexBuilder.buildCompositeIndex(); }
private static Graph openTuplGraph() { final Configuration conf = new BaseConfiguration(); conf.addProperty("storage.backend", "jp.classmethod.titan.diskstorage.tupl.TuplStoreManager"); final TitanGraph g = TitanFactory.open(conf); final TitanManagement mgmt = g.openManagement(); final PropertyKey nameKey = mgmt.makePropertyKey(NAME).cardinality(Cardinality.SINGLE).dataType(String.class).make(); mgmt.buildIndex("nameKeyIndex", Vertex.class).addKey(nameKey).unique().buildCompositeIndex(); mgmt.commit(); g.tx().commit(); return g; }
public void createExactMatchVertexIndex(String propertyName, boolean enforceUniqueness, List<AtlasPropertyKey> propertyKeys) { TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class); for (AtlasPropertyKey key : propertyKeys) { PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key); indexBuilder.addKey(titanKey); } if (enforceUniqueness) { indexBuilder.unique(); } indexBuilder.buildCompositeIndex(); }
public PropertyKey makeVertexIndexedUniqueKey(String name, Class datatype) { PropertyKey key = mgmt.makePropertyKey(name).dataType(datatype).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).unique().buildCompositeIndex(); return key; }
mgmt.buildIndex(RESTAURANT_ID, Vertex.class).addKey(RESTAURANTIdKey).unique().buildCompositeIndex(); mgmt.makePropertyKey(PROP_RESTAURANT_NAME).dataType(String.class).make(); mgmt.makePropertyKey(PROP_RESTAURANT_LATITUDE).dataType(Double.class).make(); mgmt.buildIndex(USER_ID, Vertex.class).addKey(userKey).unique().buildCompositeIndex(); mgmt.makePropertyKey(PROP_USER_DRESSPREFERENCE).dataType(String.class).make(); mgmt.makePropertyKey(PROP_USER_BUDGET).dataType(String.class).make(); mgmt.buildIndex(GENRE, Vertex.class).addKey(genreKey).unique().buildCompositeIndex();
TitanGraphIndex prop2 = mgmt.buildIndex("prop2", TitanVertexProperty.class).addKey(weight).addKey(text).buildCompositeIndex(); TitanGraphIndex vertex1 = mgmt.buildIndex("vertex1", Vertex.class).addKey(time).indexOnly(person).unique().buildCompositeIndex(); TitanGraphIndex vertex12 = mgmt.buildIndex("vertex12", Vertex.class).addKey(text).indexOnly(person).buildCompositeIndex(); TitanGraphIndex vertex2 = mgmt.buildIndex("vertex2", Vertex.class).addKey(time).addKey(name).indexOnly(organization).buildCompositeIndex(); mgmt.buildIndex("edgexyz", Edge.class).addKey(time).unique().buildCompositeIndex(); fail(); } catch (IllegalArgumentException e) { mgmt.buildIndex("edgexyz", Edge.class).addKey(time).unique().buildCompositeIndex(); fail(); } catch (IllegalArgumentException e) {
TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name); if (uniqueNameCompositeIndex) nameIndexBuilder.unique(); TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex(); mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
VertexLabel org = mgmt.makeVertexLabel("organization").make(); TitanGraphIndex vindex1 = mgmt.buildIndex("vindex1", Vertex.class).addKey(time).indexOnly(person).unique().buildCompositeIndex(); TitanGraphIndex vindex2 = mgmt.buildIndex("vindex2", Vertex.class).addKey(time).addKey(text).unique().buildCompositeIndex(); finishSchema();
/** * This test exercises different types of updates against cardinality restricted properties * to ensure that the resulting behavior is fully consistent. */ @Test public void testPropertyCardinality() { PropertyKey uid = mgmt.makePropertyKey("uid").dataType(Long.class).cardinality(Cardinality.SINGLE).make(); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex("byUid", Vertex.class).addKey(uid).unique().buildCompositeIndex(); mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex(); finishSchema(); TitanVertex v1 = tx.addVertex(); v1.property("name", "name1"); TitanVertex v2 = tx.addVertex(); v2.property("uid", 512); newTx(); v1 = tx.getVertex(v1.longId()); v1.property("name", "name2"); //Ensure that the old index record gets removed v2 = tx.getVertex(v2.longId()); v2.property("uid", 512); //Ensure that replacement is allowed newTx(); assertCount(0, tx.query().has("name", "name1").vertices()); assertCount(1, tx.query().has("name", "name2").vertices()); assertCount(1, tx.query().has("uid", 512).vertices()); }
@Test public void testIndexQueryWithLabelsAndContainsIN() { // This test is based on the steps to reproduce #882 String labelName = "labelName"; VertexLabel label = mgmt.makeVertexLabel(labelName).make(); PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make(); TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex(); mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK); finishSchema(); TitanVertex foo = graph.addVertex(labelName); TitanVertex bar = graph.addVertex(labelName); foo.property("uid", "foo"); bar.property("uid", "bar"); graph.tx().commit(); Iterable<TitanVertex> vertexes = graph.query() .has("uid", Contain.IN, ImmutableList.of("foo", "bar")) .has(LABEL_NAME, labelName) .vertices(); assertEquals(2, Iterables.size(vertexes)); for (TitanVertex v : vertexes) { assertEquals(labelName, v.vertexLabel().name()); } }
@Test public void testStaleVertex() { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make(); mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex(); finishSchema(); TitanVertex cartman = graph.addVertex("name", "cartman", "age", 10); TitanVertex stan = graph.addVertex("name", "stan", "age", 8); graph.tx().commit(); cartman = getOnlyElement(graph.query().has("name", "cartman").vertices()); graph.tx().commit(); TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next(); assertTrue(((Long) p.longId()) > 0); graph.tx().commit(); }
public PropertyKey makeVertexIndexedUniqueKey(String name, Class datatype) { PropertyKey key = mgmt.makePropertyKey(name).dataType(datatype).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).unique().buildCompositeIndex(); return key; }