Skip to content

Commit

Permalink
[cleanup] Protos: Use UnmarshalPB() when unmarshalling a proto object (
Browse files Browse the repository at this point in the history
#16311)

Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps authored Jul 2, 2024
1 parent 05d7e76 commit 780abdd
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go/cmd/vtctldclient/command/vschemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func commandApplyVSchema(cmd *cobra.Command, args []string) error {
}

var vs vschemapb.Keyspace
err = json2.Unmarshal(schema, &vs)
err = json2.UnmarshalPB(schema, &vs)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ func checkTabletType(t *testing.T, alias string, tabletType topodata.TabletType)
output, err := localCluster.VtctldClientProcess.ExecuteCommandWithOutput("GetTablet", alias)
require.NoError(t, err)
var tabletPB topodata.Tablet
err = json2.Unmarshal([]byte(output), &tabletPB)
err = json2.UnmarshalPB([]byte(output), &tabletPB)
require.NoError(t, err)
if tabletType == tabletPB.Type {
return
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func terminateBackup(t *testing.T, alias string) {
text := scanner.Text()
if strings.Contains(text, stopBackupMsg) {
tmpProcess.Process.Signal(syscall.SIGTERM)
found = true //nolint
found = true // nolint
return
}
}
Expand Down
8 changes: 4 additions & 4 deletions go/test/endtoend/cluster/vtctldclient_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (vtctldclient *VtctldClientProcess) GetShardReplication(keyspace string, sh
}

var resp vtctldatapb.GetShardReplicationResponse
err = json2.Unmarshal([]byte(out), &resp)
err = json2.UnmarshalPB([]byte(out), &resp)
return resp.ShardReplicationByCell, err
}

Expand Down Expand Up @@ -252,7 +252,7 @@ func (vtctldclient *VtctldClientProcess) GetKeyspace(keyspace string) (*vtctldat
}

var ks vtctldatapb.Keyspace
err = json2.Unmarshal([]byte(data), &ks)
err = json2.UnmarshalPB([]byte(data), &ks)
if err != nil {
return nil, vterrors.Wrapf(err, "failed to parse keyspace output: %s", data)
}
Expand All @@ -267,7 +267,7 @@ func (vtctldclient *VtctldClientProcess) GetShard(keyspace string, shard string)
}

var si vtctldatapb.Shard
err = json2.Unmarshal([]byte(data), &si)
err = json2.UnmarshalPB([]byte(data), &si)
if err != nil {
return nil, vterrors.Wrapf(err, "failed to parse shard output: %s", data)
}
Expand All @@ -282,7 +282,7 @@ func (vtctldclient *VtctldClientProcess) GetTablet(alias string) (*topodatapb.Ta
}

