Search in sources :

Example 36 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class XAResourceImpl method recover.

@Override
public Xid[] recover(int flag) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    XAService xaService = getService();
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    Collection<Member> memberList = clusterService.getMembers();
    List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
    for (Member member : memberList) {
        if (member.localMember()) {
            continue;
        }
        CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
        Address address = member.getAddress();
        InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
        futureList.add(future);
    }
    Set<SerializableXID> xids = new HashSet<SerializableXID>(xaService.getPreparedXids());
    for (Future<SerializableList> future : futureList) {
        try {
            SerializableList xidSet = future.get();
            for (Data xidData : xidSet) {
                SerializableXID xid = nodeEngine.toObject(xidData);
                xids.add(xid);
            }
        } catch (InterruptedException e) {
            currentThread().interrupt();
            throw new XAException(XAException.XAER_RMERR);
        } catch (MemberLeftException e) {
            logger.warning("Member left while recovering", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
                logger.warning("Member left while recovering", e);
            } else {
                throw new XAException(XAException.XAER_RMERR);
            }
        }
    }
    return xids.toArray(new SerializableXID[0]);
}
Also used : Address(com.hazelcast.cluster.Address) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeEngine(com.hazelcast.spi.impl.NodeEngine) CollectRemoteTransactionsOperation(com.hazelcast.transaction.impl.xa.operations.CollectRemoteTransactionsOperation) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) XAException(javax.transaction.xa.XAException) Data(com.hazelcast.internal.serialization.Data) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClusterService(com.hazelcast.internal.cluster.ClusterService) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 37 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class ScheduledExecutorServiceProxy method accumulateTaskHandlersAsScheduledFutures.

@SuppressWarnings("unchecked")
private <V> void accumulateTaskHandlersAsScheduledFutures(Map<Member, List<IScheduledFuture<V>>> accumulator, Map<?, ?> taskHandlersMap) {
    ClusterService clusterService = getNodeEngine().getClusterService();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    for (Map.Entry<?, ?> entry : taskHandlersMap.entrySet()) {
        Member owner;
        Object key = entry.getKey();
        if (key instanceof Number) {
            owner = clusterService.getMember(partitionService.getPartitionOwner((Integer) key));
        } else {
            owner = (Member) key;
        }
        List<ScheduledTaskHandler> handlers = (List<ScheduledTaskHandler>) entry.getValue();
        List<IScheduledFuture<V>> futures = new ArrayList<>();
        for (ScheduledTaskHandler handler : handlers) {
            IScheduledFuture future = new ScheduledFutureProxy(handler, this);
            futures.add(initializeManagedContext(future));
        }
        if (accumulator.containsKey(owner)) {
            List<IScheduledFuture<V>> memberFutures = accumulator.get(owner);
            memberFutures.addAll(futures);
        } else {
            accumulator.put(owner, futures);
        }
    }
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) ArrayList(java.util.ArrayList) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ClusterService(com.hazelcast.internal.cluster.ClusterService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(com.hazelcast.cluster.Member)

Example 38 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class TransactionImpl method purgeBackupLogs.

private void purgeBackupLogs() {
    if (!backupLogsCreated) {
        return;
    }
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    for (Address backupAddress : backupAddresses) {
        if (clusterService.getMember(backupAddress) != null) {
            try {
                operationService.invokeOnTarget(SERVICE_NAME, createPurgeTxBackupLogOperation(), backupAddress);
            } catch (Throwable e) {
                logger.warning("Error during purging backups!", e);
            }
        }
    }
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.cluster.Address) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 39 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService 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 40 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleGetClusterVersion.

private void handleGetClusterVersion(HttpGetCommand command) {
    Node node = textCommandService.getNode();
    ClusterService clusterService = node.getClusterService();
    JsonObject response = new JsonObject().add("status", "success").add("version", clusterService.getClusterVersion().toString());
    prepareResponse(command, response);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Node(com.hazelcast.instance.impl.Node) JsonObject(com.hazelcast.internal.json.JsonObject)

Aggregations

ClusterService (com.hazelcast.internal.cluster.ClusterService)53 Address (com.hazelcast.cluster.Address)11 Member (com.hazelcast.cluster.Member)10 ArrayList (java.util.ArrayList)10 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)8 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)8 Future (java.util.concurrent.Future)8 UUID (java.util.UUID)6 CPMember (com.hazelcast.cp.CPMember)5 ILogger (com.hazelcast.logging.ILogger)5 Accessors.getClusterService (com.hazelcast.test.Accessors.getClusterService)5 ClusterState (com.hazelcast.cluster.ClusterState)4 Node (com.hazelcast.instance.impl.Node)4 JsonObject (com.hazelcast.internal.json.JsonObject)4 AbstractJobTracker (com.hazelcast.mapreduce.impl.AbstractJobTracker)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 Member (com.hazelcast.core.Member)3 CPGroupId (com.hazelcast.cp.CPGroupId)3 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)3