Search in sources :

Example 16 with IPartitionService

use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.

the class CacheProxySupport method getPartitionsForKeys.

protected PartitionIdSet getPartitionsForKeys(Set<Data> keys) {
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    int partitions = partitionService.getPartitionCount();
    PartitionIdSet partitionIds = new PartitionIdSet(partitions);
    Iterator<Data> iterator = keys.iterator();
    int addedPartitions = 0;
    while (iterator.hasNext() && addedPartitions < partitions) {
        Data key = iterator.next();
        if (partitionIds.add(partitionService.getPartitionId(key))) {
            addedPartitions++;
        }
    }
    return partitionIds;
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Data(com.hazelcast.internal.serialization.Data)

Example 17 with IPartitionService

use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.

the class CacheLoadAllOperation method run.

@Override
public void run() throws Exception {
    int partitionId = getPartitionId();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    Set<Data> filteredKeys = null;
    if (keys != null) {
        filteredKeys = new HashSet<Data>();
        for (Data k : keys) {
            if (partitionService.getPartitionId(k) == partitionId) {
                filteredKeys.add(k);
            }
        }
    }
    if (filteredKeys == null || filteredKeys.isEmpty()) {
        return;
    }
    try {
        ICacheService service = getService();
        cache = service.getOrCreateRecordStore(name, partitionId);
        Set<Data> keysLoaded = cache.loadAll(filteredKeys, replaceExistingValues);
        int loadedKeyCount = keysLoaded.size();
        if (loadedKeyCount > 0) {
            backupRecords = createHashMap(loadedKeyCount);
            for (Data key : keysLoaded) {
                CacheRecord record = cache.getRecord(key);
                // So if the loaded key is evicted, don't send it to backup.
                if (record != null) {
                    backupRecords.put(key, record);
                }
            }
            shouldBackup = !backupRecords.isEmpty();
        }
    } catch (CacheException e) {
        response = new CacheClearResponse(e);
    }
}
Also used : CacheClearResponse(com.hazelcast.cache.impl.CacheClearResponse) CacheRecord(com.hazelcast.cache.impl.record.CacheRecord) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data)

Example 18 with IPartitionService

use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.

the class CacheGetInvalidationMetaDataOperation method getOwnedPartitions.

private List<Integer> getOwnedPartitions() {
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
    List<Integer> ownedPartitions = memberPartitionsMap.get(getNodeEngine().getThisAddress());
    return ownedPartitions == null ? Collections.<Integer>emptyList() : ownedPartitions;
}
Also used : Address(com.hazelcast.cluster.Address) IPartitionService(com.hazelcast.internal.partition.IPartitionService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with IPartitionService

use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.

the class CardinalityEstimatorService method prepareReplicationOperation.

@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final int roughSize = (int) ((containers.size() * SIZING_FUDGE_FACTOR) / partitionService.getPartitionCount());
    Map<String, CardinalityEstimatorContainer> data = createHashMap(roughSize);
    int partitionId = event.getPartitionId();
    for (Map.Entry<String, CardinalityEstimatorContainer> containerEntry : containers.entrySet()) {
        String name = containerEntry.getKey();
        CardinalityEstimatorContainer container = containerEntry.getValue();
        if (partitionId == getPartitionId(name) && event.getReplicaIndex() <= container.getTotalBackupCount()) {
            data.put(name, containerEntry.getValue());
        }
    }
    return data.isEmpty() ? null : new ReplicationOperation(data);
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) ReplicationOperation(com.hazelcast.cardinality.impl.operations.ReplicationOperation)

Example 20 with IPartitionService

use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.

the class AddPartitionLostListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    final IPartitionService partitionService = getService(getServiceName());
    final PartitionLostListener listener = event -> {
        if (endpoint.isAlive()) {
            ClusterService clusterService = getService(ClusterServiceImpl.SERVICE_NAME);
            Address eventSource = event.getEventSource();
            MemberImpl member = clusterService.getMember(eventSource);
            ClientMessage eventMessage = ClientAddPartitionLostListenerCodec.encodePartitionLostEvent(event.getPartitionId(), event.getLostBackupCount(), member.getUuid());
            sendClientMessage(null, eventMessage);
        }
    };
    if (parameters) {
        return newCompletedFuture(partitionService.addLocalPartitionLostListener(listener));
    }
    return partitionService.addPartitionLostListenerAsync(listener);
}
Also used : Address(com.hazelcast.cluster.Address) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) Connection(com.hazelcast.internal.nio.Connection) IPartitionService(com.hazelcast.internal.partition.IPartitionService) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) Node(com.hazelcast.instance.impl.Node) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ClusterService(com.hazelcast.internal.cluster.ClusterService) ClientAddPartitionLostListenerCodec(com.hazelcast.client.impl.protocol.codec.ClientAddPartitionLostListenerCodec) PARTITION_LOST_EVENT_TOPIC(com.hazelcast.internal.partition.InternalPartitionService.PARTITION_LOST_EVENT_TOPIC) Permission(java.security.Permission) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.cluster.Address) IPartitionService(com.hazelcast.internal.partition.IPartitionService) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

IPartitionService (com.hazelcast.internal.partition.IPartitionService)36 Data (com.hazelcast.internal.serialization.Data)10 NodeEngine (com.hazelcast.spi.impl.NodeEngine)10 Address (com.hazelcast.cluster.Address)8 List (java.util.List)7 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)6 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)5 IPartition (com.hazelcast.internal.partition.IPartition)4 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)4 MapService (com.hazelcast.map.impl.MapService)4 ClusterService (com.hazelcast.internal.cluster.ClusterService)3 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)3 ICacheService (com.hazelcast.cache.impl.ICacheService)2 Connection (com.hazelcast.internal.nio.Connection)2 JobConfig (com.hazelcast.jet.config.JobConfig)2 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)2 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)2