Search in sources :

Example 46 with HugeException

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

the class GraphIndexTransaction method queryByLabel.

@Watched(prefix = "index")
private IdHolderList queryByLabel(ConditionQuery query) {
    HugeType queryType = query.resultType();
    IndexLabel il = IndexLabel.label(queryType);
    validateIndexLabel(il);
    Id label = query.condition(HugeKeys.LABEL);
    assert label != null;
    HugeType indexType;
    SchemaLabel schemaLabel;
    if (queryType.isVertex()) {
        indexType = HugeType.VERTEX_LABEL_INDEX;
        schemaLabel = this.graph().vertexLabel(label);
    } else if (queryType.isEdge()) {
        indexType = HugeType.EDGE_LABEL_INDEX;
        schemaLabel = this.graph().edgeLabel(label);
    } else {
        throw new HugeException("Can't query %s by label", queryType);
    }
    if (!this.store().features().supportsQueryByLabel() && !schemaLabel.enableLabelIndex()) {
        throw new NoIndexException("Don't accept query by label '%s', " + "label index is disabled", schemaLabel);
    }
    ConditionQuery indexQuery = new ConditionQuery(indexType, query);
    indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id());
    indexQuery.eq(HugeKeys.FIELD_VALUES, label);
    /*
         * We can avoid redundant element ids if set limit, but if there are
         * label index overridden by other vertices with different label,
         * query with limit like g.V().hasLabel('xx').limit(10) may lose some
         * results, so can't set limit here. But in this case, the following
         * query results may be still different:
         *   g.V().hasLabel('xx').count()  // label index count
         *   g.V().hasLabel('xx').limit(-1).count()  // actual vertices count
         * It’s a similar situation for the offset, like:
         *   g.V().hasLabel('xx').range(26, 27)
         *   g.V().hasLabel('xx').range(27, 28)
         * we just reset limit here, but don't reset offset due to performance
         * optimization with index+offset query, see Query.skipOffsetIfNeeded().
         * NOTE: if set offset the backend itself will skip the offset
         */
    indexQuery.copyBasic(query);
    indexQuery.limit(Query.NO_LIMIT);
    IdHolder idHolder = this.doIndexQuery(il, indexQuery);
    IdHolderList holders = new IdHolderList(query.paging());
    holders.add(idHolder);
    return holders;
}
Also used : NoIndexException(com.baidu.hugegraph.exception.NoIndexException) SortByCountIdHolderList(com.baidu.hugegraph.backend.page.SortByCountIdHolderList) IdHolderList(com.baidu.hugegraph.backend.page.IdHolderList) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IdHolder(com.baidu.hugegraph.backend.page.IdHolder) FixedIdHolder(com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder) PagingIdHolder(com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder) BatchIdHolder(com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType) HugeException(com.baidu.hugegraph.HugeException) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 47 with HugeException

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

the class AbstractComputer method call.

@Override
public Object call(Job<Object> job, Map<String, Object> parameters) {
    this.checkAndCollectParameters(parameters);
    // Read configuration
    try {
        this.initializeConfig((ComputerJob) job);
    } catch (Exception e) {
        throw new HugeException("Failed to initialize computer config file", e);
    }
    // Set current computer job's specified parameters
    Map<String, Object> configs = new HashMap<>();
    configs.putAll(this.commonConfig);
    configs.putAll(this.checkAndCollectParameters(parameters));
    // Construct shell command for computer job
    String[] command = this.constructShellCommands(configs);
    LOG.info("Execute computer job: {}", String.join(SPACE, command));
    // Execute current computer
    try {
        ProcessBuilder builder = new ProcessBuilder(command);
        builder.redirectErrorStream(true);
        builder.directory(new File(executeDir()));
        Process process = builder.start();
        StringBuilder output = new StringBuilder();
        try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(process.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                output.append(line).append("\n");
            }
        }
        int exitCode = process.waitFor();
        if (exitCode == 0) {
            return 0;
        }
        throw new HugeException("The computer job exit with code %s: %s", exitCode, output);
    } catch (HugeException e) {
        throw e;
    } catch (Throwable e) {
        throw new HugeException("Failed to execute computer job", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException) LineNumberReader(java.io.LineNumberReader) File(java.io.File)

Example 48 with HugeException

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

the class RamTable method loadFromDB.

private void loadFromDB() throws Exception {
    Query query = new Query(HugeType.VERTEX);
    query.capacity(this.verticesCapacityHalf * 2L);
    query.limit(Query.NO_LIMIT);
    Iterator<Vertex> vertices = this.graph.vertices(query);
    // switch concurrent loading here
    boolean concurrent = true;
    if (concurrent) {
        try (LoadTraverser traverser = new LoadTraverser()) {
            traverser.load(vertices);
        }
        return;
    }
    Iterator<Edge> adjEdges;
    Id lastId = IdGenerator.ZERO;
    while (vertices.hasNext()) {
        Id vertex = (Id) vertices.next().id();
        LOG.info("scan from hbase {} loadfromDB", vertex);
        if (vertex.compareTo(lastId) < 0) {
            throw new HugeException("The ramtable feature is not " + "supported by %s backend", this.graph.backend());
        }
        ensureNumberId(vertex);
        lastId = vertex;
        adjEdges = this.graph.adjacentEdges(vertex);
        if (adjEdges.hasNext()) {
            HugeEdge edge = (HugeEdge) adjEdges.next();
            this.addEdge(true, edge);
        }
        while (adjEdges.hasNext()) {
            HugeEdge edge = (HugeEdge) adjEdges.next();
            this.addEdge(false, edge);
        }
    }
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) HugeException(com.baidu.hugegraph.HugeException)

Example 49 with HugeException

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

the class RaftSharedContext method endpoint.

public PeerId endpoint() {
    PeerId endpoint = new PeerId();
    String endpointStr = this.config().get(CoreOptions.RAFT_ENDPOINT);
    if (!endpoint.parse(endpointStr)) {
        throw new HugeException("Failed to parse endpoint %s", endpointStr);
    }
    return endpoint;
}
Also used : HugeException(com.baidu.hugegraph.HugeException) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 50 with HugeException

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

the class IndexLabelBuilder method create.

/**
 * Create index label with sync mode
 */
@Override
public IndexLabel create() {
    // Create index label async
    SchemaElement.TaskWithSchema createdIndexLabel = this.createWithTask();
    Id task = createdIndexLabel.task();
    if (task == IdGenerator.ZERO) {
        /*
             * Task id will be IdGenerator.ZERO if creating index label
             * already exists or creating index label is for olap
             */
        return createdIndexLabel.indexLabel();
    }
    // Wait task completed (change to sync mode)
    HugeGraph graph = this.graph();
    long timeout = graph.option(CoreOptions.TASK_WAIT_TIMEOUT);
    try {
        graph.taskScheduler().waitUntilTaskCompleted(task, timeout);
    } catch (TimeoutException e) {
        throw new HugeException("Failed to wait index-creating task completed", e);
    }
    // Return index label without task-info
    return createdIndexLabel.indexLabel();
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException)

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