Search in sources :

Example 31 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class CompleteDestroyRaftGroupsOp method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    int count = in.readInt();
    groupIds = new HashSet<>();
    for (int i = 0; i < count; i++) {
        CPGroupId groupId = in.readObject();
        groupIds.add(groupId);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId)

Example 32 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class ClientProxySessionManager method shutdownAndAwait.

public void shutdownAndAwait() {
    Map<RaftGroupId, InternalCompletableFuture<Object>> futures = super.shutdown();
    ILogger logger = client.getLoggingService().getLogger(getClass());
    long remainingTimeNanos = TimeUnit.SECONDS.toNanos(SHUTDOWN_TIMEOUT_SECONDS);
    while (remainingTimeNanos > 0) {
        int closed = 0;
        for (Entry<RaftGroupId, InternalCompletableFuture<Object>> entry : futures.entrySet()) {
            CPGroupId groupId = entry.getKey();
            InternalCompletableFuture<Object> f = entry.getValue();
            if (f.isDone()) {
                closed++;
                try {
                    f.get();
                    logger.fine("Session closed for " + groupId);
                } catch (Exception e) {
                    logger.warning("Close session failed for " + groupId, e);
                }
            }
        }
        if (closed == futures.size()) {
            break;
        }
        try {
            Thread.sleep(SHUTDOWN_WAIT_SLEEP_MILLIS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
        remainingTimeNanos -= MILLISECONDS.toNanos(SHUTDOWN_WAIT_SLEEP_MILLIS);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ILogger(com.hazelcast.logging.ILogger)

Example 33 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method completeRaftGroupMembershipChanges.

public MembershipChangeSchedule completeRaftGroupMembershipChanges(long commitIndex, Map<CPGroupId, BiTuple<Long, Long>> changedGroups) {
    checkNotNull(changedGroups);
    if (membershipChangeSchedule == null) {
        String msg = "Cannot apply CP membership changes: " + changedGroups + " since there is no membership change context!";
        logger.warning(msg);
        throw new IllegalStateException(msg);
    }
    for (CPGroupMembershipChange change : membershipChangeSchedule.getChanges()) {
        CPGroupId groupId = change.getGroupId();
        CPGroupInfo group = groups.get(groupId);
        checkState(group != null, groupId + "not found in CP groups: " + groups.keySet() + "to apply " + change);
        BiTuple<Long, Long> t = changedGroups.get(groupId);
        if (t != null) {
            if (!applyMembershipChange(change, group, t.element1, t.element2)) {
                changedGroups.remove(groupId);
            }
        } else if (group.status() == DESTROYED && !changedGroups.containsKey(groupId)) {
            if (logger.isFineEnabled()) {
                logger.warning(groupId + " is already destroyed so will skip: " + change);
            }
            changedGroups.put(groupId, BiTuple.of(0L, 0L));
        }
    }
    membershipChangeSchedule = membershipChangeSchedule.excludeCompletedChanges(changedGroups.keySet());
    if (checkSafeToRemoveIfCPMemberLeaving(membershipChangeSchedule)) {
        CPMemberInfo leavingMember = membershipChangeSchedule.getLeavingMember();
        removeActiveMember(commitIndex, leavingMember);
        completeFutures(getMetadataGroupId(), membershipChangeSchedule.getMembershipChangeCommitIndices(), null);
        membershipChangeSchedule = null;
        logger.info(leavingMember + " is removed from CP Subsystem.");
    } else if (membershipChangeSchedule.getChanges().isEmpty()) {
        completeFutures(getMetadataGroupId(), membershipChangeSchedule.getMembershipChangeCommitIndices(), null);
        membershipChangeSchedule = null;
        logger.info("Rebalancing is completed.");
    }
    return membershipChangeSchedule;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroupMembershipChange(com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange)

Example 34 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method initMembershipChangeScheduleForLeavingMember.

private boolean initMembershipChangeScheduleForLeavingMember(long commitIndex, CPMemberInfo leavingMember) {
    List<CPGroupId> leavingGroupIds = new ArrayList<>();
    List<CPGroupMembershipChange> changes = new ArrayList<>();
    for (CPGroupInfo group : groups.values()) {
        CPGroupId groupId = group.id();
        if (!group.containsMember(leavingMember.toRaftEndpoint()) || group.status() == DESTROYED) {
            continue;
        }
        CPMemberInfo substitute = findSubstitute(group);
        RaftEndpoint substituteEndpoint = substitute != null ? substitute.toRaftEndpoint() : null;
        leavingGroupIds.add(groupId);
        changes.add(new CPGroupMembershipChange(groupId, group.getMembersCommitIndex(), group.memberImpls(), substituteEndpoint, leavingMember.toRaftEndpoint()));
    }
    if (changes.isEmpty()) {
        if (logger.isFineEnabled()) {
            logger.fine("Removing " + leavingMember + " directly since it is not present in any CP group.");
        }
        removeActiveMember(commitIndex, leavingMember);
        return true;
    }
    membershipChangeSchedule = MembershipChangeSchedule.forLeavingMember(singletonList(commitIndex), leavingMember, changes);
    if (logger.isFineEnabled()) {
        logger.info(leavingMember + " will be removed from " + changes);
    } else {
        logger.info(leavingMember + " will be removed from " + leavingGroupIds);
    }
    return false;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) CPGroupMembershipChange(com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange)

Example 35 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method completeDestroyRaftGroups.

public void completeDestroyRaftGroups(Set<CPGroupId> groupIds) {
    checkNotNull(groupIds);
    for (CPGroupId groupId : groupIds) {
        checkNotNull(groupId);
        if (!groups.containsKey(groupId)) {
            String msg = groupId + " does not exist to complete destroy";
            logger.warning(msg);
            throw new IllegalArgumentException(msg);
        }
    }
    for (CPGroupId groupId : groupIds) {
        completeDestroyRaftGroup(groups.get(groupId));
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId)

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5