public JanusGraphIndex 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 (JanusGraphVertexProperty.class.isAssignableFrom(clazz)) prefix = "p"; else throw new AssertionError(clazz.toString()); final String indexName = prefix+backingIndex; JanusGraphIndex index = mgmt.getGraphIndex(indexName); if (index==null) { index = mgmt.buildIndex(indexName,clazz).buildMixedIndex(backingIndex); } return index; }
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 { management = g.openManagement(); idx = management.getGraphIndex(graphIndexName); for (PropertyKey pk : idx.getFieldKeys()) { SchemaStatus s = idx.getIndexStatus(pk);
@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(getConfig().get(IDS_STORE_NAME), SYSTEM_METRICS, ImmutableMap.of(M_MUTATE, 3L, M_GET_SLICE, 6L)); }
isStable = idx.getIndexStatus().isStable(); } else { JanusGraphIndex idx = management.getGraphIndex(indexName); Preconditions.checkArgument(idx!=null,"Index could not be found: %s",indexName); isStable = true;
@Test public void shouldAwaitMultipleStatuses() throws InterruptedException, ExecutionException { final PropertyKey key1 = makeKey("key1", String.class); final JanusGraphIndex index = mgmt.buildIndex("randomMixedIndex", Vertex.class).addKey(key1).buildMixedIndex(INDEX); if (index.getIndexStatus(key1) == SchemaStatus.INSTALLED) { mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.REGISTER_INDEX).get(); mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.ENABLE_INDEX).get(); } else if (index.getIndexStatus(key1) == SchemaStatus.REGISTERED) { mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.ENABLE_INDEX).get(); } final PropertyKey key2 = makeKey("key2", String.class); mgmt.addIndexKey(index, key2); mgmt.commit(); //key1 now has status ENABLED, let's ensure we can watch for REGISTERED and ENABLED try { ManagementSystem.awaitGraphIndexStatus(graph, "randomMixedIndex").status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call(); } catch (final Exception e) { Assert.fail("Failed to awaitGraphIndexStatus on multiple statuses."); } }
private void createIndexIfDoesNotExist(String indexName, String propertyKeyName, Class dataType,boolean unique) { graph.tx().rollback(); JanusGraphManagement management = graph.openManagement(); if (null == management.getGraphIndex(indexName)) { final PropertyKey key; boolean propertyKeyAlreadyExisted = false; management = graph.openManagement(); if (propertyKeyAlreadyExisted) { management.updateIndex(management.getGraphIndex(indexName), REINDEX).get(); } else { management.updateIndex(management.getGraphIndex(indexName), ENABLE_INDEX).get(); management.updateIndex(management.getGraphIndex(indexName), REINDEX).get(); } else { management.updateIndex(management.getGraphIndex(indexName), ENABLE_INDEX).get();
finishSchema(); JanusGraphIndex graphIndex = mgmt.getGraphIndex(name); graphIndex = mgmt.getGraphIndex(name); mgmt.updateIndex(graphIndex, SchemaAction.DISABLE_INDEX); mgmt.commit(); graphIndex = mgmt.getGraphIndex(name); mgmt.updateIndex(graphIndex, SchemaAction.REMOVE_INDEX); JanusGraphManagement.IndexJobFuture graphMetrics = mgmt.getIndexJobStatus(graphIndex);
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyWithoutLabelConstraint() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexShouldBeEnabledForExistingPropertyKeyAndConstrainedToNewVertexLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); VertexLabel newLabel = mgmt.makeVertexLabel("newLabel").make(); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).indexOnly(newLabel).buildCompositeIndex(); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexShouldBeEnabledForExistingPropertyKeyAndConstrainedToNewEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel newLabel = mgmt.makeEdgeLabel("newLabel").make(); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(newLabel).buildCompositeIndex(); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyAndConstrainedToExistingEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("alreadyExistingLabel").make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel existingLabel = mgmt.getEdgeLabel("alreadyExistingLabel"); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(existingLabel).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyAndConstrainedToExistingVertexLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeVertexLabel("alreadyExistingLabel").make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); VertexLabel existingLabel = mgmt.getVertexLabel("alreadyExistingLabel"); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).indexOnly(existingLabel).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
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)) { final 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(); JanusGraphIndex index = mgmt.getGraphIndex("theIndex"); for (final 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.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); .call().getSucceeded()); finishSchema(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); finishSchema();
mgmt.setConsistency(mgmt.getGraphIndex("uid"),ConsistencyModifier.LOCK); finishSchema();
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();
JanusGraphIndex graphIndex = mgmt.getGraphIndex("timeIndex"); mgmt.changeName(graphIndex, "byTime"); assertEquals("byTime", graphIndex.name());
graphIndex = mgmt.getGraphIndex("bySensorReading"); try { mgmt.updateIndex(pindex, SchemaAction.ENABLE_INDEX); graphIndex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.REGISTERED, pindex.getIndexStatus()); assertEquals(SchemaStatus.REGISTERED, eindex.getIndexStatus()); ScanMetrics reindexSensorByTime = mgmt.updateIndex(pindex, SchemaAction.REINDEX).get(); finishSchema(); graphIndex = mgmt.getGraphIndex("bySensorReading"); ScanMetrics reindexBySensorReading = mgmt.updateIndex(graphIndex, SchemaAction.REINDEX).get(); finishSchema(); graphIndex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.ENABLED, eindex.getIndexStatus()); assertEquals(SchemaStatus.ENABLED, pindex.getIndexStatus()); graphIndex = mgmt.getGraphIndex("bySensorReading"); mgmt.updateIndex(pindex, SchemaAction.DISABLE_INDEX); mgmt.updateIndex(graphIndex, SchemaAction.DISABLE_INDEX); graphIndex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.DISABLED, pindex.getIndexStatus()); assertEquals(SchemaStatus.DISABLED, graphIndex.getIndexStatus(graphIndex.getFieldKeys()[0])); finishSchema(); pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); graphIndex = mgmt.getGraphIndex("bySensorReading");