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; }
assertEquals(2, Iterables.size(mgmt.getGraphIndexes(TitanVertexProperty.class))); assertEquals(4, Iterables.size(mgmt.getGraphIndexes(Vertex.class))); assertNull(mgmt.getGraphIndex("balblub")); edge1 = mgmt.getGraphIndex("edge1"); edge2 = mgmt.getGraphIndex("edge2"); prop1 = mgmt.getGraphIndex("prop1"); prop2 = mgmt.getGraphIndex("prop2"); vertex1 = mgmt.getGraphIndex("vertex1"); vertex12 = mgmt.getGraphIndex("vertex12"); vertex2 = mgmt.getGraphIndex("vertex2"); vertex3 = mgmt.getGraphIndex("vertex3"); assertEquals(2, Iterables.size(mgmt.getGraphIndexes(TitanVertexProperty.class))); assertEquals(4, Iterables.size(mgmt.getGraphIndexes(Vertex.class))); assertNull(mgmt.getGraphIndex("balblub")); edge1 = mgmt.getGraphIndex("edge1"); edge2 = mgmt.getGraphIndex("edge2"); prop1 = mgmt.getGraphIndex("prop1"); prop2 = mgmt.getGraphIndex("prop2"); vertex1 = mgmt.getGraphIndex("vertex1"); vertex12 = mgmt.getGraphIndex("vertex12"); vertex2 = mgmt.getGraphIndex("vertex2"); vertex3 = mgmt.getGraphIndex("vertex3");
@Test public void testIdCounts() { makeVertexIndexedUniqueKey("uid", Integer.class); mgmt.setConsistency(mgmt.getGraphIndex("uid"), ConsistencyModifier.LOCK); finishSchema(); //Schema and relation id pools are tapped, Schema id pool twice because the renew is triggered. Each id acquisition requires 1 mutations and 2 reads verifyStoreMetrics(ID_STORE_NAME, SYSTEM_METRICS, ImmutableMap.of(M_MUTATE, 3l, M_GET_SLICE, 6l)); }
assertFalse(mgmt.containsGraphIndex("index")); assertCount(3, mgmt.getGraphIndexes(Vertex.class)); assertNull(mgmt.getGraphIndex("indexx")); person = mgmt.getVertexLabel("person"); org = mgmt.getVertexLabel("org"); index1 = mgmt.getGraphIndex("index1"); index2 = mgmt.getGraphIndex("index2"); index3 = mgmt.getGraphIndex("index3"); assertFalse(mgmt.containsGraphIndex("index")); assertCount(3, mgmt.getGraphIndexes(Vertex.class)); assertNull(mgmt.getGraphIndex("indexx")); person = mgmt.getVertexLabel("person"); org = mgmt.getVertexLabel("org"); index1 = mgmt.getGraphIndex("index1"); index2 = mgmt.getGraphIndex("index2"); index3 = mgmt.getGraphIndex("index3");
try { mgmt = g.openManagement(); idx = mgmt.getGraphIndex(graphIndexName); for (PropertyKey pk : idx.getFieldKeys()) { SchemaStatus s = idx.getIndexStatus(pk);
isStable = idx.getIndexStatus().isStable(); } else { TitanGraphIndex idx = mgmt.getGraphIndex(indexName); Preconditions.checkArgument(idx!=null,"Index could not be found: %s",indexName); isStable = true;
finishSchema(); TitanGraphIndex gindex = mgmt.getGraphIndex(name); gindex = mgmt.getGraphIndex(name); mgmt.updateIndex(gindex, SchemaAction.DISABLE_INDEX); mgmt.commit(); gindex = mgmt.getGraphIndex(name); mgmt.updateIndex(gindex, SchemaAction.REMOVE_INDEX); TitanManagement.IndexJobFuture gmetrics = mgmt.getIndexJobStatus(gindex);
@Test public void testRemoveGraphIndex() throws InterruptedException, BackendException, ExecutionException { tx.commit(); mgmt.commit(); // Load the "Graph of the Gods" sample data GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); // Disable the "name" composite index TitanManagement m = graph.openManagement(); TitanGraphIndex nameIndex = m.getGraphIndex("name"); m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX); m.commit(); graph.tx().commit(); // Block until the SchemaStatus transitions to DISABLED assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "name") .status(SchemaStatus.DISABLED).call().getSucceeded()); // Remove index MapReduceIndexManagement mri = new MapReduceIndexManagement(graph); m = graph.openManagement(); TitanGraphIndex index = m.getGraphIndex("name"); ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get(); assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT)); }
finishSchema(); try { mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); .call().getSucceeded()); finishSchema(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); finishSchema();
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), time, getFieldMap(time)); finishSchema(); newTx(); assertNull(mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX)); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REGISTER_INDEX).get(); mgmt.commit(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX).get(); finishSchema(); mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), height); if (indexFeatures.supportsCardinality(Cardinality.LIST)) { PropertyKey phone = mgmt.getPropertyKey("phone"); mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), phone, new Parameter("mapping", Mapping.STRING)); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); finishSchema(); TitanGraphIndex index = mgmt.getGraphIndex("theIndex"); for (PropertyKey key : index.getFieldKeys()) { assertEquals(SchemaStatus.ENABLED, index.getIndexStatus(key)); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REINDEX).get(); mgmt.commit(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.DISABLE_INDEX).get(); tx.commit();
mgmt.setConsistency(mgmt.getGraphIndex("uid"),ConsistencyModifier.LOCK); finishSchema();
TitanGraphIndex index = m.getGraphIndex("verticesByAge"); m.updateIndex(index, SchemaAction.ENABLE_INDEX); m.commit(); index = m.getGraphIndex("verticesByAge"); ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get(); assertEquals(6, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
gindex = mgmt.getGraphIndex("bySensorReading"); try { mgmt.updateIndex(pindex, SchemaAction.ENABLE_INDEX); gindex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.REGISTERED, pindex.getIndexStatus()); assertEquals(SchemaStatus.REGISTERED, eindex.getIndexStatus()); ScanMetrics reindexSensorByTime = mgmt.updateIndex(pindex, SchemaAction.REINDEX).get(); finishSchema(); gindex = mgmt.getGraphIndex("bySensorReading"); ScanMetrics reindexBySensorReading = mgmt.updateIndex(gindex, SchemaAction.REINDEX).get(); finishSchema(); gindex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.ENABLED, eindex.getIndexStatus()); assertEquals(SchemaStatus.ENABLED, pindex.getIndexStatus()); gindex = mgmt.getGraphIndex("bySensorReading"); mgmt.updateIndex(pindex, SchemaAction.DISABLE_INDEX); mgmt.updateIndex(gindex, SchemaAction.DISABLE_INDEX); gindex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.DISABLED, pindex.getIndexStatus()); assertEquals(SchemaStatus.DISABLED, gindex.getIndexStatus(gindex.getFieldKeys()[0])); finishSchema(); pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); gindex = mgmt.getGraphIndex("bySensorReading");
TitanGraphIndex gindex = mgmt.getGraphIndex("timeIndex"); mgmt.changeName(gindex, "byTime"); assertEquals("byTime", gindex.name());
assertEquals(1, sig.length); assertEquals(weight.longId(), sig[0]); assertTrue(mgmt.getGraphIndex(uid.name()).isUnique()); assertFalse(mgmt.getGraphIndex(someid.name()).isUnique()); assertEquals(1, sig.length); assertEquals(weight.longId(), sig[0]); assertTrue(mgmt.getGraphIndex(uid.name()).isUnique()); assertFalse(mgmt.getGraphIndex(someid.name()).isUnique());
mgmt.setConsistency(uid, ConsistencyModifier.LOCK); mgmt.setConsistency(name, ConsistencyModifier.LOCK); mgmt.setConsistency(mgmt.getGraphIndex("uid"), ConsistencyModifier.LOCK); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.SIMPLE).make(); EdgeLabel spouse = mgmt.makeEdgeLabel("spouse").multiplicity(Multiplicity.ONE2ONE).make();
if (mgmt.getGraphIndex(RESTAURANT_ID) == null) { final PropertyKey RESTAURANTIdKey = mgmt.makePropertyKey(RESTAURANT_ID).dataType(Integer.class).make(); mgmt.buildIndex(RESTAURANT_ID, Vertex.class).addKey(RESTAURANTIdKey).unique().buildCompositeIndex(); if (mgmt.getGraphIndex(USER_ID) == null) { final PropertyKey userKey = mgmt.makePropertyKey(USER_ID).dataType(String.class).make(); mgmt.buildIndex(USER_ID, Vertex.class).addKey(userKey).unique().buildCompositeIndex(); if (mgmt.getGraphIndex(GENRE) == null) { final PropertyKey genreKey = mgmt.makePropertyKey(GENRE).dataType(String.class).make(); mgmt.buildIndex(GENRE, Vertex.class).addKey(genreKey).unique().buildCompositeIndex();
@Override public AtlasGraphIndex getGraphIndex(String indexName) { TitanGraphIndex index = management.getGraphIndex(indexName); return GraphDbObjectFactory.createGraphIndex(index); }
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 (TitanProperty.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; }
@Test public void testIdCounts() { makeVertexIndexedUniqueKey("uid",Integer.class); mgmt.setConsistency(mgmt.getGraphIndex("uid"),ConsistencyModifier.LOCK); finishSchema(); //Schema and relation id pools are tapped, Schema id pool twice because the renew is triggered. Each id acquisition requires 1 mutations and 2 reads verifyStoreMetrics(ID_STORE_NAME, SYSTEM_METRICS, ImmutableMap.of(M_MUTATE, 3l, M_GET_SLICE, 6l)); }