Search in sources :

Example 1 with ReadIndexState

use of org.apache.ignite.raft.jraft.entity.ReadIndexState in project ignite-3 by apache.

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(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) ReadIndexState(org.apache.ignite.raft.jraft.entity.ReadIndexState)

Example 2 with ReadIndexState

use of org.apache.ignite.raft.jraft.entity.ReadIndexState in project ignite-3 by apache.

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(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) ReadIndexState(org.apache.ignite.raft.jraft.entity.ReadIndexState)

Example 3 with ReadIndexState

use of org.apache.ignite.raft.jraft.entity.ReadIndexState in project ignite-3 by apache.

the class ReadOnlyServiceTest method testOnApplied.

@Test
public void testOnApplied() throws Exception {
    final ArrayList<ReadIndexState> states = new ArrayList<>();
    final byte[] reqContext = TestUtils.getRandomBytes();
    final CountDownLatch latch = new CountDownLatch(1);
    final ReadIndexState state = new ReadIndexState(new Bytes(reqContext), new ReadIndexClosure() {

        @Override
        public void run(final Status status, final long index, final byte[] reqCtx) {
            assertTrue(status.isOk());
            assertEquals(index, 1);
            assertArrayEquals(reqCtx, reqContext);
            latch.countDown();
        }
    }, Utils.monotonicMs());
    state.setIndex(1);
    states.add(state);
    final ReadIndexStatus readIndexStatus = new ReadIndexStatus(states, null, 1);
    this.readOnlyServiceImpl.getPendingNotifyStatus().put(1L, Arrays.asList(readIndexStatus));
    this.readOnlyServiceImpl.onApplied(2);
    latch.await();
    assertTrue(this.readOnlyServiceImpl.getPendingNotifyStatus().isEmpty());
}
Also used : Status(org.apache.ignite.raft.jraft.Status) ReadIndexStatus(org.apache.ignite.raft.jraft.entity.ReadIndexStatus) Bytes(org.apache.ignite.raft.jraft.util.Bytes) ReadIndexClosure(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) ReadIndexStatus(org.apache.ignite.raft.jraft.entity.ReadIndexStatus) ReadIndexState(org.apache.ignite.raft.jraft.entity.ReadIndexState) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 4 with ReadIndexState

use of org.apache.ignite.raft.jraft.entity.ReadIndexState in project ignite-3 by apache.

the class ReadOnlyServiceImpl method executeReadIndexEvents.

private void executeReadIndexEvents(final List<ReadIndexEvent> events) {
    if (events.isEmpty())
        return;
    ReadIndexRequestBuilder rb = raftOptions.getRaftMessagesFactory().readIndexRequest().groupId(this.node.getGroupId()).serverId(this.node.getServerId().toString());
    List<ReadIndexState> states = new ArrayList<>(events.size());
    List<ByteString> entries = new ArrayList<>(events.size());
    for (ReadIndexEvent event : events) {
        byte[] ctx = event.requestContext.get();
        entries.add(ctx == null ? ByteString.EMPTY : new ByteString(ctx));
        states.add(new ReadIndexState(event.requestContext, event.done, event.startTime));
    }
    ReadIndexRequest request = rb.entriesList(entries).build();
    this.node.handleReadIndexRequest(request, new ReadIndexResponseClosure(states, request));
}
Also used : ReadIndexRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest) ByteString(org.apache.ignite.raft.jraft.util.ByteString) ReadIndexState(org.apache.ignite.raft.jraft.entity.ReadIndexState) ReadIndexRequestBuilder(org.apache.ignite.raft.jraft.rpc.ReadIndexRequestBuilder) ArrayList(java.util.ArrayList)

Aggregations

ReadIndexState (org.apache.ignite.raft.jraft.entity.ReadIndexState)4 ReadIndexClosure (org.apache.ignite.raft.jraft.closure.ReadIndexClosure)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Status (org.apache.ignite.raft.jraft.Status)1 ReadIndexStatus (org.apache.ignite.raft.jraft.entity.ReadIndexStatus)1 ReadIndexRequestBuilder (org.apache.ignite.raft.jraft.rpc.ReadIndexRequestBuilder)1 ReadIndexRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest)1 ByteString (org.apache.ignite.raft.jraft.util.ByteString)1 Bytes (org.apache.ignite.raft.jraft.util.Bytes)1 Test (org.junit.jupiter.api.Test)1