Search in sources :

Example 1 with LeaderChangeContext

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

the class NodeImpl method resetLeaderId.

private void resetLeaderId(final PeerId newLeaderId, final Status status) {
    if (newLeaderId.isEmpty()) {
        if (!this.leaderId.isEmpty() && this.state.compareTo(State.STATE_TRANSFERRING) > 0) {
            this.fsmCaller.onStopFollowing(new LeaderChangeContext(this.leaderId.copy(), this.currTerm, status));
        }
        this.leaderId = PeerId.emptyPeer();
    } else {
        if (this.leaderId == null || this.leaderId.isEmpty()) {
            this.fsmCaller.onStartFollowing(new LeaderChangeContext(newLeaderId, this.currTerm, status));
        }
        this.leaderId = newLeaderId.copy();
        resetElectionTimeoutToInitial();
    }
}
Also used : LeaderChangeContext(org.apache.ignite.raft.jraft.entity.LeaderChangeContext)

Example 2 with LeaderChangeContext

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

the class FSMCallerTest method testOnStartStopFollowing.

@Test
public void testOnStartStopFollowing() throws Exception {
    final LeaderChangeContext ctx = new LeaderChangeContext(null, 11, Status.OK());
    this.fsmCaller.onStartFollowing(ctx);
    this.fsmCaller.flush();
    Mockito.verify(this.fsm).onStartFollowing(ctx);
    this.fsmCaller.onStopFollowing(ctx);
    this.fsmCaller.flush();
    Mockito.verify(this.fsm).onStopFollowing(ctx);
}
Also used : LeaderChangeContext(org.apache.ignite.raft.jraft.entity.LeaderChangeContext) Test(org.junit.jupiter.api.Test)

Example 3 with LeaderChangeContext

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

the class FSMCallerImpl method onStartFollowing.

@Override
public boolean onStartFollowing(final LeaderChangeContext ctx) {
    return enqueueTask((task, sequence) -> {
        task.groupId = groupId;
        task.type = TaskType.START_FOLLOWING;
        task.leaderChangeCtx = new LeaderChangeContext(ctx.getLeaderId(), ctx.getTerm(), ctx.getStatus());
    });
}
Also used : LeaderChangeContext(org.apache.ignite.raft.jraft.entity.LeaderChangeContext)

Example 4 with LeaderChangeContext

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

the class FSMCallerImpl method onStopFollowing.

@Override
public boolean onStopFollowing(final LeaderChangeContext ctx) {
    return enqueueTask((task, sequence) -> {
        task.groupId = groupId;
        task.type = TaskType.STOP_FOLLOWING;
        task.leaderChangeCtx = new LeaderChangeContext(ctx.getLeaderId(), ctx.getTerm(), ctx.getStatus());
    });
}
Also used : LeaderChangeContext(org.apache.ignite.raft.jraft.entity.LeaderChangeContext)

Aggregations

LeaderChangeContext (org.apache.ignite.raft.jraft.entity.LeaderChangeContext)4 Test (org.junit.jupiter.api.Test)1