Skip to content

Commit 9f45368

Browse files
leon-apeapecloud-bot
authored andcommitted
fix: do not select the replicas being scaled as the data source (#9639)
(cherry picked from commit a92d6c5)
1 parent 9a0555c commit 9f45368

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

controllers/apps/component/transformer_component_workload_ops.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ func (r *componentWorkloadOps) buildDataReplicationTask() error {
266266

267267
// replicas to be created
268268
newReplicas := r.desiredCompPodNameSet.Difference(r.runningItsPodNameSet).UnsortedList()
269+
if len(newReplicas) == 0 {
270+
return nil
271+
}
269272

270273
// replicas in provisioning that the data has not been loaded
271274
provisioningReplicas, err := component.GetReplicasStatusFunc(r.protoITS, func(s component.ReplicaStatus) bool {
@@ -275,17 +278,13 @@ func (r *componentWorkloadOps) buildDataReplicationTask() error {
275278
return err
276279
}
277280

278-
replicas := append(slices.Clone(newReplicas), provisioningReplicas...)
279-
if len(replicas) == 0 {
280-
return nil
281-
}
282-
283281
// the source replica
284-
source, err := r.sourceReplica(r.synthesizeComp.LifecycleActions.DataDump)
282+
source, err := r.sourceReplica(r.synthesizeComp.LifecycleActions.DataDump, provisioningReplicas)
285283
if err != nil {
286284
return err
287285
}
288286

287+
replicas := append(slices.Clone(newReplicas), provisioningReplicas...)
289288
parameters, err := component.NewReplicaTask(r.synthesizeComp.FullCompName, r.synthesizeComp.Generation, source, replicas)
290289
if err != nil {
291290
return err
@@ -300,16 +299,23 @@ func (r *componentWorkloadOps) buildDataReplicationTask() error {
300299
return createOrUpdateEnvConfigMap(transCtx, r.dag, parameters)
301300
}
302301

303-
func (r *componentWorkloadOps) sourceReplica(dataDump *appsv1.Action) (*corev1.Pod, error) {
302+
func (r *componentWorkloadOps) sourceReplica(dataDump *appsv1.Action, provisioningReplicas []string) (*corev1.Pod, error) {
304303
pods, err := component.ListOwnedPods(r.transCtx.Context, r.cli,
305304
r.synthesizeComp.Namespace, r.synthesizeComp.ClusterName, r.synthesizeComp.Name)
306305
if err != nil {
307306
return nil, err
308307
}
308+
if len(provisioningReplicas) > 0 {
309+
// exclude provisioning replicas
310+
pods = slices.DeleteFunc(pods, func(pod *corev1.Pod) bool {
311+
return slices.Contains(provisioningReplicas, pod.Name)
312+
})
313+
}
309314
if len(pods) > 0 {
310315
if len(dataDump.Exec.TargetPodSelector) == 0 {
311316
dataDump.Exec.TargetPodSelector = appsv1.AnyReplica
312317
}
318+
// TODO: idempotence for provisioning replicas
313319
pods, err = lifecycle.SelectTargetPods(pods, nil, dataDump)
314320
if err != nil {
315321
return nil, err

0 commit comments

Comments
 (0)