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);
}
}
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);
}
}
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;
}
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;
}
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));
}
}
Aggregations