Search in sources :

Example 31 with CPMember

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;
}
Also used : CPMember(com.hazelcast.cp.CPMember)

Example 32 with CPMember

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;
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UUID(java.util.UUID) CPMember(com.hazelcast.cp.CPMember)

Example 33 with CPMember

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ListenerConfig(com.hazelcast.config.ListenerConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) CountingDownCPMembershipListener(com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with CPMember

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());
        }
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroupAvailabilityEventImpl(com.hazelcast.cp.event.impl.CPGroupAvailabilityEventImpl) CPGroupAvailabilityEvent(com.hazelcast.cp.event.CPGroupAvailabilityEvent) ClusterService(com.hazelcast.internal.cluster.ClusterService) ArrayList(java.util.ArrayList) CPMember(com.hazelcast.cp.CPMember)

Example 35 with CPMember

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) CPMember(com.hazelcast.cp.CPMember)

Aggregations

CPMember (com.hazelcast.cp.CPMember)57 HazelcastInstance (com.hazelcast.core.HazelcastInstance)40 Test (org.junit.Test)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)27 CPGroup (com.hazelcast.cp.CPGroup)17 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)16 CPGroupId (com.hazelcast.cp.CPGroupId)14 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ArrayList (java.util.ArrayList)11 Config (com.hazelcast.config.Config)10 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)10 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)7 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)6 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 JsonValue (com.hazelcast.internal.json.JsonValue)4