Skip to content

Commit e4e2c0a

Browse files
Move Unmarshal() to UnmarshalPB() when unmarshalling a proto object
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
1 parent e827f6b commit e4e2c0a

File tree

19 files changed

+33
-33
lines changed

19 files changed

+33
-33
lines changed

go/cmd/vtctldclient/command/vschemas.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func commandApplyVSchema(cmd *cobra.Command, args []string) error {
102102
}
103103

104104
var vs vschemapb.Keyspace
105-
err = json2.Unmarshal(schema, &vs)
105+
err = json2.UnmarshalPB(schema, &vs)
106106
if err != nil {
107107
return err
108108
}

go/test/endtoend/backup/vtctlbackup/backup_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func checkTabletType(t *testing.T, alias string, tabletType topodata.TabletType)
837837
output, err := localCluster.VtctldClientProcess.ExecuteCommandWithOutput("GetTablet", alias)
838838
require.NoError(t, err)
839839
var tabletPB topodata.Tablet
840-
err = json2.Unmarshal([]byte(output), &tabletPB)
840+
err = json2.UnmarshalPB([]byte(output), &tabletPB)
841841
require.NoError(t, err)
842842
if tabletType == tabletPB.Type {
843843
return
@@ -1058,7 +1058,7 @@ func terminateBackup(t *testing.T, alias string) {
10581058
text := scanner.Text()
10591059
if strings.Contains(text, stopBackupMsg) {
10601060
tmpProcess.Process.Signal(syscall.SIGTERM)
1061-
found = true //nolint
1061+
found = true // nolint
10621062
return
10631063
}
10641064
}

go/test/endtoend/cluster/vtctldclient_process.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (vtctldclient *VtctldClientProcess) GetShardReplication(keyspace string, sh
173173
}
174174

175175
var resp vtctldatapb.GetShardReplicationResponse
176-
err = json2.Unmarshal([]byte(out), &resp)
176+
err = json2.UnmarshalPB([]byte(out), &resp)
177177
return resp.ShardReplicationByCell, err
178178
}
179179

@@ -252,7 +252,7 @@ func (vtctldclient *VtctldClientProcess) GetKeyspace(keyspace string) (*vtctldat
252252
}
253253

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

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

284284
var tablet topodatapb.Tablet
285-
err = json2.Unmarshal([]byte(data), &tablet)
285+
err = json2.UnmarshalPB([]byte(data), &tablet)
286286
if err != nil {
287287
return nil, vterrors.Wrapf(err, "failed to parse tablet output: %s", data)
288288
}

