use of com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest in project sofa-jraft by sofastack.
the class NodeImpl method readFollower.
private void readFollower(final ReadIndexRequest request, final RpcResponseClosure<ReadIndexResponse> closure) {
if (this.leaderId == null || this.leaderId.isEmpty()) {
closure.run(new Status(RaftError.EPERM, "No leader at term %d.", this.currTerm));
return;
}
// send request to leader.
final ReadIndexRequest newRequest = //
ReadIndexRequest.newBuilder().mergeFrom(//
request).setPeerId(//
this.leaderId.toString()).build();
this.rpcService.readIndex(this.leaderId.getEndpoint(), newRequest, -1, closure);
}
use of com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest in project sofa-jraft by sofastack.
the class ReadOnlyServiceImpl method executeReadIndexEvents.
private void executeReadIndexEvents(final List<ReadIndexEvent> events) {
if (events.isEmpty()) {
return;
}
final ReadIndexRequest.Builder rb = //
ReadIndexRequest.newBuilder().setGroupId(//
this.node.getGroupId()).setServerId(this.node.getServerId().toString());
final List<ReadIndexState> states = new ArrayList<>(events.size());
for (final ReadIndexEvent event : events) {
rb.addEntries(ZeroByteStringHelper.wrap(event.requestContext.get()));
states.add(new ReadIndexState(event.requestContext, event.done, event.startTime));
}
final ReadIndexRequest request = rb.build();
this.node.handleReadIndexRequest(request, new ReadIndexResponseClosure(states, request));
}
Aggregations