Search in sources :

Example 36 with IPartitionService

use of com.hazelcast.spi.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 = new HashMap<Data, CacheRecord>(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.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data)

Example 37 with IPartitionService

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

the class PartitionContainer method createRecordStore.

private RecordStore createRecordStore(String name) {
    MapServiceContext serviceContext = mapService.getMapServiceContext();
    MapContainer mapContainer = serviceContext.getMapContainer(name);
    MapConfig mapConfig = mapContainer.getMapConfig();
    NodeEngine nodeEngine = serviceContext.getNodeEngine();
    IPartitionService ps = nodeEngine.getPartitionService();
    OperationService opService = nodeEngine.getOperationService();
    ExecutionService execService = nodeEngine.getExecutionService();
    HazelcastProperties hazelcastProperties = nodeEngine.getProperties();
    MapKeyLoader keyLoader = new MapKeyLoader(name, opService, ps, nodeEngine.getClusterService(), execService, mapContainer.toData());
    keyLoader.setMaxBatch(hazelcastProperties.getInteger(GroupProperty.MAP_LOAD_CHUNK_SIZE));
    keyLoader.setMaxSize(getMaxSizePerNode(mapConfig.getMaxSizeConfig()));
    keyLoader.setHasBackup(mapConfig.getTotalBackupCount() > 0);
    keyLoader.setMapOperationProvider(serviceContext.getMapOperationProvider(name));
    RecordStore recordStore = serviceContext.createRecordStore(mapContainer, partitionId, keyLoader);
    recordStore.init();
    return recordStore;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) IPartitionService(com.hazelcast.spi.partition.IPartitionService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapConfig(com.hazelcast.config.MapConfig) OperationService(com.hazelcast.spi.OperationService) ExecutionService(com.hazelcast.spi.ExecutionService)

Example 38 with IPartitionService

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

the class EvictionChecker method isOwnerOrBackup.

protected boolean isOwnerOrBackup(int partitionId) {
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final IPartition partition = partitionService.getPartition(partitionId, false);
    final Address thisAddress = nodeEngine.getThisAddress();
    return partition.isOwnerOrBackup(thisAddress);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) IPartitionService(com.hazelcast.spi.partition.IPartitionService) IPartition(com.hazelcast.spi.partition.IPartition)

Example 39 with IPartitionService

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

the class EvictionChecker method findPartitionIds.

protected List<Integer> findPartitionIds() {
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final int partitionCount = partitionService.getPartitionCount();
    List<Integer> partitionIds = null;
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        if (isOwnerOrBackup(partitionId)) {
            if (partitionIds == null) {
                partitionIds = new ArrayList<Integer>();
            }
            partitionIds.add(partitionId);
        }
    }
    return partitionIds == null ? Collections.<Integer>emptyList() : partitionIds;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) IPartitionService(com.hazelcast.spi.partition.IPartitionService)

Example 40 with IPartitionService

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

the class GetAllOperation method run.

@Override
public void run() {
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    int partitionId = getPartitionId();
    Set<Data> partitionKeySet = new HashSet<Data>();
    for (Data key : keys) {
        if (partitionId == partitionService.getPartitionId(key)) {
            partitionKeySet.add(key);
        }
    }
    entries = recordStore.getAll(partitionKeySet);
}
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