Skip to content

Commit

Permalink
fix: oceanbase healthcheck in oracle mode (#7162)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun authored Apr 25, 2024
1 parent d22abd5 commit 67c6336
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
13 changes: 9 additions & 4 deletions pkg/lorry/dcs/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 33 additions & 31 deletions pkg/lorry/engines/oceanbase/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 67c6336

Please sign in to comment.