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

Fix rebooting cluster from complete outage #94

Merged
merged 2 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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