vitess.io/vitess@v0.16.2/go/vt/vtctl/schematools/schematools.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package schematools 18 19 import ( 20 "context" 21 22 "vitess.io/vitess/go/vt/topo" 23 "vitess.io/vitess/go/vt/vterrors" 24 "vitess.io/vitess/go/vt/vttablet/tmclient" 25 26 tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" 27 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 28 "vitess.io/vitess/go/vt/proto/vtrpc" 29 ) 30 31 // GetSchema makes an RPC to get the schema from a remote tablet, after 32 // verifying a tablet with that alias exists in the topo. 33 func GetSchema(ctx context.Context, ts *topo.Server, tmc tmclient.TabletManagerClient, alias *topodatapb.TabletAlias, request *tabletmanagerdatapb.GetSchemaRequest) (*tabletmanagerdatapb.SchemaDefinition, error) { 34 ti, err := ts.GetTablet(ctx, alias) 35 if err != nil { 36 return nil, vterrors.Errorf(vtrpc.Code_NOT_FOUND, "GetTablet(%v) failed: %v", alias, err) 37 } 38 39 sd, err := tmc.GetSchema(ctx, ti.Tablet, request) 40 if err != nil { 41 return nil, vterrors.Wrapf(err, "GetSchema(%v, %v) failed: %v", ti.Tablet, request, err) 42 } 43 44 return sd, nil 45 }