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

The following examples show how to use com.thinkaurelius.titan.core.schema.TitanManagement#rollback() . 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: SchemaContainer.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 2
Source File: Titan1Graph.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public Titan1Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan1GraphDatabase.getGraphInstance().openManagement();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = new HashSet<>();
        for (PropertyKey key : keys) {
            if (key.cardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.name());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example 3
Source File: Titan0Graph.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public Titan0Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = Collections.synchronizedSet(new HashSet<String>());
        for(PropertyKey key : keys) {
            if (key.getCardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.getName());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example 4
Source File: RelationIndexStatusWatcher.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
/**
 * 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(status, "Target status must not be null");

    RelationTypeIndex idx;

    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        SchemaStatus actualStatus = null;
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), relationIndexName);
            actualStatus = idx.getIndexStatus();
            LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
            if (status.equals(actualStatus)) {
                return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, status, t.elapsed());
            }
        } finally {
            if (null != mgmt)
                mgmt.rollback(); // Let an exception here propagate up the stack
        }

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

        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status {}",
                    timeout, relationIndexName, relationTypeName, status);
            return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, status, t.elapsed());
        }

        Thread.sleep(poll.toMillis());
    }
}
 
Example 5
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());
    }
}