Search in sources :

Example 86 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class VoteStateTest method shouldReportNoUpdateWhenVoteStateUnchanged.

@Test
public void shouldReportNoUpdateWhenVoteStateUnchanged() throws Exception {
    // given
    VoteState voteState = new VoteState();
    MemberId member1 = new MemberId(UUID.randomUUID());
    MemberId member2 = new MemberId(UUID.randomUUID());
    // when
    Assert.assertTrue(voteState.update(null, 0));
    Assert.assertFalse(voteState.update(null, 0));
    Assert.assertTrue(voteState.update(member1, 0));
    Assert.assertFalse(voteState.update(member1, 0));
    Assert.assertTrue(voteState.update(member2, 1));
    Assert.assertFalse(voteState.update(member2, 1));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Test(org.junit.Test)

Example 87 with MemberId

use of org.neo4j.causalclustering.identity.MemberId 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)

Example 88 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class DumpClusterState method dump.

void dump() throws IOException {
    SimpleStorage<MemberId> memberIdStorage = new SimpleFileStorage<>(fs, clusterStateDirectory, CORE_MEMBER_ID_NAME, new Marshal(), NullLogProvider.getInstance());
    if (memberIdStorage.exists()) {
        MemberId memberId = memberIdStorage.readState();
        out.println(CORE_MEMBER_ID_NAME + ": " + memberId);
    }
    dumpState(LAST_FLUSHED_NAME, new LongIndexMarshal());
    dumpState(LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal(new Marshal()));
    dumpState(ID_ALLOCATION_NAME, new IdAllocationState.Marshal());
    dumpState(SESSION_TRACKER_NAME, new GlobalSessionTrackerState.Marshal(new Marshal()));
    /* raft state */
    dumpState(RAFT_MEMBERSHIP_NAME, new RaftMembershipState.Marshal());
    dumpState(RAFT_TERM_NAME, new TermState.Marshal());
    dumpState(RAFT_VOTE_NAME, new VoteState.Marshal(new Marshal()));
}
Also used : IdAllocationState(org.neo4j.causalclustering.core.state.machines.id.IdAllocationState) GlobalSessionTrackerState(org.neo4j.causalclustering.core.replication.session.GlobalSessionTrackerState) MemberId(org.neo4j.causalclustering.identity.MemberId) SimpleFileStorage(org.neo4j.causalclustering.core.state.storage.SimpleFileStorage) VoteState(org.neo4j.causalclustering.core.consensus.vote.VoteState) ReplicatedLockTokenState(org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenState) RaftMembershipState(org.neo4j.causalclustering.core.consensus.membership.RaftMembershipState) Marshal(org.neo4j.causalclustering.identity.MemberId.Marshal) StateMarshal(org.neo4j.causalclustering.core.state.storage.StateMarshal) TermState(org.neo4j.causalclustering.core.consensus.term.TermState)

Example 89 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class EnterpriseCoreEditionModule method createMessageLogger.

private MessageLogger<MemberId> createMessageLogger(Config config, LifeSupport life, MemberId myself) {
    final MessageLogger<MemberId> messageLogger;
    if (config.get(CausalClusteringSettings.raft_messages_log_enable)) {
        File logsDir = config.get(GraphDatabaseSettings.logs_directory);
        messageLogger = life.add(new BetterMessageLogger<>(myself, raftMessagesLog(logsDir)));
    } else {
        messageLogger = new NullMessageLogger<>();
    }
    return messageLogger;
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) BetterMessageLogger(org.neo4j.causalclustering.logging.BetterMessageLogger) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File)

Example 90 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ReplicatedLockTokenSerializer method unmarshal.

public static ReplicatedLockTokenRequest unmarshal(ReadableChannel channel) throws IOException, EndOfStreamException {
    int candidateId = channel.getInt();
    MemberId owner = new MemberId.Marshal().unmarshal(channel);
    return new ReplicatedLockTokenRequest(owner, candidateId);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5