Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for show slave status #2767

Merged
merged 2 commits into from
Nov 25, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
31 changes: 29 additions & 2 deletions sql/plan/show_replica_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions sql/planbuilder/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down