Skip to content

Commit fb76299

Browse files
authored
Merge pull request #2767 from dolthub/fulghum/show_slave_status
Add support for `show slave status`
2 parents 6625ccc + 7c3d811 commit fb76299

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0
9+
github.com/dolthub/vitess v0.0.0-20241125223808-07f6e12611ec
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ github.com/dolthub/vitess v0.0.0-20241120000209-5ff664bddfc4 h1:C3RSQjvv2T5TdQzR
6464
github.com/dolthub/vitess v0.0.0-20241120000209-5ff664bddfc4/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
6565
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0 h1:C8X4RkkWKcrJG6rG+MsdFINX2PhB7ObpbBvFcWsI8K8=
6666
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg=
67+
github.com/dolthub/vitess v0.0.0-20241125223808-07f6e12611ec h1:4EpyVnCleDMSuIqg8oCHf5IpwW7DPhjSQEgYCWkKpTo=
68+
github.com/dolthub/vitess v0.0.0-20241125223808-07f6e12611ec/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg=
6769
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6870
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6971
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

sql/plan/show_replica_status.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package plan
1616

1717
import (
18+
"strings"
19+
1820
"github.com/dolthub/go-mysql-server/sql"
1921
"github.com/dolthub/go-mysql-server/sql/binlogreplication"
2022
"github.com/dolthub/go-mysql-server/sql/types"
@@ -26,16 +28,28 @@ import (
2628
// https://dev.mysql.com/doc/refman/8.0/en/show-replica-status.html
2729
type ShowReplicaStatus struct {
2830
ReplicaController binlogreplication.BinlogReplicaController
31+
// useDeprecatedColumnNames is used to determine if the column names returned should be the old
32+
// and deprecated master/slave column names, or the new source/replica column names.
33+
useDeprecatedColumnNames bool
2934
}
3035

3136
var _ sql.Node = (*ShowReplicaStatus)(nil)
3237
var _ sql.CollationCoercible = (*ShowReplicaStatus)(nil)
3338
var _ BinlogReplicaControllerCommand = (*ShowReplicaStatus)(nil)
3439

40+
// NewShowReplicaStatus creates a new ShowReplicaStatus node.
3541
func NewShowReplicaStatus() *ShowReplicaStatus {
3642
return &ShowReplicaStatus{}
3743
}
3844

45+
// NewShowSlaveStatus creates a new ShowReplicaStatus node configured to use the old, deprecated
46+
// column names (i.e. master/slave) instead of the new, renamed columns (i.e. source/replica).
47+
func NewShowSlaveStatus() *ShowReplicaStatus {
48+
return &ShowReplicaStatus{
49+
useDeprecatedColumnNames: true,
50+
}
51+
}
52+
3953
// WithBinlogReplicaController implements the BinlogReplicaControllerCommand interface.
4054
func (s *ShowReplicaStatus) WithBinlogReplicaController(controller binlogreplication.BinlogReplicaController) sql.Node {
4155
nc := *s
@@ -48,11 +62,15 @@ func (s *ShowReplicaStatus) Resolved() bool {
4862
}
4963

5064
func (s *ShowReplicaStatus) String() string {
51-
return "SHOW REPLICA STATUS"
65+
if s.useDeprecatedColumnNames {
66+
return "SHOW SLAVE STATUS"
67+
} else {
68+
return "SHOW REPLICA STATUS"
69+
}
5270
}
5371

5472
func (s *ShowReplicaStatus) Schema() sql.Schema {
55-
return sql.Schema{
73+
sch := sql.Schema{
5674
{Name: "Replica_IO_State", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false},
5775
{Name: "Source_Host", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 255), Default: nil, Nullable: false},
5876
{Name: "Source_User", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false},
@@ -109,6 +127,15 @@ func (s *ShowReplicaStatus) Schema() sql.Schema {
109127
{Name: "Auto_Position", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false},
110128
{Name: "Replicate_Rewrite_DB", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false},
111129
}
130+
131+
if s.useDeprecatedColumnNames {
132+
for i := range sch {
133+
sch[i].Name = strings.ReplaceAll(sch[i].Name, "Source", "Master")
134+
sch[i].Name = strings.ReplaceAll(sch[i].Name, "Replica", "Slave")
135+
}
136+
}
137+
138+
return sch
112139
}
113140

114141
func (s *ShowReplicaStatus) Children() []sql.Node {

sql/planbuilder/show.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ func (b *Builder) buildShow(inScope *scope, s *ast.Show) (outScope *scope) {
102102
showRep.ReplicaController = binCat.GetBinlogReplicaController()
103103
}
104104
outScope.node = showRep
105+
case "slave status":
106+
// The deprecated "show slave status" command returns the same information as "show replica status",
107+
// but uses a schema with different column names so we create the node differently here.
108+
outScope = inScope.push()
109+
showRep := plan.NewShowSlaveStatus()
110+
if binCat, ok := b.cat.(binlogreplication.BinlogReplicaCatalog); ok && binCat.HasBinlogReplicaController() {
111+
showRep.ReplicaController = binCat.GetBinlogReplicaController()
112+
}
113+
outScope.node = showRep
105114
default:
106115
unsupportedShow := fmt.Sprintf("SHOW %s", s.Type)
107116
b.handleErr(sql.ErrUnsupportedFeature.New(unsupportedShow))

0 commit comments

Comments
 (0)