Search in sources :

Example 26 with IPartitionService

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

the class ListKeyValueSource method open.

@Override
public boolean open(NodeEngine nodeEngine) {
    NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
    ss = nei.getSerializationService();
    Address thisAddress = nei.getThisAddress();
    IPartitionService ps = nei.getPartitionService();
    Data data = ss.toData(listName, StringAndPartitionAwarePartitioningStrategy.INSTANCE);
    int partitionId = ps.getPartitionId(data);
    Address partitionOwner = ps.getPartitionOwner(partitionId);
    if (partitionOwner == null) {
        return false;
    }
    if (thisAddress.equals(partitionOwner)) {
        ListService listService = nei.getService(ListService.SERVICE_NAME);
        ListContainer listContainer = listService.getOrCreateContainer(listName, false);
        List<CollectionItem> items = new ArrayList<CollectionItem>(listContainer.getCollection());
        iterator = items.iterator();
    }
    return true;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ListService(com.hazelcast.collection.impl.list.ListService) Address(com.hazelcast.nio.Address) IPartitionService(com.hazelcast.spi.partition.IPartitionService) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) ListContainer(com.hazelcast.collection.impl.list.ListContainer) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 27 with IPartitionService

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

the class MapReduceUtil method enforcePartitionTableWarmup.

public static void enforcePartitionTableWarmup(MapReduceService mapReduceService) throws TimeoutException {
    IPartitionService partitionService = mapReduceService.getNodeEngine().getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    long startTime = Clock.currentTimeMillis();
    for (int p = 0; p < partitionCount; p++) {
        while (partitionService.getPartitionOwner(p) == null) {
            try {
                Thread.sleep(RETRY_PARTITION_TABLE_MILLIS);
            } catch (Exception ignore) {
                EmptyStatement.ignore(ignore);
            }
            if (Clock.currentTimeMillis() - startTime > PARTITION_READY_TIMEOUT) {
                throw new TimeoutException("Partition get ready timeout reached!");
            }
        }
    }
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 28 with IPartitionService

use of com.hazelcast.spi.partition.IPartitionService 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<IScheduledFuture<V>>();
        for (ScheduledTaskHandler handler : handlers) {
            IScheduledFuture future = new ScheduledFutureProxy(handler);
            attachHazelcastInstance(future);
            futures.add(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.spi.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.AbstractDistributedObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(com.hazelcast.core.Member)

Example 29 with IPartitionService

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

the class RingbufferService method clearRingbuffersHavingLesserBackupCountThan.

private void clearRingbuffersHavingLesserBackupCountThan(int partitionId, int thresholdReplicaIndex) {
    Iterator<Map.Entry<String, RingbufferContainer>> iterator = containers.entrySet().iterator();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    while (iterator.hasNext()) {
        Map.Entry<String, RingbufferContainer> entry = iterator.next();
        String name = entry.getKey();
        int containerPartitionId = partitionService.getPartitionId(getPartitionKey(name));
        if (containerPartitionId != partitionId) {
            continue;
        }
        RingbufferContainer container = entry.getValue();
        if (thresholdReplicaIndex < 0 || thresholdReplicaIndex > container.getConfig().getTotalBackupCount()) {
            iterator.remove();
        }
    }
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 30 with IPartitionService

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

the class AbstractCacheProxy method getPartitionsForKeys.

private Set<Integer> getPartitionsForKeys(Set<Data> keys) {
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    int partitions = partitionService.getPartitionCount();
    int capacity = Math.min(partitions, keys.size());
    Set<Integer> partitionIds = new HashSet<Integer>(capacity);
    Iterator<Data> iterator = keys.iterator();
    while (iterator.hasNext() && partitionIds.size() < partitions) {
        Data key = iterator.next();
        partitionIds.add(partitionService.getPartitionId(key));
    }
    return partitionIds;
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data) HashSet(java.util.HashSet)

Aggregations

IPartitionService (com.hazelcast.spi.partition.IPartitionService)48 Data (com.hazelcast.nio.serialization.Data)11 NodeEngine (com.hazelcast.spi.NodeEngine)11 Address (com.hazelcast.nio.Address)8 HashMap (java.util.HashMap)8 OperationService (com.hazelcast.spi.OperationService)7 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)7 Map (java.util.Map)7 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)5 IPartition (com.hazelcast.spi.partition.IPartition)5 MapService (com.hazelcast.map.impl.MapService)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ICacheService (com.hazelcast.cache.impl.ICacheService)2 CacheRecord (com.hazelcast.cache.impl.record.CacheRecord)2 QueueReplicationOperation (com.hazelcast.collection.impl.queue.operations.QueueReplicationOperation)2 Member (com.hazelcast.core.Member)2 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 MapEvictionPolicy (com.hazelcast.map.eviction.MapEvictionPolicy)2