Search in sources :

Example 26 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class GraphTransaction method removeVertices.

public void removeVertices(VertexLabel vertexLabel) {
    if (this.hasUpdate()) {
        throw new HugeException("There are still changes to commit");
    }
    boolean autoCommit = this.autoCommit();
    this.autoCommit(false);
    // Commit data already in tx firstly
    this.commit();
    try {
        this.traverseVerticesByLabel(vertexLabel, vertex -> {
            this.removeVertex((HugeVertex) vertex);
            this.commitIfGtSize(COMMIT_BATCH);
        }, true);
        this.commit();
    } catch (Exception e) {
        LOG.error("Failed to remove vertices", e);
        throw new HugeException("Failed to remove vertices", e);
    } finally {
        this.autoCommit(autoCommit);
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException) BackendException(com.baidu.hugegraph.backend.BackendException) LimitExceedException(com.baidu.hugegraph.exception.LimitExceedException) ForbiddenException(jakarta.ws.rs.ForbiddenException) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeException(com.baidu.hugegraph.HugeException)

Example 27 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class GraphTransaction method checkVertexExistIfCustomizedId.

private void checkVertexExistIfCustomizedId(Map<Id, HugeVertex> vertices) {
    Set<Id> ids = new HashSet<>();
    for (HugeVertex vertex : vertices.values()) {
        VertexLabel vl = vertex.schemaLabel();
        if (!vl.hidden() && vl.idStrategy().isCustomized()) {
            ids.add(vertex.id());
        }
    }
    if (ids.isEmpty()) {
        return;
    }
    IdQuery idQuery = new IdQuery(HugeType.VERTEX, ids);
    Iterator<HugeVertex> results = this.queryVerticesFromBackend(idQuery);
    try {
        if (!results.hasNext()) {
            return;
        }
        HugeVertex existedVertex = results.next();
        HugeVertex newVertex = vertices.get(existedVertex.id());
        if (!existedVertex.label().equals(newVertex.label())) {
            throw new HugeException("The newly added vertex with id:'%s' label:'%s' " + "is not allowed to insert, because already exist " + "a vertex with same id and different label:'%s'", newVertex.id(), newVertex.label(), existedVertex.label());
        }
    } finally {
        CloseableIterator.closeIterator(results);
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) HugeException(com.baidu.hugegraph.HugeException) HashSet(java.util.HashSet)

Example 28 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class GraphTransaction method verifyEdgesConditionQuery.

private static void verifyEdgesConditionQuery(ConditionQuery query) {
    assert query.resultType().isEdge();
    int total = query.conditionsSize();
    if (total == 1) {
        /*
             * Supported query:
             *  1.query just by edge label
             *  2.query just by PROPERTIES (like containsKey,containsValue)
             *  3.query with scan
             */
        if (query.containsCondition(HugeKeys.LABEL) || query.containsCondition(HugeKeys.PROPERTIES) || query.containsScanRelation()) {
            return;
        }
    }
    int matched = 0;
    for (HugeKeys key : EdgeId.KEYS) {
        Object value = query.condition(key);
        if (value == null) {
            break;
        }
        matched++;
    }
    int count = matched;
    if (query.containsCondition(HugeKeys.PROPERTIES)) {
        matched++;
        if (count < 3 && query.containsCondition(HugeKeys.LABEL)) {
            matched++;
        }
    }
    if (matched != total) {
        throw new HugeException("Not supported querying edges by %s, expect %s", query.conditions(), EdgeId.KEYS[count]);
    }
}
Also used : HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) HugeException(com.baidu.hugegraph.HugeException)

Example 29 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class RamTable method reload.

public void reload(boolean loadFromFile, String file) {
    if (this.loading) {
        throw new HugeException("There is one loading task, " + "please wait for it to complete");
    }
    this.loading = true;
    try {
        this.reset();
        if (loadFromFile) {
            this.loadFromFile(file);
        } else {
            this.loadFromDB();
            if (file != null) {
                LOG.info("Export graph to file '{}'", file);
                if (!this.exportToFile(file)) {
                    LOG.warn("Can't export graph to file '{}'", file);
                }
            }
        }
        LOG.info("Loaded {} edges", this.edgesSize());
    } catch (Throwable e) {
        this.reset();
        throw new HugeException("Failed to load ramtable", e);
    } finally {
        this.loading = false;
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException)

Example 30 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class API method commit.

public static <R> R commit(HugeGraph g, Callable<R> callable) {
    Consumer<Throwable> rollback = (error) -> {
        if (error != null) {
            LOG.error("Failed to commit", error);
        }
        try {
            g.tx().rollback();
        } catch (Throwable e) {
            LOG.error("Failed to rollback", e);
        }
    };
    try {
        R result = callable.call();
        g.tx().commit();
        SUCCEED_METER.mark();
        return result;
    } catch (IllegalArgumentException | NotFoundException | ForbiddenException e) {
        ILLEGAL_ARG_ERROR_METER.mark();
        rollback.accept(null);
        throw e;
    } catch (RuntimeException e) {
        EXPECTED_ERROR_METER.mark();
        rollback.accept(e);
        throw e;
    } catch (Throwable e) {
        UNKNOWN_ERROR_METER.mark();
        rollback.accept(e);
        // TODO: throw the origin exception 'e'
        throw new HugeException("Failed to commit", e);
    }
}
Also used : NotFoundException(jakarta.ws.rs.NotFoundException) NotSupportedException(jakarta.ws.rs.NotSupportedException) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Callable(java.util.concurrent.Callable) ForbiddenException(jakarta.ws.rs.ForbiddenException) Consumer(java.util.function.Consumer) HugeException(com.baidu.hugegraph.HugeException) RestServer(com.baidu.hugegraph.server.RestServer) Meter(com.codahale.metrics.Meter) Log(com.baidu.hugegraph.util.Log) Checkable(com.baidu.hugegraph.define.Checkable) MetricsUtil(com.baidu.hugegraph.metrics.MetricsUtil) JsonUtil(com.baidu.hugegraph.util.JsonUtil) MediaType(jakarta.ws.rs.core.MediaType) HugeGraph(com.baidu.hugegraph.HugeGraph) Map(java.util.Map) E(com.baidu.hugegraph.util.E) GraphManager(com.baidu.hugegraph.core.GraphManager) ForbiddenException(jakarta.ws.rs.ForbiddenException) NotFoundException(jakarta.ws.rs.NotFoundException) HugeException(com.baidu.hugegraph.HugeException)

Aggregations

HugeException (com.baidu.hugegraph.HugeException)59 Id (com.baidu.hugegraph.backend.id.Id)11 TimeoutException (java.util.concurrent.TimeoutException)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)4 File (java.io.File)4 Map (java.util.Map)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 ConfigException (com.baidu.hugegraph.config.ConfigException)3 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)3 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)3 StringReader (java.io.StringReader)3 PeerId (com.alipay.sofa.jraft.entity.PeerId)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)2 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)2