Search in sources :

Example 6 with ReadIndexRequest

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);
}
Also used : Status(com.alipay.sofa.jraft.Status) ReadIndexRequest(com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest)

Example 7 with ReadIndexRequest

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));
}
Also used : ReadIndexRequest(com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest) ReadIndexState(com.alipay.sofa.jraft.entity.ReadIndexState) ArrayList(java.util.ArrayList)

Aggregations

ReadIndexRequest (com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest)7 Status (com.alipay.sofa.jraft.Status)6 ReadIndexClosure (com.alipay.sofa.jraft.closure.ReadIndexClosure)5 ReadIndexStatus (com.alipay.sofa.jraft.entity.ReadIndexStatus)5 Test (org.junit.Test)5 ArgumentMatcher (org.mockito.ArgumentMatcher)5 RpcResponseClosure (com.alipay.sofa.jraft.rpc.RpcResponseClosure)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ReadIndexState (com.alipay.sofa.jraft.entity.ReadIndexState)1 ArrayList (java.util.ArrayList)1