Search in sources :

Example 1 with ReadIndexState

use of io.dingodb.raft.entity.ReadIndexState in project dingo by dingodb.

the class ReadOnlyServiceImpl method notifySuccess.

private void notifySuccess(final ReadIndexStatus status) {
    final long nowMs = Utils.monotonicMs();
    final List<ReadIndexState> states = status.getStates();
    final int taskCount = states.size();
    for (int i = 0; i < taskCount; i++) {
        final ReadIndexState task = states.get(i);
        // stack copy
        final ReadIndexClosure done = task.getDone();
        if (done != null) {
            this.nodeMetrics.recordLatency("read-index", nowMs - task.getStartTimeMs());
            done.setResult(task.getIndex(), task.getRequestContext().get());
            done.run(Status.OK());
        }
    }
}
Also used : ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) ReadIndexState(io.dingodb.raft.entity.ReadIndexState)

Example 2 with ReadIndexState

use of io.dingodb.raft.entity.ReadIndexState in project dingo by dingodb.

the class ReadOnlyServiceImpl method executeReadIndexEvents.

private void executeReadIndexEvents(final List<ReadIndexEvent> events) {
    if (events.isEmpty()) {
        return;
    }
    final RpcRequests.ReadIndexRequest.Builder rb = // 
    RpcRequests.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 RpcRequests.ReadIndexRequest request = rb.build();
    this.node.handleReadIndexRequest(request, new ReadIndexResponseClosure(states, request));
}
Also used : ReadIndexState(io.dingodb.raft.entity.ReadIndexState) ArrayList(java.util.ArrayList) RpcRequests(io.dingodb.raft.rpc.RpcRequests)

Example 3 with ReadIndexState

use of io.dingodb.raft.entity.ReadIndexState in project dingo by dingodb.

the class ReadOnlyServiceImpl method reportError.

private void reportError(final ReadIndexStatus status, final Status st) {
    final long nowMs = Utils.monotonicMs();
    final List<ReadIndexState> states = status.getStates();
    final int taskCount = states.size();
    for (int i = 0; i < taskCount; i++) {
        final ReadIndexState task = states.get(i);
        final ReadIndexClosure done = task.getDone();
        if (done != null) {
            this.nodeMetrics.recordLatency("read-index", nowMs - task.getStartTimeMs());
            done.run(st);
        }
    }
}
Also used : ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) ReadIndexState(io.dingodb.raft.entity.ReadIndexState)

Aggregations

ReadIndexState (io.dingodb.raft.entity.ReadIndexState)3 ReadIndexClosure (io.dingodb.raft.closure.ReadIndexClosure)2 RpcRequests (io.dingodb.raft.rpc.RpcRequests)1 ArrayList (java.util.ArrayList)1