Search in sources :

Example 6 with ServiceNamespace

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

the class PartitionReplicaManager method sendSyncReplicaRequest.

/**
 * Send the sync request to {@code target} if the max number of parallel sync requests has not been made and the target
 * was not removed while the cluster was not active. Also cancel any currently scheduled sync requests for the given
 * partition and schedule a new sync request that is to be run in the case of timeout
 */
private void sendSyncReplicaRequest(int partitionId, Collection<ServiceNamespace> requestedNamespaces, int replicaIndex, PartitionReplica target) {
    if (node.clusterService.isMissingMember(target.address(), target.uuid())) {
        return;
    }
    int permits = tryAcquireReplicaSyncPermits(requestedNamespaces.size());
    if (permits == 0) {
        if (logger.isFinestEnabled()) {
            logger.finest("Cannot send sync replica request for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + requestedNamespaces + ". No permits available!");
        }
        return;
    }
    // Select only permitted number of namespaces
    Collection<ServiceNamespace> namespaces = registerSyncInfoForNamespaces(partitionId, requestedNamespaces, replicaIndex, target, permits);
    // release unused permits
    if (namespaces.size() != permits) {
        releaseReplicaSyncPermits(permits - namespaces.size());
    }
    if (namespaces.isEmpty()) {
        return;
    }
    if (logger.isFinestEnabled()) {
        logger.finest("Sending sync replica request for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + namespaces);
    }
    replicaSyncRequestsCounter.inc();
    Operation syncRequest = ALLOW_OFFLOAD ? new PartitionReplicaSyncRequestOffloadable(namespaces, partitionId, replicaIndex) : new PartitionReplicaSyncRequest(namespaces, partitionId, replicaIndex);
    nodeEngine.getOperationService().send(syncRequest, target.address());
}
Also used : PartitionReplicaSyncRequest(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequest) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaSyncRequestOffloadable(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequestOffloadable) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 7 with ServiceNamespace

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

the class PartitionReplicaSyncRequestOffloadable method readReplicaVersions.

private void readReplicaVersions() {
    InternalPartitionServiceImpl partitionService = getService();
    OperationService operationService = getNodeEngine().getOperationService();
    PartitionReplicaVersionManager versionManager = partitionService.getPartitionReplicaVersionManager();
    UrgentPartitionRunnable<Void> gatherReplicaVersionsRunnable = new UrgentPartitionRunnable<>(partitionId(), () -> {
        for (ServiceNamespace ns : namespaces) {
            // make a copy because
            // getPartitionReplicaVersions
            // returns references to the internal
            // replica versions data structures
            // that may change under our feet
            long[] versions = Arrays.copyOf(versionManager.getPartitionReplicaVersions(partitionId(), ns), IPartition.MAX_BACKUP_COUNT);
            replicaVersions.put(BiTuple.of(partitionId(), ns), versions);
        }
    });
    operationService.execute(gatherReplicaVersionsRunnable);
    gatherReplicaVersionsRunnable.future.joinInternal();
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 8 with ServiceNamespace

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

the class PartitionReplicaSyncRequest method sendOperationsForNamespaces.

/**
 * Send responses for first number of {@code permits} namespaces and remove them from the list.
 */
protected void sendOperationsForNamespaces(int permits) {
    InternalPartitionServiceImpl partitionService = getService();
    try {
        PartitionReplicationEvent event = new PartitionReplicationEvent(getCallerAddress(), partitionId(), getReplicaIndex());
        Iterator<ServiceNamespace> iterator = namespaces.iterator();
        for (int i = 0; i < permits; i++) {
            ServiceNamespace namespace = iterator.next();
            Collection<Operation> operations = Collections.emptyList();
            Collection<ChunkSupplier> chunkSuppliers = Collections.emptyList();
            if (NonFragmentedServiceNamespace.INSTANCE.equals(namespace)) {
                operations = createNonFragmentedReplicationOperations(event);
            } else {
                chunkSuppliers = isChunkedMigrationEnabled() ? collectChunkSuppliers(event, namespace) : chunkSuppliers;
                if (isEmpty(chunkSuppliers)) {
                    operations = createFragmentReplicationOperations(event, namespace);
                }
            }
            sendOperations(operations, chunkSuppliers, namespace);
            while (hasRemainingChunksToSend(chunkSuppliers)) {
                sendOperations(operations, chunkSuppliers, namespace);
            }
            iterator.remove();
        }
    } finally {
        partitionService.getReplicaManager().releaseReplicaSyncPermits(permits);
    }
}
Also used : ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationCycleOperation(com.hazelcast.internal.partition.MigrationCycleOperation) PartitionAwareOperation(com.hazelcast.spi.impl.operationservice.PartitionAwareOperation) PartitionReplicationEvent(com.hazelcast.internal.partition.PartitionReplicationEvent)

Example 9 with ServiceNamespace

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

the class MapReplicationStateHolder method prepare.

void prepare(PartitionContainer container, Collection<ServiceNamespace> namespaces, int replicaIndex) {
    storesByMapName = createHashMap(namespaces.size());
    loaded = createHashMap(namespaces.size());
    mapIndexInfos = new ArrayList<>(namespaces.size());
    for (ServiceNamespace namespace : namespaces) {
        ObjectNamespace mapNamespace = (ObjectNamespace) namespace;
        String mapName = mapNamespace.getObjectName();
        RecordStore recordStore = container.getExistingRecordStore(mapName);
        if (recordStore == null) {
            continue;
        }
        MapContainer mapContainer = recordStore.getMapContainer();
        MapConfig mapConfig = mapContainer.getMapConfig();
        if (mapConfig.getTotalBackupCount() < replicaIndex) {
            continue;
        }
        loaded.put(mapName, recordStore.isLoaded());
        storesByMapName.put(mapName, recordStore);
        statsByMapName.put(mapName, mapContainer.getMapServiceContext().getLocalMapStatsProvider().getLocalMapStatsImpl(mapName).getReplicationStats());
        Set<IndexConfig> indexConfigs = new HashSet<>();
        if (mapContainer.isGlobalIndexEnabled()) {
            // global-index
            final Indexes indexes = mapContainer.getIndexes();
            for (Index index : indexes.getIndexes()) {
                indexConfigs.add(index.getConfig());
            }
            indexConfigs.addAll(indexes.getIndexDefinitions());
        } else {
            // partitioned-index
            final Indexes indexes = mapContainer.getIndexes(container.getPartitionId());
            if (indexes != null && indexes.haveAtLeastOneIndexOrDefinition()) {
                for (Index index : indexes.getIndexes()) {
                    indexConfigs.add(index.getConfig());
                }
                indexConfigs.addAll(indexes.getIndexDefinitions());
            }
        }
        MapIndexInfo mapIndexInfo = new MapIndexInfo(mapName);
        mapIndexInfo.addIndexCofigs(indexConfigs);
        mapIndexInfos.add(mapIndexInfo);
    }
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) MapIndexInfo(com.hazelcast.query.impl.MapIndexInfo) InternalIndex(com.hazelcast.query.impl.InternalIndex) Index(com.hazelcast.query.impl.Index) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) IndexConfig(com.hazelcast.config.IndexConfig) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapConfig(com.hazelcast.config.MapConfig) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) HashSet(java.util.HashSet)

Example 10 with ServiceNamespace

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

the class MapNearCacheStateHolder method prepare.

void prepare(PartitionContainer container, Collection<ServiceNamespace> namespaces) {
    MapService mapService = container.getMapService();
    MetaDataGenerator metaData = getPartitionMetaDataGenerator(mapService);
    int partitionId = container.getPartitionId();
    partitionUuid = metaData.getOrCreateUuid(partitionId);
    List<Object> nameSeqPairs = new ArrayList<>(namespaces.size());
    for (ServiceNamespace namespace : namespaces) {
        ObjectNamespace mapNamespace = (ObjectNamespace) namespace;
        String mapName = mapNamespace.getObjectName();
        nameSeqPairs.add(mapName);
        nameSeqPairs.add(metaData.currentSequence(mapName, partitionId));
    }
    mapNameSequencePairs = nameSeqPairs;
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ArrayList(java.util.ArrayList) MapService(com.hazelcast.map.impl.MapService) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

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