Search in sources :

Example 46 with BackendException

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

the class RaftNode method snapshot.

public void snapshot() {
    if (!this.context.useSnapshot()) {
        return;
    }
    RaftClosure<?> future = new RaftClosure<>();
    try {
        this.node().snapshot(future);
        future.waitFinished();
    } catch (Throwable e) {
        throw new BackendException("Failed to create snapshot", e);
    }
}
Also used : BackendException(com.baidu.hugegraph.backend.BackendException)

Example 47 with BackendException

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

the class RaftNode method waitStarted.

protected void waitStarted(int timeout) {
    String group = this.context.group();
    ReadIndexClosure readIndexClosure = new ReadIndexClosure() {

        @Override
        public void run(Status status, long index, byte[] reqCtx) {
            RaftNode.this.started.set(status.isOk());
        }
    };
    long beginTime = System.currentTimeMillis();
    while (true) {
        this.node.readIndex(BytesUtil.EMPTY_BYTES, readIndexClosure);
        if (this.started.get()) {
            break;
        }
        try {
            Thread.sleep(RaftSharedContext.POLL_INTERVAL);
        } catch (InterruptedException e) {
            LOG.info("Waiting for heartbeat is interrupted: {}", e);
        }
        long consumedTime = System.currentTimeMillis() - beginTime;
        if (timeout > 0 && consumedTime >= timeout) {
            throw new BackendException("Waiting for raft group '%s' heartbeat timeout(%sms)", group, consumedTime);
        }
        LOG.warn("Waiting for raft group '{}' heartbeat cost {}s", group, consumedTime / 1000.0);
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) ReadIndexClosure(com.alipay.sofa.jraft.closure.ReadIndexClosure) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 48 with BackendException

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

the class TextBackendEntry method copy.

public TextBackendEntry copy() {
    try {
        TextBackendEntry clone = (TextBackendEntry) this.clone();
        clone.columns = new ConcurrentSkipListMap<>(this.columns);
        return clone;
    } catch (CloneNotSupportedException e) {
        throw new BackendException(e);
    }
}
Also used : BackendException(com.baidu.hugegraph.backend.BackendException)

Example 49 with BackendException

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

the class TextBackendEntry method copyLast.

public TextBackendEntry copyLast(int count) {
    TextBackendEntry clone;
    try {
        clone = (TextBackendEntry) this.clone();
    } catch (CloneNotSupportedException e) {
        throw new BackendException(e);
    }
    clone.resetColumns();
    // Copy the last count columns
    Iterator<Entry<String, String>> it = this.columns.entrySet().iterator();
    final int skip = this.columns.size() - count;
    for (int i = 0; it.hasNext(); i++) {
        Entry<String, String> entry = it.next();
        if (i < skip) {
            continue;
        }
        clone.columns.put(entry.getKey(), entry.getValue());
    }
    return clone;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Entry(java.util.Map.Entry) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 50 with BackendException

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

the class AbstractSerializer method writeQuery.

@Override
public Query writeQuery(Query query) {
    HugeType type = query.resultType();
    // Serialize edge condition query (TODO: add VEQ(for EOUT/EIN))
    if (type.isEdge() && query.conditionsSize() > 0) {
        if (query.idsSize() > 0) {
            throw new BackendException("Not supported query edge by id " + "and by condition at the same time");
        }
        Query result = this.writeQueryEdgeCondition(query);
        if (result != null) {
            return result;
        }
    }
    // Serialize id in query
    if (query.idsSize() == 1 && query instanceof IdQuery.OneIdQuery) {
        IdQuery.OneIdQuery result = (IdQuery.OneIdQuery) query.copy();
        result.resetId(this.writeQueryId(type, result.id()));
        query = result;
    } else if (query.idsSize() > 0 && query instanceof IdQuery) {
        IdQuery result = (IdQuery) query.copy();
        result.resetIds();
        for (Id id : query.ids()) {
            result.query(this.writeQueryId(type, id));
        }
        query = result;
    }
    // Serialize condition(key/value) in query
    if (query instanceof ConditionQuery && query.conditionsSize() > 0) {
        query = this.writeQueryCondition(query);
    }
    return query;
}
Also used : IdQuery(com.baidu.hugegraph.backend.query.IdQuery) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

BackendException (com.baidu.hugegraph.backend.BackendException)79 SQLException (java.sql.SQLException)15 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)6 Status (com.alipay.sofa.jraft.Status)5 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)4 Path (java.nio.file.Path)4 Random (java.util.Random)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 RocksDBException (org.rocksdb.RocksDBException)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Id (com.baidu.hugegraph.backend.id.Id)3 Query (com.baidu.hugegraph.backend.query.Query)3 HugeConfig (com.baidu.hugegraph.config.HugeConfig)3 Map (java.util.Map)3 ReadIndexClosure (com.alipay.sofa.jraft.closure.ReadIndexClosure)2 Condition (com.baidu.hugegraph.backend.query.Condition)2 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)2