var tablet topodatapb.Tablet
err = json2.Unmarshal([]byte(data), &tablet)
err = json2.UnmarshalPB([]byte(data), &tablet)
if err != nil {
return nil, vterrors.Wrapf(err, "failed to parse tablet output: %s", data)
}
Expand Down
8 changes: 4 additions & 4 deletions go/test/endtoend/recovery/pitr/shardedpitr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestPITRRecovery(t *testing.T) {
initializeCluster(t)
defer clusterInstance.Teardown()

//start the binlog server and point it to primary
// start the binlog server and point it to primary
bs := startBinlogServer(t, primary)
defer bs.stop()

Expand Down Expand Up @@ -167,11 +167,11 @@ func TestPITRRecovery(t *testing.T) {
// starting resharding process
performResharding(t)

//start the binlog server and point it to shard0Primary
// start the binlog server and point it to shard0Primary
bs0 := startBinlogServer(t, shard0Primary)
defer bs0.stop()

//start the binlog server and point it to shard1Primary
// start the binlog server and point it to shard1Primary
bs1 := startBinlogServer(t, shard1Primary)
defer bs1.stop()

Expand Down Expand Up @@ -585,7 +585,7 @@ func waitForNoWorkflowLag(t *testing.T, vc *cluster.LocalProcessCluster, ks stri
require.NoError(t, err)

var resp vtctldatapb.GetWorkflowsResponse
err = json2.Unmarshal([]byte(output), &resp)
err = json2.UnmarshalPB([]byte(output), &resp)
require.NoError(t, err)
require.GreaterOrEqual(t, len(resp.Workflows), 1, "responce should have at least one workflow")
lag = resp.Workflows[0].MaxVReplicationTransactionLag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func waitForLowLag(t *testing.T, clusterInstance *cluster.LocalProcessCluster, k
require.NoError(t, err)

var resp vtctldatapb.GetWorkflowsResponse
err = json2.Unmarshal([]byte(output), &resp)
err = json2.UnmarshalPB([]byte(output), &resp)
require.NoError(t, err)
require.GreaterOrEqual(t, len(resp.Workflows), 1, "responce should have at least one workflow")
lagSeconds := resp.Workflows[0].MaxVReplicationTransactionLag
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/tabletmanager/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func runHookAndAssert(t *testing.T, params []string, expectedStatus int64, expec
require.Nil(t, err)

var resp vtctldatapb.ExecuteHookResponse
err = json2.Unmarshal([]byte(hr), &resp)
err = json2.UnmarshalPB([]byte(hr), &resp)
require.Nil(t, err)

assert.Equal(t, expectedStatus, resp.HookResult.ExitStatus)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/tableacl/tableacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error {
config := &tableaclpb.Config{}
if err := config.UnmarshalVT(data); err != nil {
// try to parse tableacl as json file
if jsonErr := json2.Unmarshal(data, config); jsonErr != nil {
if jsonErr := json2.UnmarshalPB(data, config); jsonErr != nil {
log.Infof("unable to parse tableACL config file as a protobuf or json file. protobuf err: %v json err: %v", err, jsonErr)
return fmt.Errorf("unable to unmarshal Table ACL data: %s", data)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtctl/endtoend/get_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestGetSchema(t *testing.T) {
val := events[0].Value

actual := &tabletmanagerdatapb.SchemaDefinition{}
err = json2.Unmarshal([]byte(val), actual)
err = json2.UnmarshalPB([]byte(val), actual)
require.NoError(t, err)

utils.MustMatch(t, sd, actual)
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestGetSchema(t *testing.T) {
val = events[0].Value

actual = &tabletmanagerdatapb.SchemaDefinition{}
err = json2.Unmarshal([]byte(val), actual)
err = json2.UnmarshalPB([]byte(val), actual)
require.NoError(t, err)

utils.MustMatch(t, sd, actual)
Expand Down
8 changes: 4 additions & 4 deletions go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ func commandCreateLookupVindex(ctx context.Context, wr *wrangler.Wrangler, subFl
}
keyspace := subFlags.Arg(0)
specs := &vschemapb.Keyspace{}
if err := json2.Unmarshal([]byte(subFlags.Arg(1)), specs); err != nil {
if err := json2.UnmarshalPB([]byte(subFlags.Arg(1)), specs); err != nil {
return err
}
return wr.CreateLookupVindex(ctx, keyspace, specs, *cells, *tabletTypes, *continueAfterCopyWithOwner)
Expand All @@ -2533,7 +2533,7 @@ func commandMaterialize(ctx context.Context, wr *wrangler.Wrangler, subFlags *pf
return fmt.Errorf("a single argument is required: <json_spec>")
}
ms := &vtctldatapb.MaterializeSettings{}
if err := json2.Unmarshal([]byte(subFlags.Arg(0)), ms); err != nil {
if err := json2.UnmarshalPB([]byte(subFlags.Arg(0)), ms); err != nil {
return err
}
ms.Cell = *cells
Expand Down Expand Up @@ -3402,7 +3402,7 @@ func commandApplyVSchema(ctx context.Context, wr *wrangler.Wrangler, subFlags *p
}

vs = &vschemapb.Keyspace{}
err := json2.Unmarshal(schema, vs)
err := json2.UnmarshalPB(schema, vs)
if err != nil {
return err
}
Expand Down Expand Up @@ -3490,7 +3490,7 @@ func commandApplyRoutingRules(ctx context.Context, wr *wrangler.Wrangler, subFla
}

rr := &vschemapb.RoutingRules{}
if err := json2.Unmarshal(rulesBytes, rr); err != nil {
if err := json2.UnmarshalPB(rulesBytes, rr); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtctl/workflow/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (ts *trafficSwitcher) addParticipatingTablesToKeyspace(ctx context.Context,
if strings.HasPrefix(tableSpecs, "{") { // user defined the vschema snippet, typically for a sharded target
wrap := fmt.Sprintf(`{"tables": %s}`, tableSpecs)
ks := &vschemapb.Keyspace{}
if err := json2.Unmarshal([]byte(wrap), ks); err != nil {
if err := json2.UnmarshalPB([]byte(wrap), ks); err != nil {
return err
}
for table, vtab := range ks.Tables {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtexplain/vtexplain_vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (vte *VTExplain) buildTopology(ctx context.Context, ts *topo.Server, opts *
// handle string->enum conversion correctly.
var srvVSchema vschemapb.SrvVSchema
wrappedStr := fmt.Sprintf(`{"keyspaces": %s}`, vschemaStr)
err := json2.Unmarshal([]byte(wrappedStr), &srvVSchema)
err := json2.UnmarshalPB([]byte(wrappedStr), &srvVSchema)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func onceInit() {
// loadSchemaForFuzzing is a helper to load *vindexes.VSchema
// for fuzzing.
func loadSchemaForFuzzing(f *fuzz.ConsumeFuzzer) (*vindexes.VSchema, error) {
//formal, err := vindexes.LoadFormal(filename)
// formal, err := vindexes.LoadFormal(filename)
formal, err := loadFormalForFuzzing(f)
if err != nil {
return nil, err
Expand Down Expand Up @@ -69,7 +69,7 @@ func loadFormalForFuzzing(f *fuzz.ConsumeFuzzer) (*vschemapb.SrvVSchema, error)
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
err = json2.UnmarshalPB(data, formal)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func getSandboxSrvVSchema() *vschemapb.SrvVSchema {
defer sandboxMu.Unlock()
for keyspace, sandbox := range ksToSandbox {
var vs vschemapb.Keyspace
if err := json2.Unmarshal([]byte(sandbox.VSchema), &vs); err != nil {
if err := json2.UnmarshalPB([]byte(sandbox.VSchema), &vs); err != nil {
panic(err)
}
result.Keyspaces[keyspace] = &vs
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ func LoadFormal(filename string) (*vschemapb.SrvVSchema, error) {
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
err = json2.UnmarshalPB(data, formal)
if err != nil {
return nil, err
}
Expand All @@ -1367,7 +1367,7 @@ func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error) {
if err != nil {
return nil, err
}
err = json2.Unmarshal(data, formal)
err = json2.UnmarshalPB(data, formal)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/vindexes/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2735,7 +2735,7 @@ func TestVSchemaPBJSON(t *testing.T) {
}
`
var got vschemapb.Keyspace
if err := json2.Unmarshal([]byte(in), &got); err != nil {
if err := json2.UnmarshalPB([]byte(in), &got); err != nil {
t.Error(err)
}
want := vschemapb.Keyspace{
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/vstreamer/planbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func init() {
}
}`
var kspb vschemapb.Keyspace
if err := json2.Unmarshal([]byte(input), &kspb); err != nil {
if err := json2.UnmarshalPB([]byte(input), &kspb); err != nil {
panic(fmt.Errorf("Unmarshal failed: %v", err))
}
srvVSchema := &vschemapb.SrvVSchema{
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (te *Env) Close() {
func (te *Env) SetVSchema(vs string) error {
ctx := context.Background()
var kspb vschemapb.Keyspace
if err := json2.Unmarshal([]byte(vs), &kspb); err != nil {
if err := json2.UnmarshalPB([]byte(vs), &kspb); err != nil {
return err
}
if err := te.TopoServ.SaveVSchema(ctx, te.KeyspaceName, &kspb); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/materializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (wr *Wrangler) MoveTables(ctx context.Context, workflow, sourceKeyspace, ta
}
wrap := fmt.Sprintf(`{"tables": %s}`, tableSpecs)
ks := &vschemapb.Keyspace{}
if err := json2.Unmarshal([]byte(wrap), ks); err != nil {
if err := json2.UnmarshalPB([]byte(wrap), ks); err != nil {
return err
}
for table, vtab := range ks.Tables {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/wrangler/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ func doValidateWorkflowHasCompleted(ctx context.Context, ts *trafficSwitcher) er
wg.Wait()

if !ts.keepRoutingRules {
//check if table is routable
// check if table is routable
if ts.MigrationType() == binlogdatapb.MigrationType_TABLES {
rules, err := topotools.GetRoutingRules(ctx, ts.TopoServer())
if err != nil {
Expand Down Expand Up @@ -1981,7 +1981,7 @@ func (ts *trafficSwitcher) addParticipatingTablesToKeyspace(ctx context.Context,
if strings.HasPrefix(tableSpecs, "{") { // user defined the vschema snippet, typically for a sharded target
wrap := fmt.Sprintf(`{"tables": %s}`, tableSpecs)
ks := &vschemapb.Keyspace{}
if err := json2.Unmarshal([]byte(wrap), ks); err != nil {
if err := json2.UnmarshalPB([]byte(wrap), ks); err != nil {
return err
}
for table, vtab := range ks.Tables {
Expand Down

0 comments on commit 780abdd

Please sign in to comment.