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

Commit 2dd6144

Browse files
authored
Fix rebooting cluster from complete outage (#94)
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.
1 parent e8f04fe commit 2dd6144

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

hack/mysqlsh-py.sh renamed to hack/mysqlsh.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#
33
# Gets an interactive Python based mysqlsh on the given instance.
44

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

@@ -17,4 +18,4 @@ kubectl exec \
1718
-it \
1819
-c mysql-agent \
1920
${POD} -- /bin/sh \
20-
-c "PS1='\u@\h:\w\$ ' mysqlsh --no-wizard --uri ${URI} --py"
21+
-c "PS1='\u@\h:\w\$ ' mysqlsh --no-wizard --uri ${URI} ${@:2}"

pkg/util/mysqlsh/mysqlsh.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"regexp"
23+
"strings"
2324
"sync"
2425

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

173174
func (r *runner) RebootClusterFromCompleteOutage(ctx context.Context) error {
174-
python := fmt.Sprintf("dba.reboot_cluster_from_complete_outage('%s')", innodb.DefaultClusterName)
175-
_, err := r.run(ctx, python)
175+
r.mu.Lock()
176+
defer r.mu.Unlock()
177+
178+
stdout := &bytes.Buffer{}
179+
stderr := &bytes.Buffer{}
180+
181+
// NOTE(apryde): This is implemented in SQL rather than as a call to
182+
// dba.reboot_cluster_from_complete_outage() due to https://bugs.mysql.com/90793.
183+
sql := strings.Join([]string{
184+
"RESET PERSIST group_replication_bootstrap_group;",
185+
"SET GLOBAL group_replication_bootstrap_group=ON;",
186+
"start group_replication;",
187+
}, " ")
188+
189+
args := []string{"--no-wizard", "--uri", r.uri, "--sql", "-e", sql}
190+
191+
cmd := r.exec.CommandContext(ctx, "mysqlsh", args...)
192+
193+
cmd.SetStdout(stdout)
194+
cmd.SetStderr(stderr)
195+
196+
glog.V(6).Infof("Running command: mysqlsh %v", args)
197+
err := cmd.Run()
198+
glog.V(6).Infof(" stdout: %s\n stderr: %s\n err: %s", stdout, stderr, err)
199+
if err != nil {
200+
underlying := NewErrorFromStderr(stderr.String())
201+
if underlying != nil {
202+
return errors.WithStack(underlying)
203+
}
204+
}
176205
return err
177206
}
178207

0 commit comments

Comments
 (0)