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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations