From 67c63369a379767e2b862e224df52242ee395ab7 Mon Sep 17 00:00:00 2001 From: xuriwuyun Date: Thu, 25 Apr 2024 10:43:45 +0800 Subject: [PATCH] fix: oceanbase healthcheck in oracle mode (#7162) --- pkg/lorry/dcs/k8s.go | 13 ++++-- pkg/lorry/engines/oceanbase/manager.go | 64 +++++++++++++------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/pkg/lorry/dcs/k8s.go b/pkg/lorry/dcs/k8s.go index eb48654454e..5c58a3cbede 100644 --- a/pkg/lorry/dcs/k8s.go +++ b/pkg/lorry/dcs/k8s.go @@ -242,13 +242,18 @@ func (store *KubernetesStore) GetMembers() ([]Member, error) { } store.logger.Info(fmt.Sprintf("podlist: %d", len(podList.Items))) - members := make([]Member, len(podList.Items)) - for i, pod := range podList.Items { - member := &members[i] + members := make([]Member, 0, len(podList.Items)) + for _, pod := range podList.Items { + componentName := pod.Labels[constant.KBAppComponentLabelKey] + if componentName == "" { + // it is not a member pod + continue + } + member := Member{} member.Name = pod.Name // member.Name = fmt.Sprintf("%s.%s-headless.%s.svc", pod.Name, store.clusterCompName, store.namespace) member.Role = pod.Labels[constant.RoleLabelKey] - member.ComponentName = pod.Labels[constant.KBAppComponentLabelKey] + member.ComponentName = componentName member.PodIP = pod.Status.PodIP member.DBPort = getDBPort(&pod) member.LorryPort = getLorryPort(&pod) diff --git a/pkg/lorry/engines/oceanbase/manager.go b/pkg/lorry/engines/oceanbase/manager.go index 7c3df4a26f1..2eeeb853f5b 100644 --- a/pkg/lorry/engines/oceanbase/manager.go +++ b/pkg/lorry/engines/oceanbase/manager.go @@ -241,37 +241,39 @@ func (mgr *Manager) HealthyCheckForOracleMode(ctx context.Context, cluster *dcs. if err != nil { return err } - if isLeader { - cmd := []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", "SELECT t.table_name tablename FROM user_tables t WHERE table_name = 'KB_HEALTH_CHECK'"} - output, err := util.ExecCommand(ctx, cmd, os.Environ()) - if err != nil { - return errors.Wrap(err, "check table failed") - } - if !strings.Contains(output, "KB_HEALTH_CHECK") { - sql := "create table kb_health_check (type int primary key, check_ts NUMBER);" - sql += fmt.Sprintf("INSERT INTO kb_health_check (type, check_ts) VALUES (1, %d);", time.Now().Unix()) - sql += "commit;" - cmd = []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", sql} - _, err = util.ExecCommand(ctx, cmd, os.Environ()) - if err != nil { - return errors.Wrap(err, "create table failed") - } - } - sql := fmt.Sprintf("UPDATE kb_health_check SET check_ts = %d WHERE type=1;", time.Now().Unix()) - sql += "commit;" - cmd = []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", sql} - _, err = util.ExecCommand(ctx, cmd, os.Environ()) - if err != nil { - return errors.Wrap(err, "create table failed") - } - } - - sql := "SELECT check_ts from kb_health_check WHERE type=1;" - cmd := []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", sql} - _, err = util.ExecCommand(ctx, cmd, os.Environ()) - if err != nil { - return errors.Wrap(err, "create table failed") - } + mgr.Logger.Info("check member", "isLeader", isLeader) + // lorry has no mysql client + // if isLeader { + // cmd := []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", "SELECT t.table_name tablename FROM user_tables t WHERE table_name = 'KB_HEALTH_CHECK'"} + // output, err := util.ExecCommand(ctx, cmd, os.Environ()) + // if err != nil { + // return errors.Wrap(err, "check table failed") + // } + // if !strings.Contains(output, "KB_HEALTH_CHECK") { + // sql := "create table kb_health_check (type int primary key, check_ts NUMBER);" + // sql += fmt.Sprintf("INSERT INTO kb_health_check (type, check_ts) VALUES (1, %d);", time.Now().Unix()) + // sql += "commit;" + // cmd = []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", sql} + // _, err = util.ExecCommand(ctx, cmd, os.Environ()) + // if err != nil { + // return errors.Wrap(err, "create table failed") + // } + // } + // sql := fmt.Sprintf("UPDATE kb_health_check SET check_ts = %d WHERE type=1;", time.Now().Unix()) + // sql += "commit;" + // cmd = []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", sql} + // _, err = util.ExecCommand(ctx, cmd, os.Environ()) + // if err != nil { + // return errors.Wrap(err, "create table failed") + // } + // } + + // sql := "SELECT check_ts from kb_health_check WHERE type=1;" + // cmd := []string{"mysql", "-h", member.PodIP, "-P", member.DBPort, "-u", "SYS@" + mgr.ReplicaTenant, "-e", sql} + // _, err = util.ExecCommand(ctx, cmd, os.Environ()) + // if err != nil { + // return errors.Wrap(err, "create table failed") + // } return nil }