use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionPrimaryReplicaAntiEntropyTask method run.
@Override
public void run() {
try {
InternalPartition partition = partitionService.getPartition(partitionId, false);
if (!partition.isLocal() || partition.isMigrating()) {
return;
}
Collection<ServiceNamespace> namespaces = retainAndGetNamespaces();
for (int index = 1; index < MAX_REPLICA_COUNT; index++) {
PartitionReplica replica = partition.getReplica(index);
if (replica != null) {
invokePartitionBackupReplicaAntiEntropyOp(index, replica, namespaces, null);
}
}
} finally {
if (afterRun != null) {
afterRun.run();
}
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionReplicaManager method checkAndGetPrimaryReplicaOwner.
/**
* Checks preconditions for replica sync - if we don't know the owner yet, if this node is the owner or not a replica
*/
PartitionReplica checkAndGetPrimaryReplicaOwner(int partitionId, int replicaIndex) {
InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
PartitionReplica owner = partition.getOwnerReplicaOrNull();
if (owner == null) {
logger.info("Sync replica target is null, no need to sync -> partitionId=" + partitionId + ", replicaIndex=" + replicaIndex);
return null;
}
PartitionReplica localReplica = PartitionReplica.from(nodeEngine.getLocalMember());
if (owner.equals(localReplica)) {
if (logger.isFinestEnabled()) {
logger.finest("This node is now owner of partition, cannot sync replica -> partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", partition-info=" + partitionStateManager.getPartitionImpl(partitionId));
}
return null;
}
if (!partition.isOwnerOrBackup(localReplica)) {
if (logger.isFinestEnabled()) {
logger.finest("This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + " anymore.");
}
return null;
}
return owner;
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionStateGeneratorImpl method initializeGroupPartitions.
private void initializeGroupPartitions(PartitionReplica[][] state, Queue<NodeGroup> groups, int replicaCount, boolean aggressive, Collection<Integer> toBeArrangedPartitions) {
// reset partition before reuse
for (NodeGroup nodeGroup : groups) {
nodeGroup.resetPartitions();
}
for (int partitionId = 0; partitionId < state.length; partitionId++) {
PartitionReplica[] replicas = state[partitionId];
for (int replicaIndex = 0; replicaIndex < InternalPartition.MAX_REPLICA_COUNT; replicaIndex++) {
if (replicaIndex >= replicaCount) {
replicas[replicaIndex] = null;
continue;
}
PartitionReplica owner = replicas[replicaIndex];
boolean valid = false;
if (owner != null) {
valid = partitionOwnerAvailable(groups, partitionId, replicaIndex, owner);
}
if (!valid) {
replicas[replicaIndex] = null;
} else if (aggressive && replicaIndex < AGGRESSIVE_INDEX_THRESHOLD && (toBeArrangedPartitions == null || toBeArrangedPartitions.contains(partitionId))) {
for (int i = AGGRESSIVE_INDEX_THRESHOLD; i < replicaCount; i++) {
replicas[i] = null;
}
}
}
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionReplicaSyncResponse method nodeNotOwnsBackup.
/**
* Fail all replication operations with the exception that this node is no longer the replica with the sent index
*/
private void nodeNotOwnsBackup(InternalPartitionImpl partition) {
int partitionId = getPartitionId();
int replicaIndex = getReplicaIndex();
NodeEngine nodeEngine = getNodeEngine();
ILogger logger = getLogger();
if (logger.isFinestEnabled()) {
int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(nodeEngine.getLocalMember()));
logger.finest("This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + " anymore. current replicaIndex=" + currentReplicaIndex);
}
if (operations != null) {
PartitionReplica replica = partition.getReplica(replicaIndex);
Member targetMember = null;
if (replica != null) {
ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
targetMember = clusterService.getMember(replica.address(), replica.uuid());
}
Throwable throwable = new WrongTargetException(nodeEngine.getLocalMember(), targetMember, partitionId, replicaIndex, getClass().getName());
for (Operation op : operations) {
prepareOperation(op);
onOperationFailure(op, throwable);
}
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class InternalPartitionImpl method replaceReplica.
int replaceReplica(PartitionReplica oldReplica, PartitionReplica newReplica) {
for (int i = 0; i < MAX_REPLICA_COUNT; i++) {
PartitionReplica currentReplica = replicas[i];
if (currentReplica == null) {
break;
}
if (currentReplica.equals(oldReplica)) {
PartitionReplica[] newReplicas = copyOf(replicas, MAX_REPLICA_COUNT);
newReplicas[i] = newReplica;
replicas = newReplicas;
onReplicaChange(i, oldReplica, newReplica);
return i;
}
}
return -1;
}
Aggregations