Search in sources :

Example 1 with ClusterState

use of org.neo4j.causalclustering.core.consensus.explorer.ClusterState in project neo4j by neo4j.

the class DropMessage method advance.

@Override
public ClusterState advance(ClusterState previous) {
    ClusterState newClusterState = new ClusterState(previous);
    Queue<RaftMessages.RaftMessage> inboundQueue = new LinkedList<>(previous.queues.get(member));
    RaftMessages.RaftMessage message = inboundQueue.poll();
    if (message == null) {
        return previous;
    }
    newClusterState.queues.put(member, inboundQueue);
    return newClusterState;
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) LinkedList(java.util.LinkedList)

Example 2 with ClusterState

use of org.neo4j.causalclustering.core.consensus.explorer.ClusterState in project neo4j by neo4j.

the class HeartbeatTimeout method advance.

@Override
public ClusterState advance(ClusterState previous) throws IOException {
    ClusterState newClusterState = new ClusterState(previous);
    Queue<RaftMessages.RaftMessage> newQueue = new LinkedList<>(previous.queues.get(member));
    newQueue.offer(new RaftMessages.Timeout.Heartbeat(member));
    newClusterState.queues.put(member, newQueue);
    return newClusterState;
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) LinkedList(java.util.LinkedList)

Example 3 with ClusterState

use of org.neo4j.causalclustering.core.consensus.explorer.ClusterState in project neo4j by neo4j.

the class OutOfOrderDelivery method advance.

@Override
public ClusterState advance(ClusterState previous) {
    ClusterState newClusterState = new ClusterState(previous);
    LinkedList<RaftMessages.RaftMessage> inboundQueue = new LinkedList<>(previous.queues.get(member));
    if (inboundQueue.size() < 2) {
        return previous;
    }
    RaftMessages.RaftMessage message = inboundQueue.poll();
    inboundQueue.add(1, message);
    newClusterState.queues.put(member, inboundQueue);
    return newClusterState;
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) LinkedList(java.util.LinkedList)

Example 4 with ClusterState

use of org.neo4j.causalclustering.core.consensus.explorer.ClusterState in project neo4j by neo4j.

the class NewEntry method advance.

@Override
public ClusterState advance(ClusterState previous) throws IOException {
    ClusterState newClusterState = new ClusterState(previous);
    Queue<RaftMessages.RaftMessage> newQueue = new LinkedList<>(previous.queues.get(member));
    newQueue.offer(new RaftMessages.NewEntry.Request(member, new ReplicatedString("content")));
    newClusterState.queues.put(member, newQueue);
    return newClusterState;
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) ReplicatedString(org.neo4j.causalclustering.core.consensus.ReplicatedString) LinkedList(java.util.LinkedList)

Example 5 with ClusterState

use of org.neo4j.causalclustering.core.consensus.explorer.ClusterState in project neo4j by neo4j.

the class OutOfOrderDeliveryTest method shouldReOrder.

@Test
public void shouldReOrder() throws Exception {
    // given
    ClusterState clusterState = new ClusterState(asSet(member(0)));
    clusterState.queues.get(member(0)).add(new Election(member(0)));
    clusterState.queues.get(member(0)).add(new Heartbeat(member(0)));
    // when
    ClusterState reOrdered = new OutOfOrderDelivery(member(0)).advance(clusterState);
    // then
    assertEquals(new Heartbeat(member(0)), reOrdered.queues.get(member(0)).poll());
    assertEquals(new Election(member(0)), reOrdered.queues.get(member(0)).poll());
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) Heartbeat(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Heartbeat) Election(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election) Test(org.junit.Test)

Aggregations

ClusterState (org.neo4j.causalclustering.core.consensus.explorer.ClusterState)5 LinkedList (java.util.LinkedList)4 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)2 Test (org.junit.Test)1 Election (org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election)1 Heartbeat (org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Heartbeat)1 ReplicatedString (org.neo4j.causalclustering.core.consensus.ReplicatedString)1