use of org.neo4j.cluster.protocol.atomicbroadcast.Payload in project neo4j by neo4j.
the class HardKillIT method testMasterSwitchHappensOnKillMinus9.
@Test
public void testMasterSwitchHappensOnKillMinus9() throws Exception {
Process proc = null;
HighlyAvailableGraphDatabase dbWithId2 = null, dbWithId3 = null, oldMaster = null;
try {
proc = run(1);
dbWithId2 = startDb(2, path(2));
dbWithId3 = startDb(3, path(3));
waitUntilAllProperlyAvailable(dbWithId2, 1, MASTER, 2, SLAVE, 3, SLAVE);
waitUntilAllProperlyAvailable(dbWithId3, 1, MASTER, 2, SLAVE, 3, SLAVE);
final CountDownLatch newMasterAvailableLatch = new CountDownLatch(1);
dbWithId2.getDependencyResolver().resolveDependency(ClusterClient.class).addAtomicBroadcastListener(new AtomicBroadcastListener() {
@Override
public void receive(Payload value) {
try {
Object event = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory()).receive(value);
if (event instanceof MemberIsAvailable) {
if (HighAvailabilityModeSwitcher.MASTER.equals(((MemberIsAvailable) event).getRole())) {
newMasterAvailableLatch.countDown();
}
}
} catch (Exception e) {
fail(e.toString());
}
}
});
proc.destroy();
proc = null;
assertTrue(newMasterAvailableLatch.await(60, SECONDS));
assertTrue(dbWithId2.isMaster());
assertTrue(!dbWithId3.isMaster());
// Ensure that everyone has marked the killed instance as failed, otherwise it cannot rejoin
waitUntilAllProperlyAvailable(dbWithId2, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
waitUntilAllProperlyAvailable(dbWithId3, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
oldMaster = startDb(1, path(1));
long oldMasterNode = createNamedNode(oldMaster, "Old master");
assertEquals(oldMasterNode, getNamedNode(dbWithId2, "Old master"));
} finally {
if (proc != null) {
proc.destroy();
}
if (oldMaster != null) {
oldMaster.shutdown();
}
if (dbWithId2 != null) {
dbWithId2.shutdown();
}
if (dbWithId3 != null) {
dbWithId3.shutdown();
}
}
}
use of org.neo4j.cluster.protocol.atomicbroadcast.Payload in project neo4j by neo4j.
the class PaxosInstance method toString.
@Override
public String toString() {
try {
Object toStringValue1 = null;
if (value_1 != null) {
if (value_1 instanceof Payload) {
toStringValue1 = new AtomicBroadcastSerializer().receive((Payload) value_1).toString();
} else {
toStringValue1 = value_1.toString();
}
}
Object toStringValue2 = null;
if (value_2 != null) {
if (value_2 instanceof Payload) {
toStringValue2 = new AtomicBroadcastSerializer().receive((Payload) value_2).toString();
} else {
toStringValue2 = value_2.toString();
}
}
return "[id:" + id + " state:" + state.name() + " b:" + ballot + " v1:" + toStringValue1 + " v2:" + toStringValue2 + "]";
} catch (Throwable e) {
return "";
}
}
use of org.neo4j.cluster.protocol.atomicbroadcast.Payload in project neo4j by neo4j.
the class PaxosClusterMemberAvailability method memberIsUnavailable.
@Override
public void memberIsUnavailable(String role) {
try {
MemberIsUnavailable message = new MemberIsUnavailable(role, myId, serverClusterId);
Payload payload = serializer.broadcast(message);
atomicBroadcast.broadcast(payload);
} catch (Throwable e) {
log.warn("Could not distribute member unavailability", e);
}
}
use of org.neo4j.cluster.protocol.atomicbroadcast.Payload in project neo4j by neo4j.
the class ClusterMockTest method testCluster.
protected void testCluster(int[] serverIds, VerifyInstanceConfiguration[] finalConfig, NetworkMock mock, ClusterTestScript script) throws ExecutionException, InterruptedException, URISyntaxException, TimeoutException {
this.script = script;
network = mock;
servers.clear();
out.clear();
in.clear();
for (int i = 0; i < serverIds.length; i++) {
final URI uri = new URI("server" + (i + 1));
members.put(serverIds[i], uri);
TestProtocolServer server = network.addServer(serverIds[i], uri);
final Cluster cluster = server.newClient(Cluster.class);
clusterStateListener(uri, cluster);
server.newClient(Heartbeat.class).addHeartbeatListener(new HeartbeatListener() {
@Override
public void failed(InstanceId server) {
logger.getLogger().warning(uri + ": Failed:" + server);
}
@Override
public void alive(InstanceId server) {
logger.getLogger().fine(uri + ": Alive:" + server);
}
});
server.newClient(AtomicBroadcast.class).addAtomicBroadcastListener(new AtomicBroadcastListener() {
AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory());
@Override
public void receive(Payload value) {
try {
logger.getLogger().fine(uri + " received: " + serializer.receive(value));
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
});
servers.add(server);
out.add(cluster);
}
// Run test
for (int i = 0; i < script.rounds(); i++) {
logger.getLogger().fine("Round " + i + ", time:" + network.getTime());
script.tick(network.getTime());
network.tick();
}
// Let messages settle
network.tick(100);
if (finalConfig == null) {
verifyConfigurations("final config");
} else {
verifyConfigurations(finalConfig);
}
logger.getLogger().fine("All nodes leave");
// All leave
for (Cluster cluster : new ArrayList<Cluster>(in)) {
logger.getLogger().fine("Leaving:" + cluster);
cluster.leave();
in.remove(cluster);
network.tick(400);
}
if (finalConfig != null) {
verifyConfigurations(finalConfig);
} else {
verifyConfigurations("test over");
}
}
use of org.neo4j.cluster.protocol.atomicbroadcast.Payload in project neo4j by neo4j.
the class StateTransitionLogger method stateTransition.
@Override
public void stateTransition(StateTransition transition) {
Log log = logProvider.getLog(transition.getOldState().getClass());
if (log.isDebugEnabled()) {
if (transition.getOldState() == HeartbeatState.heartbeat) {
return;
}
// The bulk of the message
String state = transition.getOldState().getClass().getSuperclass().getSimpleName();
StringBuilder line = new StringBuilder(state).append(": ").append(transition);
// Who was this message from?
if (transition.getMessage().hasHeader(FROM)) {
line.append(" from:").append(transition.getMessage().getHeader(FROM));
}
if (transition.getMessage().hasHeader(INSTANCE)) {
line.append(" instance:").append(transition.getMessage().getHeader(INSTANCE));
}
if (transition.getMessage().hasHeader(CONVERSATION_ID)) {
line.append(" conversation-id:").append(transition.getMessage().getHeader(CONVERSATION_ID));
}
Object payload = transition.getMessage().getPayload();
if (payload != null) {
if (payload instanceof Payload) {
try {
payload = atomicBroadcastSerializer.receive((Payload) payload);
} catch (Throwable e) {
// Ignore
}
}
line.append(" payload:").append(Strings.prettyPrint(payload));
}
// Throttle
String msg = line.toString();
if (msg.equals(lastLogMessage)) {
return;
}
// Log it
log.debug(line.toString());
lastLogMessage = msg;
}
}
Aggregations