Search in sources :

Example 11 with IPartitionService

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

the class RingbufferService method prepareReplicationOperation.

@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
    Map<String, RingbufferContainer> migrationData = new HashMap<String, RingbufferContainer>();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    for (Map.Entry<String, RingbufferContainer> entry : containers.entrySet()) {
        String name = entry.getKey();
        int partitionId = partitionService.getPartitionId(getPartitionKey(name));
        RingbufferContainer container = entry.getValue();
        int backupCount = container.getConfig().getTotalBackupCount();
        if (partitionId == event.getPartitionId() && backupCount >= event.getReplicaIndex()) {
            migrationData.put(name, container);
        }
    }
    if (migrationData.isEmpty()) {
        return null;
    }
    return new ReplicationOperation(migrationData, event.getPartitionId(), event.getReplicaIndex());
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IPartitionService(com.hazelcast.spi.partition.IPartitionService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ReplicationOperation(com.hazelcast.ringbuffer.impl.operations.ReplicationOperation)

Example 12 with IPartitionService

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

the class PutAllOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(name, true, getPartitionId());
    int partitionId = getPartitionId();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    ReplicatedMapEventPublishingService eventPublishingService = service.getEventPublishingService();
    for (int i = 0; i < entries.size(); i++) {
        Data key = entries.getKey(i);
        Data value = entries.getValue(i);
        if (partitionId != partitionService.getPartitionId(key)) {
            continue;
        }
        Object putResult = store.put(key, value);
        Data oldValue = getNodeEngine().toData(putResult);
        eventPublishingService.fireEntryListenerEvent(key, oldValue, value, name, getCallerAddress());
        VersionResponsePair response = new VersionResponsePair(putResult, store.getVersion());
        publishReplicationMessage(key, value, response);
    }
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) IPartitionService(com.hazelcast.spi.partition.IPartitionService) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) Data(com.hazelcast.nio.serialization.Data) ReplicatedMapEventPublishingService(com.hazelcast.replicatedmap.impl.ReplicatedMapEventPublishingService)

Example 13 with IPartitionService

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

the class XAResourceImpl method finalizeTransactionRemotely.

private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    Data xidData = nodeEngine.toData(serializableXID);
    int partitionId = partitionService.getPartitionId(xidData);
    FinalizeRemoteTransactionOperation operation = new FinalizeRemoteTransactionOperation(xidData, isCommit);
    InternalCompletableFuture<Integer> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
    Integer errorCode;
    try {
        errorCode = future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    if (errorCode != null) {
        throw new XAException(errorCode);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) XAException(javax.transaction.xa.XAException) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data) OperationService(com.hazelcast.spi.OperationService) FinalizeRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.FinalizeRemoteTransactionOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) MemberLeftException(com.hazelcast.core.MemberLeftException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExecutionException(java.util.concurrent.ExecutionException) XAException(javax.transaction.xa.XAException)

Example 14 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 15 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)

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