Search in sources :

Example 1 with InMemoryStateStorage

use of org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage in project neo4j by neo4j.

the class RaftStateBuilder method build.

public RaftState build() throws IOException {
    StateStorage<TermState> termStore = new InMemoryStateStorage<>(new TermState());
    StateStorage<VoteState> voteStore = new InMemoryStateStorage<>(new VoteState());
    StubMembership membership = new StubMembership(votingMembers, replicationMembers);
    RaftState state = new RaftState(myself, termStore, membership, entryLog, voteStore, new InFlightMap<>(), NullLogProvider.getInstance());
    Collection<RaftMessages.Directed> noMessages = Collections.emptyList();
    List<RaftLogCommand> noLogCommands = Collections.emptyList();
    state.update(new Outcome(null, term, leader, leaderCommit, votedFor, votesForMe, lastLogIndexBeforeWeBecameLeader, followerStates, false, noLogCommands, noMessages, emptySet(), commitIndex, emptySet()));
    return state;
}
Also used : RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand) InMemoryStateStorage(org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage) VoteState(org.neo4j.causalclustering.core.consensus.vote.VoteState) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) TermState(org.neo4j.causalclustering.core.consensus.term.TermState)

Example 2 with InMemoryStateStorage

use of org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage in project neo4j by neo4j.

the class LeaderOnlyLockManagerTest method shouldIssueLocksOnLeader.

@Test
public void shouldIssueLocksOnLeader() throws Exception {
    // given
    MemberId me = member(0);
    ReplicatedLockTokenStateMachine replicatedLockStateMachine = new ReplicatedLockTokenStateMachine(new InMemoryStateStorage(new ReplicatedLockTokenState()));
    DirectReplicator replicator = new DirectReplicator(replicatedLockStateMachine);
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(me);
    Locks locks = mock(Locks.class);
    when(locks.newClient()).thenReturn(mock(Locks.Client.class));
    LeaderOnlyLockManager lockManager = new LeaderOnlyLockManager(me, replicator, leaderLocator, locks, replicatedLockStateMachine);
    // when
    lockManager.newClient().acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, 0L);
// then
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) InMemoryStateStorage(org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Locks(org.neo4j.kernel.impl.locking.Locks) Test(org.junit.Test)

Example 3 with InMemoryStateStorage

use of org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage in project neo4j by neo4j.

the class LeaderOnlyLockManagerTest method shouldNotIssueLocksOnNonLeader.

@Test
public void shouldNotIssueLocksOnNonLeader() throws Exception {
    // given
    MemberId me = member(0);
    MemberId leader = member(1);
    ReplicatedLockTokenStateMachine replicatedLockStateMachine = new ReplicatedLockTokenStateMachine(new InMemoryStateStorage(new ReplicatedLockTokenState()));
    DirectReplicator replicator = new DirectReplicator(replicatedLockStateMachine);
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(leader);
    Locks locks = mock(Locks.class);
    when(locks.newClient()).thenReturn(mock(Locks.Client.class));
    LeaderOnlyLockManager lockManager = new LeaderOnlyLockManager(me, replicator, leaderLocator, locks, replicatedLockStateMachine);
    // when
    Locks.Client lockClient = lockManager.newClient();
    try {
        lockClient.acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, 0L);
        fail("Should have thrown exception");
    } catch (AcquireLockTimeoutException e) {
    // expected
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) InMemoryStateStorage(org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage) AcquireLockTimeoutException(org.neo4j.storageengine.api.lock.AcquireLockTimeoutException) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Locks(org.neo4j.kernel.impl.locking.Locks) Test(org.junit.Test)

Aggregations

InMemoryStateStorage (org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage)3 Test (org.junit.Test)2 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)2 DirectReplicator (org.neo4j.causalclustering.core.replication.DirectReplicator)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 Locks (org.neo4j.kernel.impl.locking.Locks)2 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)1 RaftLogCommand (org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand)1 TermState (org.neo4j.causalclustering.core.consensus.term.TermState)1 VoteState (org.neo4j.causalclustering.core.consensus.vote.VoteState)1 AcquireLockTimeoutException (org.neo4j.storageengine.api.lock.AcquireLockTimeoutException)1