use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class GraphIndexStatusWatcher method call.
@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(statuses, "Target statuses must not be null");
Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
Map<String, SchemaStatus> notConverged = new HashMap<>();
Map<String, SchemaStatus> converged = new HashMap<>();
JanusGraphIndex idx;
Timer t = new Timer(TimestampProviders.MILLI).start();
boolean timedOut;
while (true) {
JanusGraphManagement management = null;
try {
management = g.openManagement();
idx = management.getGraphIndex(graphIndexName);
for (PropertyKey pk : idx.getFieldKeys()) {
SchemaStatus s = idx.getIndexStatus(pk);
LOGGER.debug("Key {} has status {}", pk, s);
if (!statuses.contains(s))
notConverged.put(pk.toString(), s);
else
converged.put(pk.toString(), s);
}
} finally {
if (null != management)
// Let an exception here propagate up the stack
management.rollback();
}
String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
if (!notConverged.isEmpty()) {
LOGGER.info("Some key(s) on index {} do not currently have status(es) {}: {}", graphIndexName, statuses, waitingOn);
} else {
LOGGER.info("All {} key(s) on index {} have status(es) {}", converged.size(), graphIndexName, statuses);
return new GraphIndexStatusReport(true, graphIndexName, statuses, 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(es) {}", timeout, graphIndexName, statuses);
return new GraphIndexStatusReport(false, graphIndexName, statuses, notConverged, converged, t.elapsed());
}
notConverged.clear();
converged.clear();
Thread.sleep(poll.toMillis());
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class RelationIndexStatusWatcher method call.
/**
* Poll a relation index until it has a certain {@link SchemaStatus},
* or until a configurable timeout is exceeded.
*
* @return a report with information about schema state, execution duration, and the index
*/
@Override
public RelationIndexStatusReport call() throws InterruptedException {
Preconditions.checkNotNull(g, "Graph instance must not be null");
Preconditions.checkNotNull(relationIndexName, "Index name must not be null");
Preconditions.checkNotNull(statuses, "Target statuses must not be null");
Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
RelationTypeIndex idx;
Timer t = new Timer(TimestampProviders.MILLI).start();
boolean timedOut;
while (true) {
final SchemaStatus actualStatus;
JanusGraphManagement management = null;
try {
management = g.openManagement();
idx = management.getRelationIndex(management.getRelationType(relationTypeName), relationIndexName);
actualStatus = idx.getIndexStatus();
LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
if (statuses.contains(actualStatus)) {
return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
}
} finally {
if (null != management)
// Let an exception here propagate up the stack
management.rollback();
}
timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
if (timedOut) {
LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status(es) {}", timeout, relationIndexName, relationTypeName, statuses);
return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
}
Thread.sleep(poll.toMillis());
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class JanusGraphApp method createSchema.
@Override
public void createSchema() {
final JanusGraphManagement management = getJanusGraph().openManagement();
try {
// naive check if the schema was previously created
if (management.getRelationTypes(RelationType.class).iterator().hasNext()) {
management.rollback();
return;
}
LOGGER.info("creating schema");
createProperties(management);
createVertexLabels(management);
createEdgeLabels(management);
createCompositeIndexes(management);
createMixedIndexes(management);
management.commit();
} catch (Exception e) {
management.rollback();
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class AbstractIndexManagementIT method testRemoveGraphIndex.
@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
JanusGraphManagement m = graph.openManagement();
JanusGraphIndex 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();
JanusGraphIndex index = m.getGraphIndex("name");
ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get();
assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class AbstractJanusGraphProvider method loadGraphData.
@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
if (loadGraphWith != null) {
this.createIndices((JanusGraph) g, loadGraphWith.value());
} else {
if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
JanusGraphManagement management = ((JanusGraph) g).openManagement();
management.makePropertyKey("blah").dataType(Double.class).make();
management.makePropertyKey("bloop").dataType(Integer.class).make();
management.makePropertyKey("test").dataType(Object.class).make();
management.makeEdgeLabel("friend").make();
management.commit();
}
}
super.loadGraphData(g, loadGraphWith, testClass, testName);
}
Aggregations