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());
}
}
}
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());
}
}
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());
}
}
Aggregations