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());
}
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();
}
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);
}
}
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);
}
}
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;
}
Aggregations