Search in sources :

Example 1 with IPartitionService

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

the class QueueService method createLocalQueueStats.

/**
     * Returns the local queue statistics for the queue with the given {@code name}. If this node is the owner of the queue,
     * returned stats contain {@link LocalQueueStats#getOwnedItemCount()}, otherwise it contains
     * {@link LocalQueueStats#getBackupItemCount()}.
     *
     * @param name the name of the queue for which the statistics are returned
     * @return the statistics
     */
public LocalQueueStats createLocalQueueStats(String name) {
    SerializationService serializationService = nodeEngine.getSerializationService();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    Data keyData = serializationService.toData(name, StringPartitioningStrategy.INSTANCE);
    int partitionId = partitionService.getPartitionId(keyData);
    return createLocalQueueStats(name, partitionId);
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 2 with IPartitionService

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

the class CacheSplitBrainHandler method prepareMergeRunnable.

Runnable prepareMergeRunnable() {
    final Map<String, Map<Data, CacheRecord>> recordMap = new HashMap<String, Map<Data, CacheRecord>>(configs.size());
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final int partitionCount = partitionService.getPartitionCount();
    final Address thisAddress = nodeEngine.getClusterService().getThisAddress();
    for (int i = 0; i < partitionCount; i++) {
        // Add your owned entries so they will be merged
        if (thisAddress.equals(partitionService.getPartitionOwner(i))) {
            CachePartitionSegment segment = segments[i];
            Iterator<ICacheRecordStore> iter = segment.recordStoreIterator();
            while (iter.hasNext()) {
                ICacheRecordStore cacheRecordStore = iter.next();
                if (!(cacheRecordStore instanceof SplitBrainAwareCacheRecordStore)) {
                    continue;
                }
                String cacheName = cacheRecordStore.getName();
                Map<Data, CacheRecord> records = recordMap.get(cacheName);
                if (records == null) {
                    records = new HashMap<Data, CacheRecord>(cacheRecordStore.size());
                    recordMap.put(cacheName, records);
                }
                for (Map.Entry<Data, CacheRecord> cacheRecordEntry : cacheRecordStore.getReadOnlyRecords().entrySet()) {
                    Data key = cacheRecordEntry.getKey();
                    CacheRecord cacheRecord = cacheRecordEntry.getValue();
                    records.put(key, cacheRecord);
                }
                // Clear all records either owned or backup
                cacheRecordStore.clear();
                // send the cache invalidation event regardless if any actually cleared or not (no need to know how many
                // actually cleared)
                final CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
                cacheService.sendInvalidationEvent(cacheName, null, AbstractCacheRecordStore.SOURCE_NOT_AVAILABLE);
            }
        }
    }
    return new CacheMerger(nodeEngine, configs, recordMap, mergePolicyProvider);
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data) CacheRecord(com.hazelcast.cache.impl.record.CacheRecord) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with IPartitionService

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

the class CardinalityEstimatorService method getPartitionId.

private int getPartitionId(String name) {
    IPartitionService partitionService = nodeEngine.getPartitionService();
    String partitionKey = getPartitionKey(name);
    return partitionService.getPartitionId(partitionKey);
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService)

Example 4 with IPartitionService

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

the class CacheClearOperation method afterRun.

@Override
public void afterRun() throws Exception {
    super.afterRun();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    if (partitionService.getPartitionId(name) == getPartitionId()) {
        CacheService cacheService = getService();
        cacheService.sendInvalidationEvent(name, null, SOURCE_NOT_AVAILABLE);
    }
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 5 with IPartitionService

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

the class AddPartitionLostListenerMessageTask method call.

@Override
protected Object call() throws Exception {
    final IPartitionService partitionService = getService(getServiceName());
    final PartitionLostListener listener = new PartitionLostListener() {

        @Override
        public void partitionLost(PartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = ClientAddPartitionLostListenerCodec.encodePartitionLostEvent(event.getPartitionId(), event.getLostBackupCount(), event.getEventSource());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    String registrationId;
    if (parameters.localOnly) {
        registrationId = partitionService.addLocalPartitionLostListener(listener);
    } else {
        registrationId = partitionService.addPartitionLostListener(listener);
    }
    endpoint.addListenerDestroyAction(getServiceName(), PARTITION_LOST_EVENT_TOPIC, registrationId);
    return registrationId;
}
Also used : PartitionLostListener(com.hazelcast.partition.PartitionLostListener) IPartitionService(com.hazelcast.spi.partition.IPartitionService) PartitionLostEvent(com.hazelcast.partition.PartitionLostEvent) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

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