Skip to content

Commit eec908f

Browse files
authored
Merge branch 'main' into fulghum-b4036b79
2 parents b73851c + fb76299 commit eec908f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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)