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

Schema RPC to fetch table/view definition #12375

Merged
merged 7 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
834 changes: 532 additions & 302 deletions go/vt/proto/query/query.pb.go

Large diffs are not rendered by default.

516 changes: 516 additions & 0 deletions go/vt/proto/query/query_vtproto.pb.go

Large diffs are not rendered by default.

126 changes: 67 additions & 59 deletions go/vt/proto/queryservice/queryservice.pb.go

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

38 changes: 38 additions & 0 deletions go/vt/proto/queryservice/queryservice_grpc.pb.go

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

6 changes: 6 additions & 0 deletions go/vt/vtcombo/tablet_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ func (itc *internalTabletConn) Release(ctx context.Context, target *querypb.Targ
return tabletconn.ErrorFromGRPC(vterrors.ToGRPC(err))
}

// GetSchema is part of the QueryService interface.
func (itc *internalTabletConn) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.TableType, tableNames []string) (map[string]string, error) {
response, err := itc.tablet.qsc.QueryService().GetSchema(ctx, target, tableType, tableNames)
return response, tabletconn.ErrorFromGRPC(vterrors.ToGRPC(err))
}

// Close is part of queryservice.QueryService
func (itc *internalTabletConn) Close(ctx context.Context) error {
return nil
Expand Down
23 changes: 23 additions & 0 deletions go/vt/vttablet/grpctabletconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,29 @@ func (conn *gRPCQueryClient) Release(ctx context.Context, target *querypb.Target
return nil
}

// GetSchema implements the queryservice interface
func (conn *gRPCQueryClient) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.TableType, tableNames []string) (map[string]string, error) {
conn.mu.RLock()
defer conn.mu.RUnlock()
if conn.cc == nil {
return nil, tabletconn.ConnClosed
}

req := &querypb.GetSchemaRequest{
Target: target,
Type: tableType,
TableNames: tableNames,
}
reply, err := conn.c.GetSchema(ctx, req)
if err != nil {
return nil, tabletconn.ErrorFromGRPC(err)
}
if reply.Error != nil {
return nil, tabletconn.ErrorFromVTRPC(reply.Error)
}
return reply.GetTableDefinition(), nil
}

// Close closes underlying gRPC channel.
func (conn *gRPCQueryClient) Close(ctx context.Context) error {
conn.mu.Lock()
Expand Down
3 changes: 3 additions & 0 deletions go/vt/vttablet/queryservice/queryservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type QueryService interface {

Release(ctx context.Context, target *querypb.Target, transactionID, reservedID int64) error

// GetSchema returns the table definition for the specified tables.
GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.TableType, tableNames []string) (map[string]string, error)

// Close must be called for releasing resources.
Close(ctx context.Context) error
}
Expand Down
9 changes: 9 additions & 0 deletions go/vt/vttablet/queryservice/wrapped.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ func (ws *wrappedService) Release(ctx context.Context, target *querypb.Target, t
})
}

func (ws *wrappedService) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.TableType, tableNames []string) (schemaDef map[string]string, err error) {
err = ws.wrapper(ctx, target, ws.impl, "GetSchema", false, func(ctx context.Context, target *querypb.Target, conn QueryService) (bool, error) {
var innerErr error
schemaDef, innerErr = conn.GetSchema(ctx, target, tableType, tableNames)
return canRetry(ctx, innerErr), innerErr
})
return schemaDef, err
}

func (ws *wrappedService) Close(ctx context.Context) error {
return ws.wrapper(ctx, nil, ws.impl, "Close", false, func(ctx context.Context, target *querypb.Target, conn QueryService) (bool, error) {
// No point retrying Close.
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vttablet/sandboxconn/sandboxconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ func (sbc *SandboxConn) Release(ctx context.Context, target *querypb.Target, tra
return sbc.getError()
}

// GetSchema implements the QueryService interface
func (sbc *SandboxConn) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.TableType, tableNames []string) (map[string]string, error) {
panic("not implemented")
}

// Close does not change ExecCount
func (sbc *SandboxConn) Close(ctx context.Context) error {
return nil
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vttablet/tabletconntest/fakequeryservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ func (f *FakeQueryService) Release(ctx context.Context, target *querypb.Target,
panic("implement me")
}

// GetSchema implements the QueryService interface
func (f *FakeQueryService) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.TableType, tableNames []string) (map[string]string, error) {
panic("implement me")
}

// CreateFakeServer returns the fake server for the tests
func CreateFakeServer(t testing.TB) *FakeQueryService {
return &FakeQueryService{
Expand Down
Loading