use of com.hazelcast.internal.cluster.MemberInfo in project hazelcast by hazelcast.
the class MemberInfoUpdateOperation method toString.
@Override
protected void toString(StringBuilder sb) {
super.toString(sb);
sb.append(", targetUuid=").append(targetUuid);
sb.append(", members=");
for (MemberInfo address : memberInfos) {
sb.append(address).append(' ');
}
}
use of com.hazelcast.internal.cluster.MemberInfo in project hazelcast by hazelcast.
the class MemberListTest method testOutOfSyncMemberListTwoMasters.
/*
* Sets up a situation where the member list is out of order on node2. Both
* node2 and node1 think they are masters and both think each other are in
* their clusters.
*/
@Test
public void testOutOfSyncMemberListTwoMasters() throws Exception {
List<HazelcastInstance> instanceList = buildInstances(3, 35701);
final HazelcastInstance h1 = instanceList.get(0);
final HazelcastInstance h2 = instanceList.get(1);
final HazelcastInstance h3 = instanceList.get(2);
final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
final MemberImpl m3 = (MemberImpl) h3.getCluster().getLocalMember();
// All three nodes join into one cluster
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
final Node n2 = TestUtil.getNode(h2);
// Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
List<MemberInfo> members = new ArrayList<MemberInfo>();
members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
members.add(new MemberInfo(m3.getAddress(), m3.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
n2.clusterService.updateMembers(members, n2.getMasterAddress());
n2.setMasterAddress(m2.getAddress());
// Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
sleepSeconds(30);
assertMasterEquals(m1, h1);
assertMasterEquals(m1, h2);
assertMasterEquals(m1, h3);
assertClusterSize(3, h1);
assertClusterSize(3, h2);
assertClusterSize(3, h3);
}
use of com.hazelcast.internal.cluster.MemberInfo in project hazelcast by hazelcast.
the class MemberListTest method testSameMasterDifferentMemberList.
/*
* Sets up situation where all nodes have the same master, but node 2's list
* doesn't contain node 3.
*/
@Test
public void testSameMasterDifferentMemberList() throws Exception {
List<HazelcastInstance> instanceList = buildInstances(3, 45701);
final HazelcastInstance h1 = instanceList.get(0);
final HazelcastInstance h2 = instanceList.get(1);
final HazelcastInstance h3 = instanceList.get(2);
final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
// All three nodes join into one cluster
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
final Node n2 = TestUtil.getNode(h2);
// Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
List<MemberInfo> members = new ArrayList<MemberInfo>();
members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
n2.clusterService.updateMembers(members, n2.getMasterAddress());
// Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
sleepSeconds(30);
assertMasterEquals(m1, h1);
assertMasterEquals(m1, h2);
assertMasterEquals(m1, h3);
assertClusterSize(3, h1);
assertClusterSize(3, h2);
assertClusterSize(3, h3);
}
use of com.hazelcast.internal.cluster.MemberInfo in project hazelcast by hazelcast.
the class ClusterDataSerializationTest method testSerializationOf_memberInfo.
@Test
public void testSerializationOf_memberInfo() throws UnknownHostException {
// member attributes, test an integer, a String and an IdentifiedDataSerializable as values
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("a", 2);
attributes.put("b", "b");
attributes.put("c", new Address("127.0.0.1", 5999));
MemberInfo memberInfo = new MemberInfo(new Address("127.0.0.1", 5071), UUID.randomUUID().toString(), attributes, false, MemberVersion.of(BUILD_INFO.getVersion()));
Data serialized = SERIALIZATION_SERVICE.toData(memberInfo);
MemberInfo deserialized = SERIALIZATION_SERVICE.toObject(serialized);
assertEquals(deserialized.getAddress(), memberInfo.getAddress());
assertEquals(deserialized.getVersion(), memberInfo.getVersion());
assertEquals(deserialized.getUuid(), memberInfo.getUuid());
assertEquals(deserialized.getAttributes().get("a"), memberInfo.getAttributes().get("a"));
assertEquals(deserialized.getAttributes().get("b"), memberInfo.getAttributes().get("b"));
assertEquals(deserialized.getAttributes().get("c"), memberInfo.getAttributes().get("c"));
}
use of com.hazelcast.internal.cluster.MemberInfo in project hazelcast by hazelcast.
the class ClusterServiceImpl method doUpdateMembers.
private void doUpdateMembers(Collection<MemberInfo> members) {
MemberMap currentMemberMap = memberMapRef.get();
String scopeId = thisAddress.getScopeId();
Collection<MemberImpl> newMembers = new LinkedList<MemberImpl>();
MemberImpl[] updatedMembers = new MemberImpl[members.size()];
int memberIndex = 0;
for (MemberInfo memberInfo : members) {
Address address = memberInfo.getAddress();
MemberImpl member = currentMemberMap.getMember(address);
if (member == null) {
member = createMember(memberInfo, scopeId);
newMembers.add(member);
long now = clusterClock.getClusterTime();
clusterHeartbeatManager.onHeartbeat(member, now);
clusterHeartbeatManager.acceptMasterConfirmation(member, now);
repairPartitionTableIfReturningMember(member);
}
updatedMembers[memberIndex++] = member;
}
setMembers(updatedMembers);
sendMembershipEvents(currentMemberMap.getMembers(), newMembers);
MemberMap membersRemovedInNotActiveState = membersRemovedInNotActiveStateRef.get();
membersRemovedInNotActiveStateRef.set(MemberMap.cloneExcluding(membersRemovedInNotActiveState, updatedMembers));
clusterHeartbeatManager.heartbeat();
logger.info(membersString());
}
Aggregations