Search in sources :

Example 1 with DurableStateStorage

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

the class DumpClusterState method dumpState.

private void dumpState(String name, StateMarshal<?> marshal) {
    int rotationSize = Config.defaults().get(CausalClusteringSettings.replicated_lock_token_state_size);
    DurableStateStorage<?> storage = new DurableStateStorage<>(fs, clusterStateDirectory, name, marshal, rotationSize, NullLogProvider.getInstance());
    if (storage.exists()) {
        try (Lifespan ignored = new Lifespan(storage)) {
            out.println(name + ": " + storage.getInitialState());
        }
    }
}
Also used : DurableStateStorage(org.neo4j.causalclustering.core.state.storage.DurableStateStorage) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 2 with DurableStateStorage

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

the class ReplicatedLockTokenStateMachineTest method shouldPersistAndRecoverState.

@Test
public void shouldPersistAndRecoverState() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    fsa.mkdir(testDir.directory());
    StateMarshal<ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal());
    MemberId memberA = member(0);
    MemberId memberB = member(1);
    int candidateId;
    DurableStateStorage<ReplicatedLockTokenState> storage = new DurableStateStorage<>(fsa, testDir.directory(), "state", marshal, 100, NullLogProvider.getInstance());
    try (Lifespan lifespan = new Lifespan(storage)) {
        ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);
        // when
        candidateId = 0;
        stateMachine.applyCommand(new ReplicatedLockTokenRequest(memberA, candidateId), 0, r -> {
        });
        candidateId = 1;
        stateMachine.applyCommand(new ReplicatedLockTokenRequest(memberB, candidateId), 1, r -> {
        });
        stateMachine.flush();
        fsa.crash();
    }
    // then
    DurableStateStorage<ReplicatedLockTokenState> storage2 = new DurableStateStorage<>(fsa, testDir.directory(), "state", marshal, 100, NullLogProvider.getInstance());
    try (Lifespan lifespan = new Lifespan(storage2)) {
        ReplicatedLockTokenState initialState = storage2.getInitialState();
        assertEquals(memberB, initialState.get().owner());
        assertEquals(candidateId, initialState.get().id());
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StateMarshal(org.neo4j.causalclustering.core.state.storage.StateMarshal) DurableStateStorage(org.neo4j.causalclustering.core.state.storage.DurableStateStorage) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 3 with DurableStateStorage

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

the class ReplicatedLockTokenStateMachineTest method shouldBeIdempotent.

@Test
public void shouldBeIdempotent() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    fsa.mkdir(testDir.directory());
    StateMarshal<ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal());
    DurableStateStorage<ReplicatedLockTokenState> storage = new DurableStateStorage<>(fsa, testDir.directory(), "state", marshal, 100, NullLogProvider.getInstance());
    try (Lifespan lifespan = new Lifespan(storage)) {
        ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);
        MemberId memberA = member(0);
        MemberId memberB = member(1);
        stateMachine.applyCommand(new ReplicatedLockTokenRequest(memberA, 0), 3, r -> {
        });
        // when
        stateMachine.applyCommand(new ReplicatedLockTokenRequest(memberB, 1), 2, r -> {
        });
        // then
        assertEquals(memberA, stateMachine.currentToken().owner());
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StateMarshal(org.neo4j.causalclustering.core.state.storage.StateMarshal) DurableStateStorage(org.neo4j.causalclustering.core.state.storage.DurableStateStorage) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Aggregations

DurableStateStorage (org.neo4j.causalclustering.core.state.storage.DurableStateStorage)3 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)3 Test (org.junit.Test)2 StateMarshal (org.neo4j.causalclustering.core.state.storage.StateMarshal)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)2