Search in sources :

Example 11 with FollowerState

use of org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState in project neo4j by neo4j.

the class CatchupGoalTrackerTest method shouldFailToAchieveGoalDueToCatchupTimeoutExpiring.

@Test
public void shouldFailToAchieveGoalDueToCatchupTimeoutExpiring() throws Exception {
    FakeClock clock = Clocks.fakeClock();
    StubLog log = new StubLog();
    log.setAppendIndex(10);
    CatchupGoalTracker catchupGoalTracker = new CatchupGoalTracker(log, clock, ROUND_TIMEOUT, CATCHUP_TIMEOUT);
    // when
    clock.forward(CATCHUP_TIMEOUT + 10, TimeUnit.MILLISECONDS);
    catchupGoalTracker.updateProgress(new FollowerState().onSuccessResponse(4));
    // then
    assertFalse(catchupGoalTracker.isGoalAchieved());
    assertTrue(catchupGoalTracker.isFinished());
}
Also used : FakeClock(org.neo4j.time.FakeClock) FollowerState(org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState) Test(org.junit.Test)

Example 12 with FollowerState

use of org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState in project neo4j by neo4j.

the class CatchupGoalTrackerTest method shouldFailToAchieveGoalDueToCatchupTimeoutExpiringEvenThoughWeDoEventuallyAchieveTarget.

@Test
public void shouldFailToAchieveGoalDueToCatchupTimeoutExpiringEvenThoughWeDoEventuallyAchieveTarget() throws Exception {
    FakeClock clock = Clocks.fakeClock();
    StubLog log = new StubLog();
    log.setAppendIndex(10);
    CatchupGoalTracker catchupGoalTracker = new CatchupGoalTracker(log, clock, ROUND_TIMEOUT, CATCHUP_TIMEOUT);
    // when
    clock.forward(CATCHUP_TIMEOUT + 10, TimeUnit.MILLISECONDS);
    catchupGoalTracker.updateProgress(new FollowerState().onSuccessResponse(10));
    // then
    assertFalse(catchupGoalTracker.isGoalAchieved());
    assertTrue(catchupGoalTracker.isFinished());
}
Also used : FakeClock(org.neo4j.time.FakeClock) FollowerState(org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState) Test(org.junit.Test)

Example 13 with FollowerState

use of org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState in project neo4j by neo4j.

the class LeaderTest method leaderShouldIgnoreSuccessResponseThatIndicatesLaggingWhileLocalStateIndicatesFollowerIsCaughtUp.

@Test
public void leaderShouldIgnoreSuccessResponseThatIndicatesLaggingWhileLocalStateIndicatesFollowerIsCaughtUp() throws Exception {
    // given
    /*
         * A leader who
         * - has an append index of 100
         * - knows about instance 2
         * - assumes that instance 2 is fully caught up
         */
    Leader leader = new Leader();
    MemberId instance2 = member(2);
    int j = 100;
    FollowerState instance2State = createArtificialFollowerState(j);
    ReadableRaftState state = mock(ReadableRaftState.class);
    FollowerStates<MemberId> followerState = new FollowerStates<>();
    followerState = new FollowerStates<>(followerState, instance2, instance2State);
    ReadableRaftLog logMock = mock(ReadableRaftLog.class);
    when(logMock.appendIndex()).thenReturn(100L);
    //  with commit requests in this test
    when(state.commitIndex()).thenReturn(-1L);
    when(state.entryLog()).thenReturn(logMock);
    when(state.followerStates()).thenReturn(followerState);
    // both leader and follower are in the same term
    when(state.term()).thenReturn(4L);
    // when that leader is asked to handle a response from that follower that says that the follower is still
    // missing things
    RaftMessages.AppendEntries.Response response = appendEntriesResponse().success().matchIndex(80).term(4).from(instance2).build();
    Outcome outcome = leader.handle(response, state, mock(Log.class));
    // then the leader should not send anything, since this is a delayed, out of order response to a previous append
    // request
    assertTrue(outcome.getOutgoingMessages().isEmpty());
    // The follower state should not be touched
    FollowerStates<MemberId> updatedFollowerStates = outcome.getFollowerStates();
    assertEquals(100, updatedFollowerStates.get(instance2).getMatchIndex());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) Log(org.neo4j.logging.Log) ReadableRaftLog(org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog) RaftLog(org.neo4j.causalclustering.core.consensus.log.RaftLog) AppendEntries(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries) ReadableRaftState(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState) MemberId(org.neo4j.causalclustering.identity.MemberId) ReadableRaftLog(org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) FollowerStates(org.neo4j.causalclustering.core.consensus.roles.follower.FollowerStates) FollowerState(org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState) Test(org.junit.Test)

Aggregations

FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)13 Test (org.junit.Test)12 FakeClock (org.neo4j.time.FakeClock)7 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)6 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)5 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)5 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)5 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)5 FollowerStates (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerStates)5 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)5 MemberId (org.neo4j.causalclustering.identity.MemberId)5 Log (org.neo4j.logging.Log)5 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)2 List (java.util.List)1 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)1 Heartbeat (org.neo4j.causalclustering.core.consensus.RaftMessages.Heartbeat)1 LogCompactionInfo (org.neo4j.causalclustering.core.consensus.RaftMessages.LogCompactionInfo)1 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1