use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class NameSpaceUtil method getAllNamespaces.
/**
* @param containers collection of all containers in a partition
* @param containerFilter allows only matching containers
* @param toNamespace returns {@link ObjectNamespace} for a container
*
* @return all service namespaces after functions are applied
*/
public static <T> Collection<ServiceNamespace> getAllNamespaces(Map<?, T> containers, Predicate<T> containerFilter, Function<T, ObjectNamespace> toNamespace) {
if (MapUtil.isNullOrEmpty(containers)) {
return Collections.emptySet();
}
Collection<ServiceNamespace> collection = Collections.emptySet();
for (T container : containers.values()) {
if (!containerFilter.test(container)) {
continue;
}
ObjectNamespace namespace = toNamespace.apply(container);
if (collection.isEmpty()) {
collection = singleton(namespace);
continue;
}
if (collection.size() == 1) {
// previous is an immutable singleton set
collection = new HashSet<>(collection);
collection.add(namespace);
continue;
}
collection.add(namespace);
}
return collection;
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class CheckPartitionReplicaVersionTask method run.
@Override
public void run() {
InternalPartition partition = partitionService.getPartition(partitionId);
if (!partition.isLocal() || partition.isMigrating()) {
callback.accept(false, null);
return;
}
Collection<ServiceNamespace> namespaces = retainAndGetNamespaces();
PartitionReplica target = partition.getReplica(replicaIndex);
if (target == null) {
callback.accept(false, null);
return;
}
invokePartitionBackupReplicaAntiEntropyOp(replicaIndex, target, namespaces, callback);
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class ReplicaFragmentMigrationState method readData.
@Override
public void readData(ObjectDataInput in) throws IOException {
int namespaceSize = in.readInt();
namespaces = new HashMap<>(namespaceSize);
for (int i = 0; i < namespaceSize; i++) {
ServiceNamespace namespace = in.readObject();
long[] replicaVersions = in.readLongArray();
namespaces.put(namespace, replicaVersions);
}
int migrationOperationSize = in.readInt();
migrationOperations = new ArrayList<>(migrationOperationSize);
for (int i = 0; i < migrationOperationSize; i++) {
Operation migrationOperation = in.readObject();
migrationOperations.add(migrationOperation);
}
migrationOperations = readChunkedOperations(in, migrationOperations);
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class AbstractPartitionPrimaryReplicaAntiEntropyTask method invokePartitionBackupReplicaAntiEntropyOp.
final void invokePartitionBackupReplicaAntiEntropyOp(int replicaIndex, PartitionReplica target, Collection<ServiceNamespace> namespaces, BiConsumer<Object, Throwable> callback) {
if (skipSendingToTarget(target)) {
return;
}
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
Map<ServiceNamespace, Long> versionMap = new HashMap<>();
for (ServiceNamespace ns : namespaces) {
long[] versions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
long currentReplicaVersion = versions[replicaIndex - 1];
versionMap.put(ns, currentReplicaVersion);
}
boolean hasCallback = (callback != null);
Operation op = new PartitionBackupReplicaAntiEntropyOperation(versionMap, hasCallback);
op.setPartitionId(partitionId).setReplicaIndex(replicaIndex).setServiceName(SERVICE_NAME);
ILogger logger = nodeEngine.getLogger(getClass());
if (logger.isFinestEnabled()) {
logger.finest("Sending anti-entropy operation to " + target + " for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + versionMap);
}
OperationService operationService = nodeEngine.getOperationService();
if (hasCallback) {
operationService.createInvocationBuilder(SERVICE_NAME, op, target.address()).setTryCount(OPERATION_TRY_COUNT).setTryPauseMillis(OPERATION_TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(callback);
} else {
operationService.send(op, target.address());
}
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class FinalizeMigrationOperation method rollbackDestination.
/**
* Updates the replica versions on the migration destination.
*/
private void rollbackDestination() {
int partitionId = getPartitionId();
InternalPartitionServiceImpl partitionService = getService();
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
ILogger logger = getLogger();
int destinationCurrentReplicaIndex = migrationInfo.getDestinationCurrentReplicaIndex();
if (destinationCurrentReplicaIndex == -1) {
clearPartitionReplicaVersions(partitionId);
if (logger.isFinestEnabled()) {
logger.finest("Replica versions are cleared in destination after failed migration. partitionId=" + partitionId);
}
} else {
int replicaOffset = Math.max(migrationInfo.getDestinationCurrentReplicaIndex(), 1);
for (ServiceNamespace namespace : replicaManager.getNamespaces(partitionId)) {
long[] versions = updatePartitionReplicaVersions(replicaManager, partitionId, namespace, replicaOffset - 1);
if (logger.isFinestEnabled()) {
logger.finest("Replica versions are rolled back in destination after failed migration. partitionId=" + partitionId + " namespace: " + namespace + " replica versions=" + Arrays.toString(versions));
}
}
}
}
Aggregations