use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RaftInvocation method getInvocationTarget.
@Override
CPMember getInvocationTarget() {
CPMember target = getTargetEndpoint();
lastInvocationEndpoint = target;
return target;
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RaftInvocationContext method updateMember.
public void updateMember(CPMember member) {
while (true) {
// Put the given member into the current member list,
// even if the given member does not exist with another address.
// In addition, remove any other member that has the address of the given member.
CPMembersContainer currentContainer = membersContainer.get();
CPMember otherMember = null;
for (CPMember m : currentContainer.members) {
if (m.getAddress().equals(member.getAddress()) && !m.getUuid().equals(member.getUuid())) {
otherMember = m;
break;
}
}
CPMember existingMember = currentContainer.membersMap.get(member.getUuid());
if (otherMember == null && existingMember != null && existingMember.getAddress().equals(member.getAddress())) {
return;
}
Map<UUID, CPMember> newMembers = new HashMap<>(currentContainer.membersMap);
newMembers.put(member.getUuid(), member);
if (otherMember != null) {
newMembers.remove(otherMember.getUuid());
}
CPMembersContainer newContainer = new CPMembersContainer(currentContainer.version, newMembers);
if (membersContainer.compareAndSet(currentContainer, newContainer)) {
logger.info("Replaced " + existingMember + " with " + member);
return;
}
}
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class ClientCPMembershipListenerTest method whenMemberTerminated_thenReceiveMemberRemovedEvent.
@Test
public void whenMemberTerminated_thenReceiveMemberRemovedEvent() {
Config config = createConfig(3, 3);
config.getCPSubsystemConfig().setSessionTimeToLiveSeconds(2).setSessionHeartbeatIntervalSeconds(1).setMissingCPMemberAutoRemovalSeconds(3);
HazelcastInstance[] instances = factory.newInstances(config, 3);
waitUntilCPDiscoveryCompleted(instances);
HazelcastInstance client = factory.newHazelcastClient();
CountingDownCPMembershipListener listener = new CountingDownCPMembershipListener(0, 1);
client.getCPSubsystem().addMembershipListener(listener);
HazelcastInstance instance = instances[instances.length - 1];
CPMember member = instance.getCPSubsystem().getLocalCPMember();
instance.getLifecycleService().terminate();
assertOpenEventually(listener.removedLatch);
assertEquals(member, listener.removedMembers.get(0));
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RaftService method publishGroupAvailabilityEvents.
private void publishGroupAvailabilityEvents(MemberImpl removedMember) {
ClusterService clusterService = nodeEngine.getClusterService();
if (clusterService.getClusterVersion().isUnknownOrLessThan(Versions.V4_1)) {
return;
}
// they will be the ones that keep track of unreachable CP members.
for (CPGroupId groupId : metadataGroupManager.getActiveGroupIds()) {
CPGroupSummary group = metadataGroupManager.getGroup(groupId);
Collection<CPMember> missing = new ArrayList<>();
boolean availabilityDecreased = false;
for (CPMember member : group.members()) {
if (member.getAddress().equals(removedMember.getAddress())) {
// Group's availability decreased because of this removed member
availabilityDecreased = true;
missing.add(member);
} else if (clusterService.getMember(member.getAddress()) == null) {
missing.add(member);
}
}
if (availabilityDecreased) {
CPGroupAvailabilityEvent e = new CPGroupAvailabilityEventImpl(group.id(), group.members(), missing);
nodeEngine.getEventService().publishEvent(SERVICE_NAME, EVENT_TOPIC_AVAILABILITY, e, EVENT_TOPIC_AVAILABILITY.hashCode());
}
}
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class CPGroupSummary method readData.
@Override
public void readData(ObjectDataInput in) throws IOException {
id = in.readObject();
int initialMemberCount = in.readInt();
Set<RaftEndpoint> initialMembers = new LinkedHashSet<RaftEndpoint>();
for (int i = 0; i < initialMemberCount; i++) {
RaftEndpoint member = in.readObject();
initialMembers.add(member);
}
this.initialMembers = unmodifiableSet(initialMembers);
int memberCount = in.readInt();
members = new LinkedHashSet<CPMember>(memberCount);
for (int i = 0; i < memberCount; i++) {
CPMember member = in.readObject();
members.add(member);
}
members = unmodifiableSet(members);
status = CPGroupStatus.valueOf(in.readString());
}
Aggregations