Skip to content

Commit

Permalink
Check Sentinel Number In Memory
Browse files Browse the repository at this point in the history
  • Loading branch information
polefishu committed Dec 6, 2019
1 parent 181fe2a commit 9d3706a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
28 changes: 14 additions & 14 deletions pkg/controller/rediscluster/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,28 @@ func (r *RedisClusterHandler) CheckAndHeal(meta *clustercache.Meta) error {
}
}
}
// TODO: check sentinel's number
//for _, sip := range sentinels {
// if err := r.rcChecker.CheckSentinelNumberInMemory(sip, meta.Obj, meta.Auth); err != nil {
// r.logger.WithValues("namespace", meta.Obj.Namespace, "name", meta.Obj.Name).Info(err.Error())
// if err := r.rcHealer.RestoreSentinel(sip, meta.Auth); err != nil {
// return err
// }
// return needRequeueErr
// }
//}
for _, sip := range sentinels {
if err := r.rcChecker.CheckSentinelSlavesNumberInMemory(sip, meta.Obj, meta.Auth); err != nil {
r.logger.WithValues("namespace", meta.Obj.Namespace, "name", meta.Obj.Name).Info(err.Error())
r.logger.WithValues("namespace", meta.Obj.Namespace, "name", meta.Obj.Name).
Info("restoring sentinel ...", "sentinel", sip, "reason", err.Error())
if err := r.rcHealer.RestoreSentinel(sip, meta.Auth); err != nil {
return err
}
if err := r.waitRestoreSentinelOK(sip, meta.Obj, meta.Auth); err != nil {
if err := r.waitRestoreSentinelSlavesOK(sip, meta.Obj, meta.Auth); err != nil {
r.logger.WithValues("namespace", meta.Obj.Namespace, "name", meta.Obj.Name).Info(err.Error())
return err
}
}
}
for _, sip := range sentinels {
if err := r.rcChecker.CheckSentinelNumberInMemory(sip, meta.Obj, meta.Auth); err != nil {
r.logger.WithValues("namespace", meta.Obj.Namespace, "name", meta.Obj.Name).
Info("restoring sentinel ...", "sentinel", sip, "reason", err.Error())
if err := r.rcHealer.RestoreSentinel(sip, meta.Auth); err != nil {
return err
}
}
}

if err = r.setSentinelConfig(meta, sentinels); err != nil {
return err
Expand Down Expand Up @@ -161,13 +161,13 @@ func (r *RedisClusterHandler) setSentinelConfig(meta *clustercache.Meta, sentine
return nil
}

func (r *RedisClusterHandler) waitRestoreSentinelOK(sentinel string, rc *redisv1beta1.RedisCluster, auth *util.AuthConfig) error {
func (r *RedisClusterHandler) waitRestoreSentinelSlavesOK(sentinel string, rc *redisv1beta1.RedisCluster, auth *util.AuthConfig) error {
timer := time.NewTimer(timeOut)
defer timer.Stop()
for {
select {
case <-timer.C:
return fmt.Errorf("wait for resetore sentinel timeout")
return fmt.Errorf("wait for resetore sentinel slave timeout")
default:
if err := r.rcChecker.CheckSentinelSlavesNumberInMemory(sentinel, rc, auth); err != nil {
r.logger.WithValues("namespace", rc.Namespace, "name", rc.Name).Info(err.Error())
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/rediscluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
log.WithValues("namespace", e.MetaNew.GetNamespace(), "name", e.MetaNew.GetName()).V(5).Info("Call UpdateFunc")
// Ignore updates to CR status in which case metadata.Generation does not change
if e.MetaOld.GetGeneration() != e.MetaNew.GetGeneration() {
log.WithValues("namespace", e.MetaNew.GetNamespace(), "name", e.MetaNew.GetName()).Info("Generation change return true")
log.WithValues("namespace", e.MetaNew.GetNamespace(), "name", e.MetaNew.GetName()).
Info("Generation change return true", "old", e.ObjectOld, "new", e.ObjectNew)
return true
}
return false
Expand Down

0 comments on commit 9d3706a

Please sign in to comment.