use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class FinalizeMigrationOperation method commitSource.
/**
* Updates the replica versions on the migration source if the replica index has changed.
*/
private void commitSource() {
int partitionId = getPartitionId();
InternalPartitionServiceImpl partitionService = getService();
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
ILogger logger = getLogger();
int sourceNewReplicaIndex = migrationInfo.getSourceNewReplicaIndex();
if (sourceNewReplicaIndex < 0) {
clearPartitionReplicaVersions(partitionId);
if (logger.isFinestEnabled()) {
logger.finest("Replica versions are cleared in source after migration. partitionId=" + partitionId);
}
} else if (migrationInfo.getSourceCurrentReplicaIndex() != sourceNewReplicaIndex && sourceNewReplicaIndex > 1) {
for (ServiceNamespace namespace : replicaManager.getNamespaces(partitionId)) {
long[] versions = updatePartitionReplicaVersions(replicaManager, partitionId, namespace, sourceNewReplicaIndex - 1);
if (logger.isFinestEnabled()) {
logger.finest("Replica versions are set after SHIFT DOWN migration. partitionId=" + partitionId + " namespace: " + namespace + " replica versions=" + Arrays.toString(versions));
}
}
}
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class FinalizeMigrationOperation method clearPartitionReplicaVersions.
private void clearPartitionReplicaVersions(int partitionId) {
InternalPartitionServiceImpl partitionService = getService();
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
for (ServiceNamespace namespace : replicaManager.getNamespaces(partitionId)) {
replicaManager.clearPartitionReplicaVersions(partitionId, namespace);
}
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class MigrationOperation method afterMigrate.
private void afterMigrate() {
ILogger logger = getLogger();
if (success) {
InternalPartitionServiceImpl partitionService = getService();
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
int destinationNewReplicaIndex = migrationInfo.getDestinationNewReplicaIndex();
int replicaOffset = Math.max(destinationNewReplicaIndex, 1);
Map<ServiceNamespace, long[]> namespaceVersions = fragmentMigrationState.getNamespaceVersionMap();
for (Entry<ServiceNamespace, long[]> e : namespaceVersions.entrySet()) {
ServiceNamespace namespace = e.getKey();
long[] replicaVersions = e.getValue();
replicaManager.setPartitionReplicaVersions(migrationInfo.getPartitionId(), namespace, replicaVersions, replicaOffset);
if (logger.isFinestEnabled()) {
logger.finest("ReplicaVersions are set after migration. " + migrationInfo + ", namespace=" + namespace + ", replicaVersions=" + Arrays.toString(replicaVersions));
}
}
} else if (logger.isFinestEnabled()) {
logger.finest("ReplicaVersions are not set since migration failed. " + migrationInfo);
}
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class PartitionBackupReplicaAntiEntropyOperation method readInternal.
@Override
protected void readInternal(ObjectDataInput in) throws IOException {
int len = in.readInt();
versions = new HashMap<>(len);
for (int i = 0; i < len; i++) {
ServiceNamespace ns = in.readObject();
long v = in.readLong();
versions.put(ns, v);
}
returnResponse = in.readBoolean();
}
use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.
the class PartitionBackupReplicaAntiEntropyOperation method run.
@Override
public void run() {
if (!isNodeStartCompleted()) {
response = false;
return;
}
InternalPartitionServiceImpl partitionService = getService();
int partitionId = getPartitionId();
int replicaIndex = getReplicaIndex();
InternalPartitionImpl partition = partitionService.getPartitionStateManager().getPartitionImpl(partitionId);
int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(getNodeEngine().getLocalMember()));
ILogger logger = getLogger();
if (replicaIndex != currentReplicaIndex) {
logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received, but this node is not the expected backup replica!" + " Current replicaIndex=" + currentReplicaIndex);
response = false;
return;
}
Address ownerAddress = partition.getOwnerOrNull();
if (!getCallerAddress().equals(ownerAddress)) {
logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received from " + getCallerAddress() + ", but it's not the known primary replica owner: " + ownerAddress);
response = false;
return;
}
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
replicaManager.retainNamespaces(partitionId, versions.keySet());
if (logger.isFinestEnabled()) {
logger.finest("Retained namespaces for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ". Namespaces=" + replicaManager.getNamespaces(partitionId));
}
Iterator<Map.Entry<ServiceNamespace, Long>> iter = versions.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<ServiceNamespace, Long> entry = iter.next();
ServiceNamespace ns = entry.getKey();
long primaryVersion = entry.getValue();
long[] currentVersions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
long currentVersion = currentVersions[replicaIndex - 1];
if (replicaManager.isPartitionReplicaVersionDirty(partitionId, ns) || currentVersion != primaryVersion) {
logBackupVersionMismatch(ns, currentVersion, primaryVersion);
continue;
}
iter.remove();
}
if (!versions.isEmpty()) {
replicaManager.triggerPartitionReplicaSync(partitionId, versions.keySet(), replicaIndex);
response = false;
}
}
Aggregations