use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionStateManager method replaceMember.
int replaceMember(Member oldMember, Member newMember) {
if (!initialized) {
return 0;
}
PartitionReplica oldReplica = PartitionReplica.from(oldMember);
PartitionReplica newReplica = PartitionReplica.from(newMember);
int count = 0;
for (InternalPartitionImpl partition : partitions) {
if (partition.replaceReplica(oldReplica, newReplica) > -1) {
count++;
}
}
if (count > 0) {
node.getNodeExtension().onPartitionStateChange();
logger.info("Replaced " + oldMember + " with " + newMember + " in partition table in " + count + " partitions.");
}
return count;
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionReplicaManager method triggerPartitionReplicaSync.
/**
* This method is called on a backup node (replica). Given all conditions are satisfied, this method initiates a replica sync
* operation and registers it to replicaSyncRequest. The operation is scheduled for a future execution if :
* <ul>
* <li>the {@code delayMillis} is greater than 0</li>
* <li>if a migration is not allowed (during repartitioning or a node joining the cluster)</li>
* <li>the partition is currently migrating</li>
* <li>another sync request has already been sent</li>
* <li>the maximum number of parallel synchronizations has already been reached</li>
* </ul>
*
* @param partitionId the partition which is being synchronized
* @param namespaces namespaces of partition replica fragments
* @param replicaIndex the index of the replica which is being synchronized
* @throws IllegalArgumentException if the replica index is not between 0 and {@link InternalPartition#MAX_REPLICA_COUNT}
*/
public void triggerPartitionReplicaSync(int partitionId, Collection<ServiceNamespace> namespaces, int replicaIndex) {
assert replicaIndex >= 0 && replicaIndex < InternalPartition.MAX_REPLICA_COUNT : "Invalid replica index! partitionId=" + partitionId + ", replicaIndex=" + replicaIndex;
PartitionReplica target = checkAndGetPrimaryReplicaOwner(partitionId, replicaIndex);
if (target == null) {
return;
}
if (!partitionService.areMigrationTasksAllowed()) {
logger.finest("Cannot send sync replica request for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + namespaces + ". Sync is not allowed.");
return;
}
InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
if (partition.isMigrating()) {
logger.finest("Cannot send sync replica request for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + namespaces + ". Partition is already migrating.");
return;
}
sendSyncReplicaRequest(partitionId, namespaces, replicaIndex, target);
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionStateGeneratorImpl method updatePartitionState.
private void updatePartitionState(PartitionReplica[][] state, Collection<NodeGroup> groups, int index) {
for (NodeGroup group : groups) {
group.postProcessPartitionTable(index);
for (PartitionReplica replica : group.getReplicas()) {
PartitionTable table = group.getPartitionTable(replica);
Set<Integer> set = table.getPartitions(index);
for (Integer partitionId : set) {
state[partitionId][index] = replica;
}
}
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionStateGeneratorImpl method initialize.
private void initialize(InternalPartition[] currentState, PartitionReplica[][] state, Collection<Integer> partitions) {
int partitionCount = currentState.length;
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
InternalPartition p = currentState[partitionId];
PartitionReplica[] replicas = state[partitionId];
boolean empty = true;
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
replicas[index] = p.getReplica(index);
empty &= replicas[index] == null;
}
if (empty || partitions != null && !partitions.contains(partitionId)) {
continue;
}
// auto shift-up colder replicas to hotter replicas to fill the empty gaps
int maxReplicaIndex = InternalPartition.MAX_REPLICA_COUNT - 1;
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
if (replicas[index] == null) {
for (int k = maxReplicaIndex; k > index; k--) {
if (replicas[k] != null) {
replicas[index] = replicas[k];
replicas[k] = null;
maxReplicaIndex = k - 1;
break;
}
}
}
}
}
}
use of com.hazelcast.internal.partition.PartitionReplica 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);
}
Aggregations