@@ -30,6 +30,9 @@ const (
3030 // Requeue intervals
3131 requeueAfterShort = 10 * time .Second
3232 requeueAfterLong = 30 * time .Second
33+ // Error backoff - prevent tight retry loops when operations fail
34+ requeueAfterError = 30 * time .Second
35+ requeueAfterErrorMax = 5 * time .Minute
3336
3437 // Finalizer name
3538 finalizerName = "memgraph.base14.io/finalizer"
@@ -212,14 +215,17 @@ func (r *MemgraphClusterReconciler) reconcileResources(ctx context.Context, clus
212215
213216 // 7. Configure replication if we have a write instance and pods are ready
214217 var registeredReplicas int32
218+ var replicationError error
215219 if writeInstance != "" && len (pods ) > 1 {
216220 if err := r .ensureReplicationManager (); err != nil {
217221 log .Error ("failed to create replication manager" , zap .Error (err ))
222+ replicationError = err
218223 } else {
219224 if err := r .replicationManager .ConfigureReplication (ctx , cluster , pods , writeInstance , log ); err != nil {
220225 log .Error ("failed to configure replication" , zap .Error (err ))
221226 r .Recorder .Event (cluster , corev1 .EventTypeWarning , EventReasonReplicationError ,
222227 fmt .Sprintf ("Failed to configure replication: %v" , err ))
228+ replicationError = err
223229 } else {
224230 health , err := r .replicationManager .CheckReplicationHealth (ctx , cluster , writeInstance , log )
225231 if err == nil && health != nil {
@@ -264,6 +270,14 @@ func (r *MemgraphClusterReconciler) reconcileResources(ctx context.Context, clus
264270 return ctrl.Result {RequeueAfter : requeueAfterShort }, nil
265271 }
266272
273+ // If there was a replication error, use longer backoff to prevent overwhelming Memgraph
274+ if replicationError != nil {
275+ log .Info ("replication error occurred, using longer backoff" ,
276+ zap .Duration ("requeueAfter" , requeueAfterError ),
277+ zap .Error (replicationError ))
278+ return ctrl.Result {RequeueAfter : requeueAfterError }, nil
279+ }
280+
267281 // Requeue for periodic health checks
268282 return ctrl.Result {RequeueAfter : requeueAfterLong }, nil
269283}
0 commit comments