diff --git a/go.mod b/go.mod index 46b39ea361..503bc453e9 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0 + github.com/dolthub/vitess v0.0.0-20241125223808-07f6e12611ec github.com/go-kit/kit v0.10.0 github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d github.com/gocraft/dbr/v2 v2.7.2 diff --git a/go.sum b/go.sum index 91bcdb1ca8..b5ce855bd7 100644 --- a/go.sum +++ b/go.sum @@ -64,6 +64,8 @@ github.com/dolthub/vitess v0.0.0-20241120000209-5ff664bddfc4 h1:C3RSQjvv2T5TdQzR github.com/dolthub/vitess v0.0.0-20241120000209-5ff664bddfc4/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0 h1:C8X4RkkWKcrJG6rG+MsdFINX2PhB7ObpbBvFcWsI8K8= github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg= +github.com/dolthub/vitess v0.0.0-20241125223808-07f6e12611ec h1:4EpyVnCleDMSuIqg8oCHf5IpwW7DPhjSQEgYCWkKpTo= +github.com/dolthub/vitess v0.0.0-20241125223808-07f6e12611ec/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= diff --git a/sql/plan/show_replica_status.go b/sql/plan/show_replica_status.go index efa5ed1439..50e55fdec6 100644 --- a/sql/plan/show_replica_status.go +++ b/sql/plan/show_replica_status.go @@ -15,6 +15,8 @@ package plan import ( + "strings" + "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/binlogreplication" "github.com/dolthub/go-mysql-server/sql/types" @@ -26,16 +28,28 @@ import ( // https://dev.mysql.com/doc/refman/8.0/en/show-replica-status.html type ShowReplicaStatus struct { ReplicaController binlogreplication.BinlogReplicaController + // useDeprecatedColumnNames is used to determine if the column names returned should be the old + // and deprecated master/slave column names, or the new source/replica column names. + useDeprecatedColumnNames bool } var _ sql.Node = (*ShowReplicaStatus)(nil) var _ sql.CollationCoercible = (*ShowReplicaStatus)(nil) var _ BinlogReplicaControllerCommand = (*ShowReplicaStatus)(nil) +// NewShowReplicaStatus creates a new ShowReplicaStatus node. func NewShowReplicaStatus() *ShowReplicaStatus { return &ShowReplicaStatus{} } +// NewShowSlaveStatus creates a new ShowReplicaStatus node configured to use the old, deprecated +// column names (i.e. master/slave) instead of the new, renamed columns (i.e. source/replica). +func NewShowSlaveStatus() *ShowReplicaStatus { + return &ShowReplicaStatus{ + useDeprecatedColumnNames: true, + } +} + // WithBinlogReplicaController implements the BinlogReplicaControllerCommand interface. func (s *ShowReplicaStatus) WithBinlogReplicaController(controller binlogreplication.BinlogReplicaController) sql.Node { nc := *s @@ -48,11 +62,15 @@ func (s *ShowReplicaStatus) Resolved() bool { } func (s *ShowReplicaStatus) String() string { - return "SHOW REPLICA STATUS" + if s.useDeprecatedColumnNames { + return "SHOW SLAVE STATUS" + } else { + return "SHOW REPLICA STATUS" + } } func (s *ShowReplicaStatus) Schema() sql.Schema { - return sql.Schema{ + sch := sql.Schema{ {Name: "Replica_IO_State", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false}, {Name: "Source_Host", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 255), Default: nil, Nullable: false}, {Name: "Source_User", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false}, @@ -109,6 +127,15 @@ func (s *ShowReplicaStatus) Schema() sql.Schema { {Name: "Auto_Position", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false}, {Name: "Replicate_Rewrite_DB", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 64), Default: nil, Nullable: false}, } + + if s.useDeprecatedColumnNames { + for i := range sch { + sch[i].Name = strings.ReplaceAll(sch[i].Name, "Source", "Master") + sch[i].Name = strings.ReplaceAll(sch[i].Name, "Replica", "Slave") + } + } + + return sch } func (s *ShowReplicaStatus) Children() []sql.Node { diff --git a/sql/planbuilder/show.go b/sql/planbuilder/show.go index 915d49ba92..dfcae8e063 100644 --- a/sql/planbuilder/show.go +++ b/sql/planbuilder/show.go @@ -102,6 +102,15 @@ func (b *Builder) buildShow(inScope *scope, s *ast.Show) (outScope *scope) { showRep.ReplicaController = binCat.GetBinlogReplicaController() } outScope.node = showRep + case "slave status": + // The deprecated "show slave status" command returns the same information as "show replica status", + // but uses a schema with different column names so we create the node differently here. + outScope = inScope.push() + showRep := plan.NewShowSlaveStatus() + if binCat, ok := b.cat.(binlogreplication.BinlogReplicaCatalog); ok && binCat.HasBinlogReplicaController() { + showRep.ReplicaController = binCat.GetBinlogReplicaController() + } + outScope.node = showRep default: unsupportedShow := fmt.Sprintf("SHOW %s", s.Type) b.handleErr(sql.ErrUnsupportedFeature.New(unsupportedShow))