Search in sources :

Example 1 with HugeException

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

the class SmartCNAnalyzer method segment.

@Override
public Set<String> segment(String text) {
    Set<String> result = InsertionOrderUtil.newSet();
    Reader reader = new StringReader(text);
    try (TokenStream tokenStream = ANALYZER.tokenStream("text", reader)) {
        tokenStream.reset();
        CharTermAttribute term = null;
        while (tokenStream.incrementToken()) {
            term = tokenStream.getAttribute(CharTermAttribute.class);
            result.add(term.toString());
        }
    } catch (Exception e) {
        throw new HugeException("SmartCN segment text '%s' failed", e, text);
    }
    return result;
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException)

Example 2 with HugeException

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

the class PageInfo method fromBytes.

public static PageInfo fromBytes(byte[] bytes) {
    if (bytes.length == 0) {
        // The first page
        return new PageInfo(0, PAGE_NONE);
    }
    try {
        BytesBuffer buffer = BytesBuffer.wrap(bytes);
        int offset = buffer.readInt();
        byte[] pageState = buffer.readBytes();
        String page = PageState.toString(pageState);
        return new PageInfo(offset, page);
    } catch (Exception e) {
        throw new HugeException("Invalid page: '0x%s'", e, Bytes.toHex(bytes));
    }
}
Also used : BytesBuffer(com.baidu.hugegraph.backend.serializer.BytesBuffer) HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException)

Example 3 with HugeException

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

the class HugeTask method syncWait.

public void syncWait() {
    // This method is just called by tests
    HugeTask<?> task = null;
    try {
        task = this.scheduler().waitUntilTaskCompleted(this.id());
    } catch (Throwable e) {
        if (this.callable() instanceof EphemeralJob && e.getClass() == NotFoundException.class && e.getMessage().contains("Can't find task with id")) {
            /*
                 * The task with EphemeralJob won't saved in backends and
                 * will be removed from memory when completed
                 */
            return;
        }
        throw new HugeException("Failed to wait for task '%s' completed", e, this.id);
    }
    assert task != null;
    /*
         * This can be enabled for debug to expose schema-clear errors early,
         * but also lead to some negative tests failed,
         */
    boolean debugTest = false;
    if (debugTest && !task.success()) {
        throw new HugeException("Task '%s' is failed with error: %s", task.id(), task.result());
    }
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) EphemeralJob(com.baidu.hugegraph.job.EphemeralJob) HugeException(com.baidu.hugegraph.HugeException)

Example 4 with HugeException

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

the class TaskManager method shutdown.

public void shutdown(long timeout) {
    assert this.schedulers.isEmpty() : this.schedulers.size();
    Throwable ex = null;
    boolean terminated = this.schedulerExecutor.isTerminated();
    final TimeUnit unit = TimeUnit.SECONDS;
    if (!this.schedulerExecutor.isShutdown()) {
        this.schedulerExecutor.shutdown();
        try {
            terminated = this.schedulerExecutor.awaitTermination(timeout, unit);
        } catch (Throwable e) {
            ex = e;
        }
    }
    if (terminated && !this.taskExecutor.isShutdown()) {
        this.taskExecutor.shutdown();
        try {
            terminated = this.taskExecutor.awaitTermination(timeout, unit);
        } catch (Throwable e) {
            ex = e;
        }
    }
    if (terminated && !this.serverInfoDbExecutor.isShutdown()) {
        this.serverInfoDbExecutor.shutdown();
        try {
            terminated = this.serverInfoDbExecutor.awaitTermination(timeout, unit);
        } catch (Throwable e) {
            ex = e;
        }
    }
    if (terminated && !this.taskDbExecutor.isShutdown()) {
        this.taskDbExecutor.shutdown();
        try {
            terminated = this.taskDbExecutor.awaitTermination(timeout, unit);
        } catch (Throwable e) {
            ex = e;
        }
    }
    if (!terminated) {
        ex = new TimeoutException(timeout + "s");
    }
    if (ex != null) {
        throw new HugeException("Failed to wait for TaskScheduler", ex);
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with HugeException

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

the class KoutTraverser method kout.

public Set<Id> kout(Id sourceV, Directions dir, String label, int depth, boolean nearest, long degree, long capacity, long limit) {
    E.checkNotNull(sourceV, "source vertex id");
    this.checkVertexExist(sourceV, "source vertex");
    E.checkNotNull(dir, "direction");
    checkPositive(depth, "k-out max_depth");
    checkDegree(degree);
    checkCapacity(capacity);
    checkLimit(limit);
    if (capacity != NO_LIMIT) {
        // Capacity must > limit because sourceV is counted in capacity
        E.checkArgument(capacity >= limit && limit != NO_LIMIT, "Capacity can't be less than limit, " + "but got capacity '%s' and limit '%s'", capacity, limit);
    }
    Id labelId = this.getEdgeLabelId(label);
    Set<Id> latest = newIdSet();
    latest.add(sourceV);
    Set<Id> all = newIdSet();
    all.add(sourceV);
    long remaining = capacity == NO_LIMIT ? NO_LIMIT : capacity - latest.size();
    while (depth-- > 0) {
        // Just get limit nodes in last layer if limit < remaining capacity
        if (depth == 0 && limit != NO_LIMIT && (limit < remaining || remaining == NO_LIMIT)) {
            remaining = limit;
        }
        if (nearest) {
            latest = this.adjacentVertices(sourceV, latest, dir, labelId, all, degree, remaining);
            all.addAll(latest);
        } else {
            latest = this.adjacentVertices(sourceV, latest, dir, labelId, null, degree, remaining);
        }
        if (capacity != NO_LIMIT) {
            // Update 'remaining' value to record remaining capacity
            remaining -= latest.size();
            if (remaining <= 0 && depth > 0) {
                throw new HugeException("Reach capacity '%s' while remaining depth '%s'", capacity, depth);
            }
        }
    }
    return latest;
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) 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