本文整理汇总了Java中com.thinkaurelius.titan.core.schema.TitanManagement.getGraphIndex方法的典型用法代码示例。如果您正苦于以下问题:Java TitanManagement.getGraphIndex方法的具体用法?Java TitanManagement.getGraphIndex怎么用?Java TitanManagement.getGraphIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thinkaurelius.titan.core.schema.TitanManagement
的用法示例。
在下文中一共展示了TitanManagement.getGraphIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveGraphIndex
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
@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));
}
示例2: waitForCompletion
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
private static void waitForCompletion(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
String name = compositeIndex.name;
TitanGraphIndex graphIndex = mgmt.getGraphIndex(name);
PropertyKey propertyKey = graphIndex.getFieldKeys()[0];
// For composite indexes, the propertyKey is ignored and the status of the index as a whole is returned
if (!SchemaStatus.ENABLED.equals(graphIndex.getIndexStatus(propertyKey))) {
try {
GraphIndexStatusReport report = ManagementSystem.awaitGraphIndexStatus(titanGraph, name).call();
LOG.info("report={}", report);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
示例3: testRepairGraphIndex
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
@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"));
}
示例4: call
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
@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());
}
}
示例5: awaitGraphIndexStatus
import com.thinkaurelius.titan.core.schema.TitanManagement; //导入方法依赖的package包/类
/**
* Do not use this method. This may be removed or refactored in future Titan versions.
*
* Final API pending resolution of https://github.com/thinkaurelius/titan/issues/709.
*
*/
public static boolean awaitGraphIndexStatus(TitanGraph g, String indexName, SchemaStatus status, long timeout, TimeUnit timeoutUnit) {
Preconditions.checkNotNull(g);
Preconditions.checkNotNull(indexName);
Preconditions.checkNotNull(status);
Preconditions.checkArgument(0L <= timeout);
Preconditions.checkNotNull(timeoutUnit);
Map<PropertyKey, SchemaStatus> notConverged = new HashMap<PropertyKey, SchemaStatus>();
Map<PropertyKey, SchemaStatus> converged = new HashMap<PropertyKey, SchemaStatus>();
TitanGraphIndex idx;
Timer t = new Timer(Timestamps.MILLI).start();
boolean timedOut;
while (true) {
TitanManagement mgmt = g.getManagementSystem();
idx = mgmt.getGraphIndex(indexName);
for (PropertyKey pk : idx.getFieldKeys()) {
SchemaStatus s = idx.getIndexStatus(pk);
LOGGER.debug("Key {} has status {}", pk, s);
if (!status.equals(s))
notConverged.put(pk, s);
else
converged.put(pk, s);
}
/* Rollback must follow the Joiner...(notConverged). The Joiner calls toString on
* PropertyKeys, and the current implementation calls the getName method on the key,
* and this expects the attached transaction to be open and usable to read the name.
* Rolling back or committing the managementsystem before calling getName results
* in an IllegalStateException in the guts of Joiner calling toString on a key.
*/
String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
mgmt.rollback();
if (!notConverged.isEmpty()) {
LOGGER.info("Some key(s) on index {} do not currently have status {}: ", indexName, status, waitingOn);
} else {
LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), indexName, status);
return true;
}
timedOut = timeout <= t.elapsed().getLength(timeoutUnit);
if (timedOut) {
LOGGER.info("Timed out ({} {}) while waiting for index {} to converge on status {}",
timeout, timeoutUnit, indexName, status);
return false;
}
notConverged.clear();
converged.clear();
}
}