Skip to content

Commit

Permalink
feat: augment PrimaryStatus to also send Server UUID
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Oct 22, 2024
1 parent e6ec0ba commit 6797545
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 79 deletions.
3 changes: 3 additions & 0 deletions go/mysql/replication/primary_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ type PrimaryStatus struct {
Position Position
// FilePosition represents the server's file based position.
FilePosition Position
// ServerUUID is the UUID of the server.
ServerUUID string
}

// PrimaryStatusToProto translates a PrimaryStatus to proto3.
func PrimaryStatusToProto(s PrimaryStatus) *replicationdatapb.PrimaryStatus {
return &replicationdatapb.PrimaryStatus{
Position: EncodePosition(s.Position),
FilePosition: EncodePosition(s.FilePosition),
ServerUuid: s.ServerUUID,
}
}

Expand Down
7 changes: 7 additions & 0 deletions go/test/endtoend/utils/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ func TestPrimaryStatus(t *testing.T) {
assert.NoError(t, err)

assert.True(t, res.Position.Equal(r.Position), "primary replication status should be same as replication status here")

suuid, err := mysqld.GetServerUUID(context.Background())
assert.NoError(t, err)
assert.NotEmpty(t, suuid)

// The server UUID read from primary status and GetServerUUID should match
assert.Equal(t, suuid, res.ServerUUID)
}

func TestReplicationConfiguration(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion go/vt/mysqlctl/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,15 @@ func (mysqld *Mysqld) PrimaryStatus(ctx context.Context) (replication.PrimarySta
}
defer conn.Recycle()

return conn.Conn.ShowPrimaryStatus()
primaryStatus, err := conn.Conn.ShowPrimaryStatus()
if err != nil {
return replication.PrimaryStatus{}, err
}
primaryStatus.ServerUUID, err = conn.Conn.GetServerUUID()
if err != nil {
return replication.PrimaryStatus{}, err
}
return primaryStatus, nil
}

func (mysqld *Mysqld) ReplicationConfiguration(ctx context.Context) (*replicationdata.Configuration, error) {
Expand Down
2 changes: 2 additions & 0 deletions go/vt/mysqlctl/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func TestPrimaryStatus(t *testing.T) {

db.AddQuery("SELECT 1", &sqltypes.Result{})
db.AddQuery("SHOW MASTER STATUS", sqltypes.MakeTestResult(sqltypes.MakeTestFields("test_field", "varchar"), "test_status"))
db.AddQuery("SELECT @@global.server_uuid", sqltypes.MakeTestResult(sqltypes.MakeTestFields("test_field", "varchar"), "test_uuid"))

testMysqld := NewMysqld(dbc)
defer testMysqld.Close()
Expand All @@ -295,6 +296,7 @@ func TestPrimaryStatus(t *testing.T) {
res, err := testMysqld.PrimaryStatus(ctx)
assert.NoError(t, err)
assert.NotNil(t, res)
assert.EqualValues(t, "test_uuid", res.ServerUUID)

db.AddQuery("SHOW MASTER STATUS", &sqltypes.Result{})
_, err = testMysqld.PrimaryStatus(ctx)
Expand Down
166 changes: 88 additions & 78 deletions go/vt/proto/replicationdata/replicationdata.pb.go

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions go/vt/proto/replicationdata/replicationdata_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/replicationdata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum StopReplicationMode {
message PrimaryStatus {
string position = 1;
string file_position = 2;
string server_uuid = 3;
}

// FullStatus contains the full status of MySQL including the replication information, semi-sync information, GTID information among others
Expand Down
6 changes: 6 additions & 0 deletions web/vtadmin/src/proto/vtadmin.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions web/vtadmin/src/proto/vtadmin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6797545

Please sign in to comment.