Search in sources :

Example 1 with CatchUpClosure

use of org.apache.ignite.raft.jraft.closure.CatchUpClosure in project ignite-3 by apache.

the class Replicator method notifyOnCaughtUp.

private void notifyOnCaughtUp(final int code, final boolean beforeDestroy) {
    if (this.catchUpClosure == null) {
        return;
    }
    if (code != RaftError.ETIMEDOUT.getNumber()) {
        if (this.nextIndex - 1 + this.catchUpClosure.getMaxMargin() < this.options.getLogManager().getLastLogIndex()) {
            return;
        }
        if (this.catchUpClosure.isErrorWasSet()) {
            return;
        }
        this.catchUpClosure.setErrorWasSet(true);
        if (code != RaftError.SUCCESS.getNumber()) {
            this.catchUpClosure.getStatus().setError(code, RaftError.describeCode(code));
        }
        if (this.catchUpClosure.hasTimer()) {
            if (!beforeDestroy && !this.catchUpClosure.getTimer().cancel(false)) {
                // on_caught_up to void ABA problem
                return;
            }
        }
    } else {
        // timed out
        if (!this.catchUpClosure.isErrorWasSet()) {
            this.catchUpClosure.getStatus().setError(code, RaftError.describeCode(code));
        }
    }
    final CatchUpClosure savedClosure = this.catchUpClosure;
    this.catchUpClosure = null;
    Utils.runClosureInThread(options.getCommonExecutor(), savedClosure, savedClosure.getStatus());
}
Also used : CatchUpClosure(org.apache.ignite.raft.jraft.closure.CatchUpClosure)

Example 2 with CatchUpClosure

use of org.apache.ignite.raft.jraft.closure.CatchUpClosure in project ignite-3 by apache.

the class ReplicatorTest method testOnRpcReturnedWaitMoreEntries.

@Test
public void testOnRpcReturnedWaitMoreEntries() throws Exception {
    final Replicator r = getReplicator();
    assertEquals(-1, r.getWaitId());
    final RpcRequests.AppendEntriesRequest request = createEmptyEntriesRequest();
    final RpcRequests.AppendEntriesResponse response = raftOptions.getRaftMessagesFactory().appendEntriesResponse().success(true).lastLogIndex(10).term(1).build();
    this.id.unlock();
    Mockito.when(this.logManager.wait(eq(10L), Mockito.any(), same(this.id))).thenReturn(99L);
    final CountDownLatch latch = new CountDownLatch(1);
    Replicator.waitForCaughtUp(this.id, 1, System.currentTimeMillis() + 5000, new CatchUpClosure() {

        @Override
        public void run(final Status status) {
            assertTrue(status.isOk());
            latch.countDown();
        }
    }, node.getOptions().getCommonExecutor());
    Replicator.onRpcReturned(this.id, Replicator.RequestType.AppendEntries, Status.OK(), request, response, 0, 0, Utils.monotonicMs());
    assertEquals(Replicator.RunningState.IDLE, r.statInfo.runningState);
    // TODO asch fix bad unlock IGNITE-14832
    this.id.unlock();
    assertEquals(11, Replicator.getNextIndex(this.id));
    assertEquals(99, r.getWaitId());
    // make sure catch up closure is invoked.
    latch.await();
}
Also used : Status(org.apache.ignite.raft.jraft.Status) CatchUpClosure(org.apache.ignite.raft.jraft.closure.CatchUpClosure) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

CatchUpClosure (org.apache.ignite.raft.jraft.closure.CatchUpClosure)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Status (org.apache.ignite.raft.jraft.Status)1 RpcRequests (org.apache.ignite.raft.jraft.rpc.RpcRequests)1 Test (org.junit.jupiter.api.Test)1