Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
Fix rebooting cluster from complete outage (#94)
Browse files Browse the repository at this point in the history
Implement recovery from complete outage in SQL.

Currently dba.reboot_cluster_from_complete_outage() does not respect
the SSL mode of the cluster (see: https://bugs.mysql.com/90793). This
works around that until 8.0.12 is released.
  • Loading branch information
prydie committed May 17, 2018
1 parent e8f04fe commit 2dd6144
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 4 additions & 3 deletions hack/mysqlsh-py.sh → hack/mysqlsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#
# Gets an interactive Python based mysqlsh on the given instance.

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <namespace/podname>"
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <namespace/podname> [args]"
echo "example: $0 default/my-cluster-0 --py"
exit 1
fi

Expand All @@ -17,4 +18,4 @@ kubectl exec \
-it \
-c mysql-agent \
${POD} -- /bin/sh \
-c "PS1='\u@\h:\w\$ ' mysqlsh --no-wizard --uri ${URI} --py"
-c "PS1='\u@\h:\w\$ ' mysqlsh --no-wizard --uri ${URI} ${@:2}"
33 changes: 31 additions & 2 deletions pkg/util/mysqlsh/mysqlsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"strings"
"sync"

"github.com/golang/glog"
Expand Down Expand Up @@ -171,8 +172,36 @@ func (r *runner) run(ctx context.Context, python string) ([]byte, error) {
}

func (r *runner) RebootClusterFromCompleteOutage(ctx context.Context) error {
python := fmt.Sprintf("dba.reboot_cluster_from_complete_outage('%s')", innodb.DefaultClusterName)
_, err := r.run(ctx, python)
r.mu.Lock()
defer r.mu.Unlock()

stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}

// NOTE(apryde): This is implemented in SQL rather than as a call to
// dba.reboot_cluster_from_complete_outage() due to https://bugs.mysql.com/90793.
sql := strings.Join([]string{
"RESET PERSIST group_replication_bootstrap_group;",
"SET GLOBAL group_replication_bootstrap_group=ON;",
"start group_replication;",
}, " ")

args := []string{"--no-wizard", "--uri", r.uri, "--sql", "-e", sql}

cmd := r.exec.CommandContext(ctx, "mysqlsh", args...)

cmd.SetStdout(stdout)
cmd.SetStderr(stderr)

glog.V(6).Infof("Running command: mysqlsh %v", args)
err := cmd.Run()
glog.V(6).Infof(" stdout: %s\n stderr: %s\n err: %s", stdout, stderr, err)
if err != nil {
underlying := NewErrorFromStderr(stderr.String())
if underlying != nil {
return errors.WithStack(underlying)
}
}
return err
}

Expand Down

0 comments on commit 2dd6144

Please sign in to comment.