Search in sources :

Example 11 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class RingbufferService method prepareReplicationOperation.

@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces) {
    int partitionId = event.getPartitionId();
    Map<ObjectNamespace, RingbufferContainer> partitionContainers = containers.get(partitionId);
    if (isNullOrEmpty(partitionContainers)) {
        return null;
    }
    Map<ObjectNamespace, RingbufferContainer> migrationData = new HashMap<>();
    for (ServiceNamespace namespace : namespaces) {
        ObjectNamespace ns = (ObjectNamespace) namespace;
        RingbufferContainer container = partitionContainers.get(ns);
        if (container != null && container.getConfig().getTotalBackupCount() >= event.getReplicaIndex()) {
            migrationData.put(ns, container);
        }
    }
    if (migrationData.isEmpty()) {
        return null;
    }
    return new ReplicationOperation(migrationData, event.getPartitionId(), event.getReplicaIndex());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ReplicationOperation(com.hazelcast.ringbuffer.impl.operations.ReplicationOperation)

Example 12 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class ReplicaFragmentMigrationState method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeInt(namespaces.size());
    for (Map.Entry<ServiceNamespace, long[]> e : namespaces.entrySet()) {
        out.writeObject(e.getKey());
        out.writeLongArray(e.getValue());
    }
    out.writeInt(migrationOperations.size());
    for (Operation operation : migrationOperations) {
        out.writeObject(operation);
    }
    chunkSerDeHelper.writeChunkedOperations(out);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Operation(com.hazelcast.spi.impl.operationservice.Operation) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class AbstractPartitionPrimaryReplicaAntiEntropyTask method retainAndGetNamespaces.

// works only on primary. backups are retained
// in PartitionBackupReplicaAntiEntropyTask
final Collection<ServiceNamespace> retainAndGetNamespaces() {
    PartitionReplicationEvent event = new PartitionReplicationEvent(null, partitionId, 0);
    Collection<FragmentedMigrationAwareService> services = nodeEngine.getServices(FragmentedMigrationAwareService.class);
    Collection<ServiceNamespace> namespaces = new HashSet<>();
    for (FragmentedMigrationAwareService service : services) {
        Collection<ServiceNamespace> serviceNamespaces = service.getAllServiceNamespaces(event);
        if (serviceNamespaces != null) {
            namespaces.addAll(serviceNamespaces);
        }
    }
    namespaces.add(NonFragmentedServiceNamespace.INSTANCE);
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    replicaManager.retainNamespaces(partitionId, namespaces);
    ILogger logger = nodeEngine.getLogger(getClass());
    if (logger.isFinestEnabled()) {
        logger.finest("Retained namespaces for partitionId=" + partitionId + ". Service namespaces=" + namespaces + ", retained namespaces=" + replicaManager.getNamespaces(partitionId));
    }
    return replicaManager.getNamespaces(partitionId);
}
Also used : NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ILogger(com.hazelcast.logging.ILogger) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService) PartitionReplicationEvent(com.hazelcast.internal.partition.PartitionReplicationEvent) HashSet(java.util.HashSet)

Example 14 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class WriteBehindStateHolder method prepare.

void prepare(PartitionContainer container, Collection<ServiceNamespace> namespaces, int replicaIndex) {
    int size = namespaces.size();
    flushSequences = createHashMap(size);
    delayedEntries = createHashMap(size);
    reservationsByTxnIdPerMap = createHashMap(size);
    for (ServiceNamespace namespace : namespaces) {
        ObjectNamespace mapNamespace = (ObjectNamespace) namespace;
        String mapName = mapNamespace.getObjectName();
        RecordStore recordStore = container.getRecordStore(mapName);
        if (recordStore == null) {
            continue;
        }
        MapContainer mapContainer = recordStore.getMapContainer();
        MapConfig mapConfig = mapContainer.getMapConfig();
        if (mapConfig.getTotalBackupCount() < replicaIndex || !mapContainer.getMapStoreContext().isWriteBehindMapStoreEnabled()) {
            continue;
        }
        WriteBehindStore mapDataStore = (WriteBehindStore) recordStore.getMapDataStore();
        reservationsByTxnIdPerMap.put(mapName, mapDataStore.getTxnReservedCapacityCounter().getReservedCapacityCountPerTxnId());
        WriteBehindQueue<DelayedEntry> writeBehindQueue = mapDataStore.getWriteBehindQueue();
        List<DelayedEntry> entries = writeBehindQueue.asList();
        if (entries == null || entries.isEmpty()) {
            continue;
        }
        delayedEntries.put(mapName, entries);
        flushSequences.put(mapName, new ArrayDeque<>(mapDataStore.getFlushSequences()));
    }
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapConfig(com.hazelcast.config.MapConfig) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) DelayedEntries.newAddedDelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntries.newAddedDelayedEntry) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) MapContainer(com.hazelcast.map.impl.MapContainer) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Example 15 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class OperationBackupHandler method sendBackups0.

int sendBackups0(BackupAwareOperation backupAwareOp) {
    int requestedSyncBackups = requestedSyncBackups(backupAwareOp);
    int requestedAsyncBackups = requestedAsyncBackups(backupAwareOp);
    int requestedTotalBackups = requestedTotalBackups(backupAwareOp);
    if (requestedTotalBackups == 0) {
        return 0;
    }
    Operation op = (Operation) backupAwareOp;
    PartitionReplicaVersionManager versionManager = node.getPartitionService().getPartitionReplicaVersionManager();
    ServiceNamespace namespace = versionManager.getServiceNamespace(op);
    long[] replicaVersions = versionManager.incrementPartitionReplicaVersions(op.getPartitionId(), namespace, requestedTotalBackups);
    boolean syncForced = backpressureRegulator.isSyncForced(backupAwareOp);
    int syncBackups = syncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    int asyncBackups = asyncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    // TODO: This could cause a problem with back pressure
    if (!op.returnsResponse()) {
        asyncBackups += syncBackups;
        syncBackups = 0;
    }
    if (syncBackups + asyncBackups == 0) {
        return 0;
    }
    return makeBackups(backupAwareOp, op.getPartitionId(), replicaVersions, syncBackups, asyncBackups);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Aggregations

ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)40 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)11 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)8 HashMap (java.util.HashMap)7 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)6 ILogger (com.hazelcast.logging.ILogger)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)4 PartitionReplicaVersionManager (com.hazelcast.internal.partition.PartitionReplicaVersionManager)4 PartitionReplicationEvent (com.hazelcast.internal.partition.PartitionReplicationEvent)4 HashSet (java.util.HashSet)4 Address (com.hazelcast.cluster.Address)3 ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)2 CacheService (com.hazelcast.cache.impl.CacheService)2 CacheConfig (com.hazelcast.config.CacheConfig)2