Search in sources :

Example 6 with IPartitionService

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

the class EvictionMaxSizePolicyTest method setMockRuntimeMemoryInfoAccessor.

public static void setMockRuntimeMemoryInfoAccessor(IMap map, final long totalMemoryMB, final long freeMemoryMB, final long maxMemoryMB) {
    final MapProxyImpl mapProxy = (MapProxyImpl) map;
    final MapService mapService = (MapService) mapProxy.getService();
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    MemoryInfoAccessor memoryInfoAccessor = new MemoryInfoAccessor() {

        @Override
        public long getTotalMemory() {
            return MEGABYTES.toBytes(totalMemoryMB);
        }

        @Override
        public long getFreeMemory() {
            return MEGABYTES.toBytes(freeMemoryMB);
        }

        @Override
        public long getMaxMemory() {
            return MEGABYTES.toBytes(maxMemoryMB);
        }
    };
    MapContainer mapContainer = mapServiceContext.getMapContainer(map.getName());
    MapEvictionPolicy mapEvictionPolicy = mapContainer.getMapConfig().getMapEvictionPolicy();
    EvictionChecker evictionChecker = new EvictionChecker(memoryInfoAccessor, mapServiceContext);
    IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
    Evictor evictor = new TestEvictor(mapEvictionPolicy, evictionChecker, partitionService);
    mapContainer.setEvictor(evictor);
}
Also used : EvictionChecker(com.hazelcast.map.impl.eviction.EvictionChecker) IPartitionService(com.hazelcast.spi.partition.IPartitionService) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MemoryInfoAccessor(com.hazelcast.util.MemoryInfoAccessor) MapService(com.hazelcast.map.impl.MapService) Evictor(com.hazelcast.map.impl.eviction.Evictor) MapEvictionPolicy(com.hazelcast.map.eviction.MapEvictionPolicy) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 7 with IPartitionService

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

the class MapGetInvalidationMetaDataOperation method getOwnedPartitions.

private List<Integer> getOwnedPartitions() {
    List<Integer> ownedPartitions = new ArrayList<Integer>();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    for (int i = 0; i < partitionService.getPartitionCount(); i++) {
        if (partitionService.isPartitionOwner(i)) {
            ownedPartitions.add(i);
        }
    }
    return ownedPartitions;
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) ArrayList(java.util.ArrayList)

Example 8 with IPartitionService

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

the class RequestPartitionMapping method run.

@Override
public void run() throws Exception {
    MapReduceService mapReduceService = getService();
    JobSupervisor supervisor = mapReduceService.getJobSupervisor(getName(), getJobId());
    if (supervisor == null) {
        result = new RequestPartitionResult(NO_SUPERVISOR, -1);
        return;
    }
    IPartitionService ps = getNodeEngine().getPartitionService();
    List<Integer> memberPartitions = ps.getMemberPartitions(getCallerAddress());
    JobProcessInformationImpl processInformation = supervisor.getJobProcessInformation();
    while (true) {
        int selectedPartition = searchMemberPartitionToProcess(processInformation, memberPartitions);
        if (selectedPartition == -1) {
            // All partitions seem to be assigned so give up
            result = new RequestPartitionResult(NO_MORE_PARTITIONS, -1);
            return;
        }
        JobPartitionState.State nextState = stateChange(getCallerAddress(), selectedPartition, WAITING, processInformation, supervisor.getConfiguration());
        if (nextState == MAPPING) {
            result = new RequestPartitionResult(SUCCESSFUL, selectedPartition);
            return;
        }
    }
}
Also used : JobPartitionState(com.hazelcast.mapreduce.JobPartitionState) IPartitionService(com.hazelcast.spi.partition.IPartitionService) MapReduceService(com.hazelcast.mapreduce.impl.MapReduceService) JobProcessInformationImpl(com.hazelcast.mapreduce.impl.task.JobProcessInformationImpl) JobSupervisor(com.hazelcast.mapreduce.impl.task.JobSupervisor)

Example 9 with IPartitionService

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

the class MapKeyValueSource method open.

@Override
public boolean open(NodeEngine nodeEngine) {
    NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
    IPartitionService ps = nei.getPartitionService();
    MapService mapService = nei.getService(MapService.SERVICE_NAME);
    ss = nei.getSerializationService();
    Address partitionOwner = ps.getPartitionOwner(partitionId);
    if (partitionOwner == null) {
        return false;
    }
    RecordStore recordStore = mapService.getMapServiceContext().getRecordStore(partitionId, mapName);
    iterator = recordStore.iterator();
    return true;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Address(com.hazelcast.nio.Address) IPartitionService(com.hazelcast.spi.partition.IPartitionService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService)

Example 10 with IPartitionService

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

the class MultiMapKeyValueSource method open.

@Override
public boolean open(NodeEngine nodeEngine) {
    NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
    IPartitionService ps = nei.getPartitionService();
    MultiMapService multiMapService = nei.getService(MultiMapService.SERVICE_NAME);
    ss = nei.getSerializationService();
    Address partitionOwner = ps.getPartitionOwner(partitionId);
    if (partitionOwner == null) {
        return false;
    }
    multiMapContainer = multiMapService.getOrCreateCollectionContainer(partitionId, multiMapName);
    isBinary = multiMapContainer.getConfig().isBinary();
    keyIterator = multiMapContainer.keySet().iterator();
    return true;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Address(com.hazelcast.nio.Address) IPartitionService(com.hazelcast.spi.partition.IPartitionService) MultiMapService(com.hazelcast.multimap.impl.MultiMapService)

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