Java Code Examples for com.thinkaurelius.titan.core.schema.TitanManagement#getGraphIndex()

The following examples show how to use com.thinkaurelius.titan.core.schema.TitanManagement#getGraphIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 2
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testRepairGraphIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();

    // Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);

    // Create and enable a graph index on age
    TitanManagement m = graph.openManagement();
    PropertyKey age = m.getPropertyKey("age");
    m.buildIndex("verticesByAge", Vertex.class).addKey(age).buildCompositeIndex();
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to REGISTERED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge")
            .status(SchemaStatus.REGISTERED).call().getSucceeded());

    m = graph.openManagement();
    TitanGraphIndex index = m.getGraphIndex("verticesByAge");
    m.updateIndex(index, SchemaAction.ENABLE_INDEX);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to ENABLED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge")
            .status(SchemaStatus.ENABLED).call().getSucceeded());

    // Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
    assertFalse(graph.query().has("age", 10000).vertices().iterator().hasNext());

    // Repair
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    index = m.getGraphIndex("verticesByAge");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
    assertEquals(6, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));

    // Test the index
    Iterable<TitanVertex> hits = graph.query().has("age", 4500).vertices();
    assertNotNull(hits);
    assertEquals(1, Iterables.size(hits));
    TitanVertex v = Iterables.getOnlyElement(hits);
    assertNotNull(v);

    assertEquals("neptune", v.value("name"));
}
 
Example 3
Source File: GraphIndexStatusWatcher.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public GraphIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(graphIndexName, "Index name must not be null");
    Preconditions.checkNotNull(status, "Target status must not be null");

    Map<String, SchemaStatus> notConverged = new HashMap<>();
    Map<String, SchemaStatus> converged = new HashMap<>();
    TitanGraphIndex idx;

    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getGraphIndex(graphIndexName);
            for (PropertyKey pk : idx.getFieldKeys()) {
                SchemaStatus s = idx.getIndexStatus(pk);
                LOGGER.debug("Key {} has status {}", pk, s);
                if (!status.equals(s))
                    notConverged.put(pk.toString(), s);
                else
                    converged.put(pk.toString(), s);
            }
        } finally {
            if (null != mgmt)
                mgmt.rollback(); // Let an exception here propagate up the stack
        }

        String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
        if (!notConverged.isEmpty()) {
            LOGGER.info("Some key(s) on index {} do not currently have status {}: {}", graphIndexName, status, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), graphIndexName, status);
            return new GraphIndexStatusReport(true, graphIndexName, status, notConverged, converged, t.elapsed());
        }

        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);

        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} to converge on status {}",
                    timeout, graphIndexName, status);
            return new GraphIndexStatusReport(false, graphIndexName, status, notConverged, converged, t.elapsed());
        }
        notConverged.clear();
        converged.clear();

        Thread.sleep(poll.toMillis());
    }
}