use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext in project neo4j by neo4j.
the class ClusterInstance method newCopy.
public ClusterInstance newCopy() {
// A very invasive method of cloning a protocol server. Nonetheless, since this is mostly an experiment at this
// point, it seems we can refactor later on to have a cleaner clone mechanism.
// Because state machines share state, and are simultaneously conceptually unaware of each other, implementing
// a clean snapshot mechanism is very hard. I've opted for having a dirty one here in the test code rather
// than introducing a hack into the runtime code.
ProverTimeouts timeoutsSnapshot = timeouts.snapshot();
InMemoryAcceptorInstanceStore snapshotAcceptorInstances = acceptorInstanceStore.snapshot();
ClusterInstanceOutput output = new ClusterInstanceOutput(uri);
ClusterInstanceInput input = new ClusterInstanceInput();
DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
MultiPaxosContext snapshotCtx = ctx.snapshot(logging, timeoutsSnapshot, executor, snapshotAcceptorInstances, objectStreamFactory, objectStreamFactory, new DefaultElectionCredentialsProvider(server.getServerId(), new StateVerifierLastTxIdGetter(), new MemberInfoProvider()));
List<StateMachine> snapshotMachines = new ArrayList<>();
for (StateMachine stateMachine : server.getStateMachines().getStateMachines()) {
snapshotMachines.add(snapshotStateMachine(logging, snapshotCtx, stateMachine));
}
ProtocolServer snapshotProtocolServer = factory.constructSupportingInfrastructureFor(server.getServerId(), input, output, executor, timeoutsSnapshot, stateMachineExecutor, snapshotCtx, snapshotMachines.toArray(new StateMachine[snapshotMachines.size()]));
return new ClusterInstance(stateMachineExecutor, logging, factory, snapshotProtocolServer, snapshotCtx, snapshotAcceptorInstances, timeoutsSnapshot, input, output, uri);
}
use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext in project neo4j by neo4j.
the class MultiPaxosContextTest method shouldDeepClone.
@Test
public void shouldDeepClone() throws Exception {
// Given
ObjectStreamFactory objStream = new ObjectStreamFactory();
AcceptorInstanceStore acceptorInstances = mock(AcceptorInstanceStore.class);
Executor executor = mock(Executor.class);
Timeouts timeouts = mock(Timeouts.class);
ClusterConfiguration clusterConfig = new ClusterConfiguration("myCluster", NullLogProvider.getInstance());
ElectionCredentialsProvider electionCredentials = mock(ElectionCredentialsProvider.class);
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.<ElectionRole>emptyList(), clusterConfig, executor, NullLogProvider.getInstance(), objStream, objStream, acceptorInstances, timeouts, electionCredentials, config);
// When
MultiPaxosContext snapshot = ctx.snapshot(NullLogProvider.getInstance(), timeouts, executor, acceptorInstances, objStream, objStream, electionCredentials);
// Then
assertEquals(ctx, snapshot);
}
use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext in project neo4j by neo4j.
the class ElectionContextTest method testElectionNotOkQuorumFailedFourInstances.
@Test
public void testElectionNotOkQuorumFailedFourInstances() {
Set<InstanceId> failed = new HashSet<InstanceId>();
failed.add(new InstanceId(2));
failed.add(new InstanceId(3));
Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
members.put(new InstanceId(1), URI.create("server1"));
members.put(new InstanceId(2), URI.create("server2"));
members.put(new InstanceId(3), URI.create("server3"));
members.put(new InstanceId(4), URI.create("server4"));
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
when(clusterConfiguration.getMembers()).thenReturn(members);
ClusterContext clusterContext = mock(ClusterContext.class);
when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
context.getHeartbeatContext().getFailed().addAll(failed);
ElectionContext toTest = context.getElectionContext();
assertFalse(toTest.electionOk());
}
use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext in project neo4j by neo4j.
the class ElectionContextTest method electionBeingForgottenMustIncreaseElectionId.
@Test
public void electionBeingForgottenMustIncreaseElectionId() throws Exception {
// Given
final String coordinatorRole = "coordinator";
HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
when(heartbeatContext.getFailed()).thenReturn(Collections.<InstanceId>emptySet());
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
ElectionContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config).getElectionContext();
ElectionContext.VoteRequest voteRequestBefore = context.voteRequestForRole(new ElectionRole(coordinatorRole));
context.forgetElection(coordinatorRole);
ElectionContext.VoteRequest voteRequestAfter = context.voteRequestForRole(new ElectionRole(coordinatorRole));
assertEquals(voteRequestBefore.getVersion() + 1, voteRequestAfter.getVersion());
}
use of org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext in project neo4j by neo4j.
the class ElectionContextTest method testElectionNotOkQuorumFailedFiveInstances.
@Test
public void testElectionNotOkQuorumFailedFiveInstances() {
Set<InstanceId> failed = new HashSet<InstanceId>();
failed.add(new InstanceId(2));
failed.add(new InstanceId(3));
failed.add(new InstanceId(4));
Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
members.put(new InstanceId(1), URI.create("server1"));
members.put(new InstanceId(2), URI.create("server2"));
members.put(new InstanceId(3), URI.create("server3"));
members.put(new InstanceId(4), URI.create("server4"));
members.put(new InstanceId(5), URI.create("server5"));
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
when(clusterConfiguration.getMembers()).thenReturn(members);
ClusterContext clusterContext = mock(ClusterContext.class);
when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
context.getHeartbeatContext().getFailed().addAll(failed);
ElectionContext toTest = context.getElectionContext();
assertFalse(toTest.electionOk());
}
Aggregations