Search in sources :

Example 26 with CPGroupId

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

the class RaftSessionService method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    MetricDescriptor root = descriptor.withPrefix("cp.session");
    for (RaftSessionRegistry registry : registries.values()) {
        CPGroupId groupId = registry.groupId();
        for (CPSession session : registry.getSessions()) {
            MetricDescriptor desc = root.copy().withDiscriminator("id", session.id() + "@" + groupId.getName()).withTag("sessionId", String.valueOf(session.id())).withTag("group", groupId.getName());
            context.collect(desc.copy().withTag("endpoint", session.endpoint().toString()).withMetric("endpoint"), 0);
            context.collect(desc.copy().withTag("endpointType", session.endpointType().toString()).withMetric("endpointType"), 0);
            context.collect(desc.copy().withMetric("version"), session.version());
            context.collect(desc.copy().withUnit(ProbeUnit.MS).withMetric("creationTime"), session.creationTime());
            context.collect(desc.copy().withUnit(ProbeUnit.MS).withMetric("expirationTime"), session.expirationTime());
        }
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) CPSession(com.hazelcast.cp.session.CPSession)

Example 27 with CPGroupId

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

the class RaftSessionService method getInactiveSessions.

private Map<CPGroupId, Collection<Long>> getInactiveSessions() {
    Map<CPGroupId, Collection<Long>> response = new ConcurrentHashMap<>();
    Semaphore semaphore = new Semaphore(0);
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    Collection<RaftSessionRegistry> registries = new ArrayList<>(this.registries.values());
    for (RaftSessionRegistry registry : registries) {
        CPGroupId groupId = registry.groupId();
        operationService.execute(new PartitionSpecificRunnableAdaptor(() -> {
            Set<Long> activeSessionIds = new HashSet<>();
            for (SessionAwareService service : nodeEngine.getServices(SessionAwareService.class)) {
                activeSessionIds.addAll(service.getAttachedSessions(groupId));
            }
            Set<Long> inactiveSessionIds = new HashSet<>();
            for (CPSession session : registry.getSessions()) {
                if (!activeSessionIds.contains(session.id()) && session.creationTime() + getSessionTTLMillis() < Clock.currentTimeMillis()) {
                    inactiveSessionIds.add(session.id());
                }
            }
            if (inactiveSessionIds.size() > 0) {
                response.put(groupId, inactiveSessionIds);
            }
            semaphore.release();
        }, nodeEngine.getPartitionService().getPartitionId(groupId)));
    }
    try {
        semaphore.tryAcquire(registries.size(), COLLECT_INACTIVE_SESSIONS_TASK_TIMEOUT_SECONDS, SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return response;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) CPGroupId(com.hazelcast.cp.CPGroupId) PartitionSpecificRunnableAdaptor(com.hazelcast.cp.internal.util.PartitionSpecificRunnableAdaptor) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Collection(java.util.Collection) CPSession(com.hazelcast.cp.session.CPSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 28 with CPGroupId

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

the class TerminateRaftNodesOp method readInternal.

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

Example 29 with CPGroupId

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

the class AbstractSessionMessageTask method processMessage.

@Override
protected final void processMessage() {
    CPGroupId groupId = getGroupId();
    RaftOp raftOp = getRaftOp();
    invoke(groupId, raftOp);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) RaftOp(com.hazelcast.cp.internal.RaftOp)

Example 30 with CPGroupId

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

the class CompleteRaftGroupMembershipChangesOp method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    int count = in.readInt();
    changedGroups = new HashMap<>(count);
    for (int i = 0; i < count; i++) {
        CPGroupId groupId = in.readObject();
        long currMembersCommitIndex = in.readLong();
        long newMembersCommitIndex = in.readLong();
        changedGroups.put(groupId, BiTuple.of(currMembersCommitIndex, newMembersCommitIndex));
    }
}
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