use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RaftGroupManagerImpl method transferLeaderTo.
@Override
public String transferLeaderTo(String endpoint) {
PeerId peerId = PeerId.parsePeer(endpoint);
Status status = this.raftNode.node().transferLeadershipTo(peerId);
if (!status.isOk()) {
throw new BackendException("Failed to transfer leader to '%s', raft error: %s", endpoint, status.getErrorMsg());
}
return peerId.toString();
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RaftGroupManagerImpl method listPeers.
@Override
public List<String> listPeers() {
if (this.raftNode.selfIsLeader()) {
List<PeerId> peerIds = this.raftNode.node().listPeers();
return peerIds.stream().map(PeerId::toString).collect(Collectors.toList());
}
// If current node is not leader, forward request to leader
ListPeersRequest request = ListPeersRequest.getDefaultInstance();
try {
RaftClosure<ListPeersResponse> future;
future = this.forwardToLeader(request);
ListPeersResponse response = future.waitFinished();
return response.getEndpointsList();
} catch (Throwable e) {
throw new BackendException("Failed to list peers", e);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class BinarySerializer method parseProperty.
protected void parseProperty(Id pkeyId, BytesBuffer buffer, HugeElement owner) {
PropertyKey pkey = owner.graph().propertyKey(pkeyId);
// Parse value
Object value = buffer.readProperty(pkey);
// Set properties of vertex/edge
if (pkey.cardinality() == Cardinality.SINGLE) {
owner.addProperty(pkey, value);
} else {
if (!(value instanceof Collection)) {
throw new BackendException("Invalid value of non-single property: %s", value);
}
owner.addProperty(pkey, value);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class InMemoryDBTable method matchCondition.
private static boolean matchCondition(BackendEntry item, Condition c) {
// TODO: Compatible with BackendEntry
TextBackendEntry entry = (TextBackendEntry) item;
// Not supported by memory
if (!(c instanceof Condition.Relation)) {
throw new BackendException("Unsupported condition: " + c);
}
Condition.Relation r = (Condition.Relation) c;
String key = r.serialKey().toString();
// TODO: deal with others Relation like: <, >=, ...
if (r.relation() == Condition.RelationType.CONTAINS_KEY) {
return entry.contains(r.serialValue().toString());
} else if (r.relation() == Condition.RelationType.CONTAINS_VALUE) {
return entry.containsValue(r.serialValue().toString());
} else if (r.relation() == Condition.RelationType.EQ) {
return entry.contains(key, r.serialValue().toString());
} else if (entry.contains(key)) {
return r.test(entry.column(key));
}
return false;
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RaftBackendStore method queryByRaft.
private Object queryByRaft(Object query, boolean safeRead, Function<Object, Object> func) {
if (!safeRead) {
return func.apply(query);
}
RaftClosure<Object> future = new RaftClosure<>();
ReadIndexClosure readIndexClosure = new ReadIndexClosure() {
@Override
public void run(Status status, long index, byte[] reqCtx) {
if (status.isOk()) {
future.complete(status, () -> func.apply(query));
} else {
future.failure(status, new BackendException("Failed to do raft read-index: %s", status));
}
}
};
this.node().readIndex(BytesUtil.EMPTY_BYTES, readIndexClosure);
try {
return future.waitFinished();
} catch (Throwable e) {
LOG.warn("Failed to execute query '{}': {}", query, future.status(), e);
throw new BackendException("Failed to execute query: %s", e, query);
}
}
Aggregations