go/test/endtoend/recovery/pitr/shardedpitr_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestPITRRecovery(t *testing.T) {
130130
initializeCluster(t)
131131
defer clusterInstance.Teardown()
132132

133-
//start the binlog server and point it to primary
133+
// start the binlog server and point it to primary
134134
bs := startBinlogServer(t, primary)
135135
defer bs.stop()
136136

@@ -167,11 +167,11 @@ func TestPITRRecovery(t *testing.T) {
167167
// starting resharding process
168168
performResharding(t)
169169

170-
//start the binlog server and point it to shard0Primary
170+
// start the binlog server and point it to shard0Primary
171171
bs0 := startBinlogServer(t, shard0Primary)
172172
defer bs0.stop()
173173

174-
//start the binlog server and point it to shard1Primary
174+
// start the binlog server and point it to shard1Primary
175175
bs1 := startBinlogServer(t, shard1Primary)
176176
defer bs1.stop()
177177

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

587587
var resp vtctldatapb.GetWorkflowsResponse
588-
err = json2.Unmarshal([]byte(output), &resp)
588+
err = json2.UnmarshalPB([]byte(output), &resp)
589589
require.NoError(t, err)
590590
require.GreaterOrEqual(t, len(resp.Workflows), 1, "responce should have at least one workflow")
591591
lag = resp.Workflows[0].MaxVReplicationTransactionLag

go/test/endtoend/tabletgateway/buffer/reshard/sharded_buffer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func waitForLowLag(t *testing.T, clusterInstance *cluster.LocalProcessCluster, k
4646
require.NoError(t, err)
4747

4848
var resp vtctldatapb.GetWorkflowsResponse
49-
err = json2.Unmarshal([]byte(output), &resp)
49+
err = json2.UnmarshalPB([]byte(output), &resp)
5050
require.NoError(t, err)
5151
require.GreaterOrEqual(t, len(resp.Workflows), 1, "responce should have at least one workflow")
5252
lagSeconds := resp.Workflows[0].MaxVReplicationTransactionLag

go/test/endtoend/tabletmanager/commands_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func runHookAndAssert(t *testing.T, params []string, expectedStatus int64, expec
197197
require.Nil(t, err)
198198

199199
var resp vtctldatapb.ExecuteHookResponse
200-
err = json2.Unmarshal([]byte(hr), &resp)
200+
err = json2.UnmarshalPB([]byte(hr), &resp)
201201
require.Nil(t, err)
202202

203203
assert.Equal(t, expectedStatus, resp.HookResult.ExitStatus)

go/vt/tableacl/tableacl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error {
113113
config := &tableaclpb.Config{}
114114
if err := config.UnmarshalVT(data); err != nil {
115115
// try to parse tableacl as json file
116-
if jsonErr := json2.Unmarshal(data, config); jsonErr != nil {
116+
if jsonErr := json2.UnmarshalPB(data, config); jsonErr != nil {
117117
log.Infof("unable to parse tableACL config file as a protobuf or json file. protobuf err: %v json err: %v", err, jsonErr)
118118
return fmt.Errorf("unable to unmarshal Table ACL data: %s", data)
119119
}

go/vt/vtctl/endtoend/get_schema_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestGetSchema(t *testing.T) {
173173
val := events[0].Value
174174

175175
actual := &tabletmanagerdatapb.SchemaDefinition{}
176-
err = json2.Unmarshal([]byte(val), actual)
176+
err = json2.UnmarshalPB([]byte(val), actual)
177177
require.NoError(t, err)
178178

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

216216
actual = &tabletmanagerdatapb.SchemaDefinition{}
217-
err = json2.Unmarshal([]byte(val), actual)
217+
err = json2.UnmarshalPB([]byte(val), actual)
218218
require.NoError(t, err)
219219

220220
utils.MustMatch(t, sd, actual)

go/vt/vtctl/vtctl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,7 @@ func commandCreateLookupVindex(ctx context.Context, wr *wrangler.Wrangler, subFl
25072507
}
25082508
keyspace := subFlags.Arg(0)
25092509
specs := &vschemapb.Keyspace{}
2510-
if err := json2.Unmarshal([]byte(subFlags.Arg(1)), specs); err != nil {
2510+
if err := json2.UnmarshalPB([]byte(subFlags.Arg(1)), specs); err != nil {
25112511
return err
25122512
}
25132513
return wr.CreateLookupVindex(ctx, keyspace, specs, *cells, *tabletTypes, *continueAfterCopyWithOwner)
@@ -2533,7 +2533,7 @@ func commandMaterialize(ctx context.Context, wr *wrangler.Wrangler, subFlags *pf
25332533
return fmt.Errorf("a single argument is required: <json_spec>")
25342534
}
25352535
ms := &vtctldatapb.MaterializeSettings{}
2536-
if err := json2.Unmarshal([]byte(subFlags.Arg(0)), ms); err != nil {
2536+
if err := json2.UnmarshalPB([]byte(subFlags.Arg(0)), ms); err != nil {
25372537
return err
25382538
}
25392539
ms.Cell = *cells
@@ -3402,7 +3402,7 @@ func commandApplyVSchema(ctx context.Context, wr *wrangler.Wrangler, subFlags *p
34023402
}
34033403

34043404
vs = &vschemapb.Keyspace{}
3405-
err := json2.Unmarshal(schema, vs)
3405+
err := json2.UnmarshalPB(schema, vs)
34063406
if err != nil {
34073407
return err
34083408
}
@@ -3490,7 +3490,7 @@ func commandApplyRoutingRules(ctx context.Context, wr *wrangler.Wrangler, subFla
34903490
}
34913491

34923492
rr := &vschemapb.RoutingRules{}
3493-
if err := json2.Unmarshal(rulesBytes, rr); err != nil {
3493+
if err := json2.UnmarshalPB(rulesBytes, rr); err != nil {
34943494
return err
34953495
}
34963496

go/vt/vtctl/workflow/traffic_switcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (ts *trafficSwitcher) addParticipatingTablesToKeyspace(ctx context.Context,
390390
if strings.HasPrefix(tableSpecs, "{") { // user defined the vschema snippet, typically for a sharded target
391391
wrap := fmt.Sprintf(`{"tables": %s}`, tableSpecs)
392392
ks := &vschemapb.Keyspace{}
393-
if err := json2.Unmarshal([]byte(wrap), ks); err != nil {
393+
if err := json2.UnmarshalPB([]byte(wrap), ks); err != nil {
394394
return err
395395
}
396396
for table, vtab := range ks.Tables {

go/vt/vtexplain/vtexplain_vtgate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (vte *VTExplain) buildTopology(ctx context.Context, ts *topo.Server, opts *
101101
// handle string->enum conversion correctly.
102102
var srvVSchema vschemapb.SrvVSchema
103103
wrappedStr := fmt.Sprintf(`{"keyspaces": %s}`, vschemaStr)
104-
err := json2.Unmarshal([]byte(wrappedStr), &srvVSchema)
104+
err := json2.UnmarshalPB([]byte(wrappedStr), &srvVSchema)
105105
if err != nil {
106106
return err
107107
}

go/vt/vtgate/planbuilder/fuzz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func onceInit() {
3737
// loadSchemaForFuzzing is a helper to load *vindexes.VSchema
3838
// for fuzzing.
3939
func loadSchemaForFuzzing(f *fuzz.ConsumeFuzzer) (*vindexes.VSchema, error) {
40-
//formal, err := vindexes.LoadFormal(filename)
40+
// formal, err := vindexes.LoadFormal(filename)
4141
formal, err := loadFormalForFuzzing(f)
4242
if err != nil {
4343
return nil, err
@@ -69,7 +69,7 @@ func loadFormalForFuzzing(f *fuzz.ConsumeFuzzer) (*vschemapb.SrvVSchema, error)
6969
if err != nil {
7070
return nil, err
7171
}
72-
err = json2.Unmarshal(data, formal)
72+
err = json2.UnmarshalPB(data, formal)
7373
if err != nil {
7474
return nil, err
7575
}

go/vt/vtgate/sandbox_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func getSandboxSrvVSchema() *vschemapb.SrvVSchema {
8181
defer sandboxMu.Unlock()
8282
for keyspace, sandbox := range ksToSandbox {
8383
var vs vschemapb.Keyspace
84-
if err := json2.Unmarshal([]byte(sandbox.VSchema), &vs); err != nil {
84+
if err := json2.UnmarshalPB([]byte(sandbox.VSchema), &vs); err != nil {
8585
panic(err)
8686
}
8787
result.Keyspaces[keyspace] = &vs

go/vt/vtgate/vindexes/vschema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ func LoadFormal(filename string) (*vschemapb.SrvVSchema, error) {
13491349
if err != nil {
13501350
return nil, err
13511351
}
1352-
err = json2.Unmarshal(data, formal)
1352+
err = json2.UnmarshalPB(data, formal)
13531353
if err != nil {
13541354
return nil, err
13551355
}
@@ -1367,7 +1367,7 @@ func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error) {
13671367
if err != nil {
13681368
return nil, err
13691369
}
1370-
err = json2.Unmarshal(data, formal)
1370+
err = json2.UnmarshalPB(data, formal)
13711371
if err != nil {
13721372
return nil, err
13731373
}

go/vt/vtgate/vindexes/vschema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ func TestVSchemaPBJSON(t *testing.T) {
27352735
}
27362736
`
27372737
var got vschemapb.Keyspace
2738-
if err := json2.Unmarshal([]byte(in), &got); err != nil {
2738+
if err := json2.UnmarshalPB([]byte(in), &got); err != nil {
27392739
t.Error(err)
27402740
}
27412741
want := vschemapb.Keyspace{

go/vt/vttablet/tabletserver/vstreamer/planbuilder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func init() {
7777
}
7878
}`
7979
var kspb vschemapb.Keyspace
80-
if err := json2.Unmarshal([]byte(input), &kspb); err != nil {
80+
if err := json2.UnmarshalPB([]byte(input), &kspb); err != nil {
8181
panic(fmt.Errorf("Unmarshal failed: %v", err))
8282
}
8383
srvVSchema := &vschemapb.SrvVSchema{

go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (te *Env) Close() {
202202
func (te *Env) SetVSchema(vs string) error {
203203
ctx := context.Background()
204204
var kspb vschemapb.Keyspace
205-
if err := json2.Unmarshal([]byte(vs), &kspb); err != nil {
205+
if err := json2.UnmarshalPB([]byte(vs), &kspb); err != nil {
206206
return err
207207
}
208208
if err := te.TopoServ.SaveVSchema(ctx, te.KeyspaceName, &kspb); err != nil {

go/vt/wrangler/materializer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (wr *Wrangler) MoveTables(ctx context.Context, workflow, sourceKeyspace, ta
162162
}
163163
wrap := fmt.Sprintf(`{"tables": %s}`, tableSpecs)
164164
ks := &vschemapb.Keyspace{}
165-
if err := json2.Unmarshal([]byte(wrap), ks); err != nil {
165+
if err := json2.UnmarshalPB([]byte(wrap), ks); err != nil {
166166
return err
167167
}
168168
for table, vtab := range ks.Tables {

go/vt/wrangler/traffic_switcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ func doValidateWorkflowHasCompleted(ctx context.Context, ts *trafficSwitcher) er
17431743
wg.Wait()
17441744

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

0 commit comments

Comments
 (0)