use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandResponse in project incubator-hugegraph by apache.
the class RpcForwarder method forwardToLeader.
public void forwardToLeader(PeerId leaderId, StoreCommand command, RaftStoreClosure future) {
E.checkNotNull(leaderId, "leader id");
E.checkState(!leaderId.equals(this.nodeId), "Invalid state: current node is the leader, there is " + "no need to forward the request");
LOG.debug("The node {} forward request to leader {}", this.nodeId, leaderId);
StoreCommandRequest.Builder builder = StoreCommandRequest.newBuilder();
builder.setType(command.type());
builder.setAction(command.action());
builder.setData(ZeroByteStringHelper.wrap(command.data()));
StoreCommandRequest request = builder.build();
RpcResponseClosure<StoreCommandResponse> responseClosure;
responseClosure = new RpcResponseClosure<StoreCommandResponse>() {
@Override
public void setResponse(StoreCommandResponse response) {
if (response.getStatus()) {
LOG.debug("StoreCommandResponse status ok");
future.complete(Status.OK(), () -> null);
} else {
LOG.debug("StoreCommandResponse status error");
Status status = new Status(RaftError.UNKNOWN, "fowared request failed");
BackendException e = new BackendException("Current node isn't leader, leader " + "is [%s], failed to forward request " + "to leader: %s", leaderId, response.getMessage());
future.failure(status, e);
}
}
@Override
public void run(Status status) {
future.run(status);
}
};
this.waitRpc(leaderId.getEndpoint(), request, responseClosure);
}
Aggregations