Skip to content

Commit

Permalink
Merge pull request #9104 from planetscale/ds-fp-9059
Browse files Browse the repository at this point in the history
tabletmanager: correct implementations of deprecated RPCs for backwards compatibility
  • Loading branch information
deepthi authored Nov 8, 2021
2 parents c225a6d + 2235ea1 commit 1152ecc
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go/mysql/server_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ func TestServerFlush(t *testing.T) {
flds, err := c.Fields()
require.NoError(t, err)
if duration, want := time.Since(start), 20*time.Millisecond; duration < *mysqlServerFlushDelay || duration > want {
assert.Fail(t, "duration: %v, want between %v and %v", duration.String(), (*mysqlServerFlushDelay).String(), want.String())
assert.Fail(t, "duration out of expected range", "duration: %v, want between %v and %v", duration.String(), (*mysqlServerFlushDelay).String(), want.String())
}
want1 := []*querypb.Field{{
Name: "result",
Expand All @@ -1409,7 +1409,7 @@ func TestServerFlush(t *testing.T) {
row, err := c.FetchNext(nil)
require.NoError(t, err)
if duration, want := time.Since(start), 50*time.Millisecond; duration < want {
assert.Fail(t, "duration: %v, want > %v", duration, want)
assert.Fail(t, "duration is too low", "duration: %v, want > %v", duration, want)
}
want2 := []sqltypes.Value{sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("delayed"))}
assert.Equal(t, want2, row)
Expand Down
12 changes: 6 additions & 6 deletions go/vt/proto/tabletmanagerservice/tabletmanagerservice_grpc.pb.go

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

79 changes: 71 additions & 8 deletions go/vt/vttablet/grpctmclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,16 @@ func (client *Client) ReplicationStatus(ctx context.Context, tablet *topodatapb.

// MasterStatus is part of the tmclient.TabletManagerClient interface.
func (client *Client) MasterStatus(ctx context.Context, tablet *topodatapb.Tablet) (*replicationdatapb.PrimaryStatus, error) {
return client.PrimaryStatus(ctx, tablet)
c, closer, err := client.dialer.dial(ctx, tablet)
if err != nil {
return nil, err
}
defer closer.Close()
response, err := c.MasterStatus(ctx, &tabletmanagerdatapb.PrimaryStatusRequest{})
if err != nil {
return nil, err
}
return response.Status, nil
}

// PrimaryStatus is part of the tmclient.TabletManagerClient interface.
Expand All @@ -560,7 +569,16 @@ func (client *Client) PrimaryStatus(ctx context.Context, tablet *topodatapb.Tabl

// MasterPosition is part of the tmclient.TabletManagerClient interface.
func (client *Client) MasterPosition(ctx context.Context, tablet *topodatapb.Tablet) (string, error) {
return client.PrimaryPosition(ctx, tablet)
c, closer, err := client.dialer.dial(ctx, tablet)
if err != nil {
return "", err
}
defer closer.Close()
response, err := c.MasterPosition(ctx, &tabletmanagerdatapb.PrimaryPositionRequest{})
if err != nil {
return "", err
}
return response.Position, nil
}

// PrimaryPosition is part of the tmclient.TabletManagerClient interface.
Expand All @@ -570,7 +588,7 @@ func (client *Client) PrimaryPosition(ctx context.Context, tablet *topodatapb.Ta
return "", err
}
defer closer.Close()
response, err := c.MasterPosition(ctx, &tabletmanagerdatapb.PrimaryPositionRequest{})
response, err := c.PrimaryPosition(ctx, &tabletmanagerdatapb.PrimaryPositionRequest{})
if err != nil {
return "", err
}
Expand Down Expand Up @@ -714,7 +732,17 @@ func (client *Client) ResetReplication(ctx context.Context, tablet *topodatapb.T

// InitMaster is part of the tmclient.TabletManagerClient interface.
func (client *Client) InitMaster(ctx context.Context, tablet *topodatapb.Tablet) (string, error) {
return client.InitPrimary(ctx, tablet)
c, closer, err := client.dialer.dial(ctx, tablet)
if err != nil {
return "", err
}
defer closer.Close()

response, err := c.InitMaster(ctx, &tabletmanagerdatapb.InitPrimaryRequest{})
if err != nil {
return "", err
}
return response.Position, nil
}

// InitPrimary is part of the tmclient.TabletManagerClient interface.
Expand Down Expand Up @@ -765,7 +793,25 @@ func (client *Client) InitReplica(ctx context.Context, tablet *topodatapb.Tablet

// DemoteMaster is part of the tmclient.TabletManagerClient interface.
func (client *Client) DemoteMaster(ctx context.Context, tablet *topodatapb.Tablet) (*replicationdatapb.PrimaryStatus, error) {
return client.DemotePrimary(ctx, tablet)
c, closer, err := client.dialer.dial(ctx, tablet)
if err != nil {
return nil, err
}
defer closer.Close()
response, err := c.DemoteMaster(ctx, &tabletmanagerdatapb.DemotePrimaryRequest{})
if err != nil {
return nil, err
}
status := response.PrimaryStatus
if status == nil {
// We are assuming this means a response came from an older server.
status = &replicationdatapb.PrimaryStatus{
Position: response.DeprecatedPosition, //nolint
FilePosition: "",
}
}
return status, nil

}

// DemotePrimary is part of the tmclient.TabletManagerClient interface.
Expand All @@ -792,7 +838,13 @@ func (client *Client) DemotePrimary(ctx context.Context, tablet *topodatapb.Tabl

// UndoDemoteMaster is part of the tmclient.TabletManagerClient interface.
func (client *Client) UndoDemoteMaster(ctx context.Context, tablet *topodatapb.Tablet) error {
return client.UndoDemotePrimary(ctx, tablet)
c, closer, err := client.dialer.dial(ctx, tablet)
if err != nil {
return err
}
defer closer.Close()
_, err = c.UndoDemoteMaster(ctx, &tabletmanagerdatapb.UndoDemotePrimaryRequest{})
return err
}

// UndoDemotePrimary is part of the tmclient.TabletManagerClient interface.
Expand All @@ -802,7 +854,7 @@ func (client *Client) UndoDemotePrimary(ctx context.Context, tablet *topodatapb.
return err
}
defer closer.Close()
_, err = c.UndoDemoteMaster(ctx, &tabletmanagerdatapb.UndoDemotePrimaryRequest{})
_, err = c.UndoDemotePrimary(ctx, &tabletmanagerdatapb.UndoDemotePrimaryRequest{})
return err
}

Expand All @@ -819,7 +871,18 @@ func (client *Client) ReplicaWasPromoted(ctx context.Context, tablet *topodatapb

// SetMaster is part of the tmclient.TabletManagerClient interface.
func (client *Client) SetMaster(ctx context.Context, tablet *topodatapb.Tablet, parent *topodatapb.TabletAlias, timeCreatedNS int64, waitPosition string, forceStartReplication bool) error {
return client.SetReplicationSource(ctx, tablet, parent, timeCreatedNS, waitPosition, forceStartReplication)
c, closer, err := client.dialer.dial(ctx, tablet)
if err != nil {
return err
}
defer closer.Close()
_, err = c.SetMaster(ctx, &tabletmanagerdatapb.SetReplicationSourceRequest{
Parent: parent,
TimeCreatedNs: timeCreatedNS,
WaitPosition: waitPosition,
ForceStartReplication: forceStartReplication,
})
return err
}

// SetReplicationSource is part of the tmclient.TabletManagerClient interface.
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/grpctmserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (s *server) MasterPosition(ctx context.Context, request *tabletmanagerdatap
defer s.tm.HandleRPCPanic(ctx, "PrimaryPosition", request, response, false /*verbose*/, &err)
ctx = callinfo.GRPCCallInfo(ctx)
response = &tabletmanagerdatapb.PrimaryPositionResponse{}
position, err := s.tm.MasterPosition(ctx)
position, err := s.tm.PrimaryPosition(ctx)
if err == nil {
response.Position = position
}
Expand All @@ -296,7 +296,7 @@ func (s *server) PrimaryPosition(ctx context.Context, request *tabletmanagerdata
defer s.tm.HandleRPCPanic(ctx, "PrimaryPosition", request, response, false /*verbose*/, &err)
ctx = callinfo.GRPCCallInfo(ctx)
response = &tabletmanagerdatapb.PrimaryPositionResponse{}
position, err := s.tm.MasterPosition(ctx)
position, err := s.tm.PrimaryPosition(ctx)
if err == nil {
response.Position = position
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func (s *server) InitMaster(ctx context.Context, request *tabletmanagerdatapb.In
defer s.tm.HandleRPCPanic(ctx, "InitMaster", request, response, true /*verbose*/, &err)
ctx = callinfo.GRPCCallInfo(ctx)
response = &tabletmanagerdatapb.InitPrimaryResponse{}
position, err := s.tm.InitMaster(ctx)
position, err := s.tm.InitPrimary(ctx)
if err == nil {
response.Position = position
}
Expand Down
6 changes: 3 additions & 3 deletions proto/tabletmanagerservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ service TabletManager {
// ReplicationStatus returns the current replication status.
rpc ReplicationStatus(tabletmanagerdata.ReplicationStatusRequest) returns (tabletmanagerdata.ReplicationStatusResponse) {};

// MasterStatus returns the current primary status.
// Deprecated, use PrimaryStatus instead
rpc MasterStatus(tabletmanagerdata.PrimaryStatusRequest) returns (tabletmanagerdata.PrimaryStatusResponse) {};

// PrimaryStatus returns the current primary status.
rpc PrimaryStatus(tabletmanagerdata.PrimaryStatusRequest) returns (tabletmanagerdata.PrimaryStatusResponse) {};

// MasterPosition returns the current primary position
// Deprecated, use PrimaryPosition instead
rpc MasterPosition(tabletmanagerdata.PrimaryPositionRequest) returns (tabletmanagerdata.PrimaryPositionResponse) {};

// PrimaryPosition returns the current primary position
Expand Down Expand Up @@ -158,7 +158,7 @@ service TabletManager {
// ReplicaWasPromoted tells the remote tablet it is now the primary
rpc ReplicaWasPromoted(tabletmanagerdata.ReplicaWasPromotedRequest) returns (tabletmanagerdata.ReplicaWasPromotedResponse) {};

// SetMaster tells the replica to reparent
// Deprecated, use SetReplicationSource instead
rpc SetMaster(tabletmanagerdata.SetReplicationSourceRequest) returns (tabletmanagerdata.SetReplicationSourceResponse) {};

// SetReplicationSource tells the replica to reparent
Expand Down

0 comments on commit 1152ecc

Please sign in to comment.