From dea2514114a78ebdc44b555953722791d118d39e Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 7 Mar 2023 15:55:09 +0100 Subject: [PATCH] Use `MarshalVT`/`UnmarshalVT` instead of `proto.Marshal`/`proto.Unmarshal`. (#12525) * Use `MarshalVT` instead of `proto.Marshal`. Signed-off-by: Arthur Schreiber * Use `UnmarshalVT` instead of `proto.Unmarshal`. Signed-off-by: Arthur Schreiber --------- Signed-off-by: Arthur Schreiber --- go/vt/tableacl/tableacl.go | 2 +- go/vt/topo/cell_info.go | 9 ++++----- go/vt/topo/cells_aliases.go | 12 +++++------- go/vt/topo/external_vitess_cluster.go | 8 +++----- go/vt/topo/keyspace.go | 8 +++----- go/vt/topo/replication.go | 6 +++--- go/vt/topo/shard.go | 10 +++++----- go/vt/topo/srv_keyspace.go | 10 ++++------ go/vt/topo/srv_vschema.go | 10 ++++------ go/vt/topo/tablet.go | 8 ++++---- go/vt/topo/test/watch.go | 16 ++++++++-------- go/vt/topo/topotests/shard_watch_test.go | 2 +- go/vt/topo/vschema.go | 10 +++++----- go/vt/topo/workflow.go | 8 +++----- go/vt/vitessdriver/driver.go | 5 ++--- go/vt/vtgate/engine/ordered_aggregate.go | 10 ++++------ go/vt/vttablet/tabletserver/schema/historian.go | 4 +--- .../tabletserver/schema/historian_test.go | 3 +-- .../vstreamer/vstreamer_flaky_test.go | 2 +- go/vt/wrangler/testlib/vtctl_topo_test.go | 2 +- 20 files changed, 63 insertions(+), 82 deletions(-) diff --git a/go/vt/tableacl/tableacl.go b/go/vt/tableacl/tableacl.go index 4f83edf18e7..4ee46ae7739 100644 --- a/go/vt/tableacl/tableacl.go +++ b/go/vt/tableacl/tableacl.go @@ -113,7 +113,7 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error { return err } config := &tableaclpb.Config{} - if err := proto.Unmarshal(data, config); err != nil { + if err := config.UnmarshalVT(data); err != nil { // try to parse tableacl as json file if jsonErr := json2.Unmarshal(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) diff --git a/go/vt/topo/cell_info.go b/go/vt/topo/cell_info.go index 2af867a8ffc..e2c1965fda1 100644 --- a/go/vt/topo/cell_info.go +++ b/go/vt/topo/cell_info.go @@ -21,7 +21,6 @@ import ( "path" "strings" - "google.golang.org/protobuf/proto" "k8s.io/apimachinery/pkg/util/sets" "vitess.io/vitess/go/vt/vterrors" @@ -74,7 +73,7 @@ func (ts *Server) GetCellInfo(ctx context.Context, cell string, strongRead bool) // Unpack the contents. ci := &topodatapb.CellInfo{} - if err := proto.Unmarshal(contents, ci); err != nil { + if err := ci.UnmarshalVT(contents); err != nil { return nil, err } return ci, nil @@ -83,7 +82,7 @@ func (ts *Server) GetCellInfo(ctx context.Context, cell string, strongRead bool) // CreateCellInfo creates a new CellInfo with the provided content. func (ts *Server) CreateCellInfo(ctx context.Context, cell string, ci *topodatapb.CellInfo) error { // Pack the content. - contents, err := proto.Marshal(ci) + contents, err := ci.MarshalVT() if err != nil { return err } @@ -108,7 +107,7 @@ func (ts *Server) UpdateCellInfoFields(ctx context.Context, cell string, update contents, version, err := ts.globalCell.Get(ctx, filePath) switch { case err == nil: - if err := proto.Unmarshal(contents, ci); err != nil { + if err := ci.UnmarshalVT(contents); err != nil { return err } case IsErrType(err, NoNode): @@ -126,7 +125,7 @@ func (ts *Server) UpdateCellInfoFields(ctx context.Context, cell string, update } // Pack and save. - contents, err = proto.Marshal(ci) + contents, err = ci.MarshalVT() if err != nil { return err } diff --git a/go/vt/topo/cells_aliases.go b/go/vt/topo/cells_aliases.go index ee47ec62604..683fa08f6ba 100644 --- a/go/vt/topo/cells_aliases.go +++ b/go/vt/topo/cells_aliases.go @@ -20,8 +20,6 @@ import ( "fmt" "path" - "google.golang.org/protobuf/proto" - "context" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -63,7 +61,7 @@ func (ts *Server) GetCellsAliases(ctx context.Context, strongRead bool) (ret map // Unpack the contents. cellsAlias := &topodatapb.CellsAlias{} - if err := proto.Unmarshal(contents, cellsAlias); err != nil { + if err := cellsAlias.UnmarshalVT(contents); err != nil { return nil, err } @@ -90,7 +88,7 @@ func (ts *Server) GetCellsAlias(ctx context.Context, name string, strongRead boo // Unpack the contents. cellsAlias := &topodatapb.CellsAlias{} - if err := proto.Unmarshal(contents, cellsAlias); err != nil { + if err := cellsAlias.UnmarshalVT(contents); err != nil { return nil, err } @@ -119,7 +117,7 @@ func (ts *Server) CreateCellsAlias(ctx context.Context, alias string, cellsAlias ts.clearCellAliasesCache() // Pack the content. - contents, err := proto.Marshal(cellsAlias) + contents, err := cellsAlias.MarshalVT() if err != nil { return err } @@ -142,7 +140,7 @@ func (ts *Server) UpdateCellsAlias(ctx context.Context, alias string, update fun contents, version, err := ts.globalCell.Get(ctx, filePath) switch { case err == nil: - if err := proto.Unmarshal(contents, cellsAlias); err != nil { + if err := cellsAlias.UnmarshalVT(contents); err != nil { return err } case IsErrType(err, NoNode): @@ -169,7 +167,7 @@ func (ts *Server) UpdateCellsAlias(ctx context.Context, alias string, update fun } // Pack and save. - contents, err = proto.Marshal(cellsAlias) + contents, err = cellsAlias.MarshalVT() if err != nil { return err } diff --git a/go/vt/topo/external_vitess_cluster.go b/go/vt/topo/external_vitess_cluster.go index 81633312f12..a7d0a69bf2c 100644 --- a/go/vt/topo/external_vitess_cluster.go +++ b/go/vt/topo/external_vitess_cluster.go @@ -20,8 +20,6 @@ import ( "context" "path" - "google.golang.org/protobuf/proto" - "vitess.io/vitess/go/event" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo/events" @@ -49,7 +47,7 @@ func GetExternalVitessClusterPath(clusterName string) string { // CreateExternalVitessCluster creates a topo record for the passed vitess cluster func (ts *Server) CreateExternalVitessCluster(ctx context.Context, clusterName string, value *topodatapb.ExternalVitessCluster) error { - data, err := proto.Marshal(value) + data, err := value.MarshalVT() if err != nil { return err } @@ -77,7 +75,7 @@ func (ts *Server) GetExternalVitessCluster(ctx context.Context, clusterName stri return nil, err } vc := &topodatapb.ExternalVitessCluster{} - if err = proto.Unmarshal(data, vc); err != nil { + if err = vc.UnmarshalVT(data); err != nil { return nil, vterrors.Wrap(err, "bad vitess cluster data") } @@ -91,7 +89,7 @@ func (ts *Server) GetExternalVitessCluster(ctx context.Context, clusterName stri // UpdateExternalVitessCluster updates the topo record for the named vitess cluster func (ts *Server) UpdateExternalVitessCluster(ctx context.Context, vc *ExternalVitessClusterInfo) error { //FIXME: check for cluster lock - data, err := proto.Marshal(vc.ExternalVitessCluster) + data, err := vc.ExternalVitessCluster.MarshalVT() if err != nil { return err } diff --git a/go/vt/topo/keyspace.go b/go/vt/topo/keyspace.go index 3a0416c9032..14b19393750 100755 --- a/go/vt/topo/keyspace.go +++ b/go/vt/topo/keyspace.go @@ -20,8 +20,6 @@ import ( "path" "strings" - "google.golang.org/protobuf/proto" - "context" "vitess.io/vitess/go/vt/vterrors" @@ -180,7 +178,7 @@ func (ts *Server) CreateKeyspace(ctx context.Context, keyspace string, value *to return vterrors.Wrapf(err, "CreateKeyspace: %s", err) } - data, err := proto.Marshal(value) + data, err := value.MarshalVT() if err != nil { return err } @@ -211,7 +209,7 @@ func (ts *Server) GetKeyspace(ctx context.Context, keyspace string) (*KeyspaceIn } k := &topodatapb.Keyspace{} - if err = proto.Unmarshal(data, k); err != nil { + if err = k.UnmarshalVT(data); err != nil { return nil, vterrors.Wrap(err, "bad keyspace data") } @@ -251,7 +249,7 @@ func (ts *Server) UpdateKeyspace(ctx context.Context, ki *KeyspaceInfo) error { return err } - data, err := proto.Marshal(ki.Keyspace) + data, err := ki.Keyspace.MarshalVT() if err != nil { return err } diff --git a/go/vt/topo/replication.go b/go/vt/topo/replication.go index 7b452f30447..ace6b4445da 100644 --- a/go/vt/topo/replication.go +++ b/go/vt/topo/replication.go @@ -186,7 +186,7 @@ func (ts *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspa // Empty node, version is nil case err == nil: // Use any data we got. - if err = proto.Unmarshal(data, sr); err != nil { + if err = sr.UnmarshalVT(data); err != nil { return vterrors.Wrap(err, "bad ShardReplication data") } default: @@ -204,7 +204,7 @@ func (ts *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspa } // marshall and save - data, err = proto.Marshal(sr) + data, err = sr.MarshalVT() if err != nil { return err } @@ -243,7 +243,7 @@ func (ts *Server) GetShardReplication(ctx context.Context, cell, keyspace, shard } sr := &topodatapb.ShardReplication{} - if err = proto.Unmarshal(data, sr); err != nil { + if err = sr.UnmarshalVT(data); err != nil { return nil, vterrors.Wrap(err, "bad ShardReplication data") } diff --git a/go/vt/topo/shard.go b/go/vt/topo/shard.go index 2599c7de962..8b961dbe4c3 100644 --- a/go/vt/topo/shard.go +++ b/go/vt/topo/shard.go @@ -213,7 +213,7 @@ func (ts *Server) GetShard(ctx context.Context, keyspace, shard string) (*ShardI } value := &topodatapb.Shard{} - if err = proto.Unmarshal(data, value); err != nil { + if err = value.UnmarshalVT(data); err != nil { return nil, vterrors.Wrapf(err, "GetShard(%v,%v): bad shard data", keyspace, shard) } return &ShardInfo{ @@ -232,7 +232,7 @@ func (ts *Server) updateShard(ctx context.Context, si *ShardInfo) error { span.Annotate("shard", si.shardName) defer span.Finish() - data, err := proto.Marshal(si.Shard) + data, err := si.Shard.MarshalVT() if err != nil { return err } @@ -315,7 +315,7 @@ func (ts *Server) CreateShard(ctx context.Context, keyspace, shard string) (err } // Marshal and save. - data, err := proto.Marshal(value) + data, err := value.MarshalVT() if err != nil { return err } @@ -670,7 +670,7 @@ func (ts *Server) WatchShard(ctx context.Context, keyspace, shard string) (*Watc return nil, nil, err } value := &topodatapb.Shard{} - if err := proto.Unmarshal(current.Contents, value); err != nil { + if err := value.UnmarshalVT(current.Contents); err != nil { // Cancel the watch, drain channel. cancel() for range wdChannel { @@ -698,7 +698,7 @@ func (ts *Server) WatchShard(ctx context.Context, keyspace, shard string) (*Watc } value := &topodatapb.Shard{} - if err := proto.Unmarshal(wd.Contents, value); err != nil { + if err := value.UnmarshalVT(wd.Contents); err != nil { cancel() for range wdChannel { } diff --git a/go/vt/topo/srv_keyspace.go b/go/vt/topo/srv_keyspace.go index e431ce55c40..8054764eeff 100644 --- a/go/vt/topo/srv_keyspace.go +++ b/go/vt/topo/srv_keyspace.go @@ -23,8 +23,6 @@ import ( "path" "sync" - "google.golang.org/protobuf/proto" - "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/concurrency" @@ -64,7 +62,7 @@ func (ts *Server) WatchSrvKeyspace(ctx context.Context, cell, keyspace string) ( return nil, nil, err } value := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(current.Contents, value); err != nil { + if err := value.UnmarshalVT(current.Contents); err != nil { // Cancel the watch, drain channel. cancel() for range wdChannel { @@ -93,7 +91,7 @@ func (ts *Server) WatchSrvKeyspace(ctx context.Context, cell, keyspace string) ( } value := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, value); err != nil { + if err := value.UnmarshalVT(wd.Contents); err != nil { cancel() for range wdChannel { } @@ -637,7 +635,7 @@ func (ts *Server) UpdateSrvKeyspace(ctx context.Context, cell, keyspace string, } nodePath := srvKeyspaceFileName(keyspace) - data, err := proto.Marshal(srvKeyspace) + data, err := srvKeyspace.MarshalVT() if err != nil { return err } @@ -691,7 +689,7 @@ func (ts *Server) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*t return nil, err } srvKeyspace := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(data, srvKeyspace); err != nil { + if err := srvKeyspace.UnmarshalVT(data); err != nil { return nil, vterrors.Wrapf(err, "SrvKeyspace unmarshal failed: %v", data) } return srvKeyspace, nil diff --git a/go/vt/topo/srv_vschema.go b/go/vt/topo/srv_vschema.go index 204b2696370..453e8c5f8d0 100644 --- a/go/vt/topo/srv_vschema.go +++ b/go/vt/topo/srv_vschema.go @@ -21,8 +21,6 @@ import ( "fmt" "sync" - "google.golang.org/protobuf/proto" - "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/vterrors" @@ -54,7 +52,7 @@ func (ts *Server) WatchSrvVSchema(ctx context.Context, cell string) (*WatchSrvVS return nil, nil, err } value := &vschemapb.SrvVSchema{} - if err := proto.Unmarshal(current.Contents, value); err != nil { + if err := value.UnmarshalVT(current.Contents); err != nil { // Cancel the watch, drain channel. cancel() for range wdChannel { @@ -83,7 +81,7 @@ func (ts *Server) WatchSrvVSchema(ctx context.Context, cell string) (*WatchSrvVS } value := &vschemapb.SrvVSchema{} - if err := proto.Unmarshal(wd.Contents, value); err != nil { + if err := value.UnmarshalVT(wd.Contents); err != nil { cancel() for range wdChannel { } @@ -105,7 +103,7 @@ func (ts *Server) UpdateSrvVSchema(ctx context.Context, cell string, srvVSchema } nodePath := SrvVSchemaFile - data, err := proto.Marshal(srvVSchema) + data, err := srvVSchema.MarshalVT() if err != nil { return err } @@ -126,7 +124,7 @@ func (ts *Server) GetSrvVSchema(ctx context.Context, cell string) (*vschemapb.Sr return nil, err } srvVSchema := &vschemapb.SrvVSchema{} - if err := proto.Unmarshal(data, srvVSchema); err != nil { + if err := srvVSchema.UnmarshalVT(data); err != nil { return nil, vterrors.Wrapf(err, "SrvVSchema unmarshal failed: %v", data) } return srvVSchema, nil diff --git a/go/vt/topo/tablet.go b/go/vt/topo/tablet.go index 619b67489e4..b68a48b0223 100644 --- a/go/vt/topo/tablet.go +++ b/go/vt/topo/tablet.go @@ -245,7 +245,7 @@ func (ts *Server) GetTablet(ctx context.Context, alias *topodatapb.TabletAlias) return nil, err } tablet := &topodatapb.Tablet{} - if err := proto.Unmarshal(data, tablet); err != nil { + if err := tablet.UnmarshalVT(data); err != nil { return nil, err } @@ -310,7 +310,7 @@ func (ts *Server) GetTabletsByCell(ctx context.Context, cellAlias string) ([]*Ta tablets := make([]*TabletInfo, len(listResults)) for n := range listResults { tablet := &topodatapb.Tablet{} - if err := proto.Unmarshal(listResults[n].Value, tablet); err != nil { + if err := tablet.UnmarshalVT(listResults[n].Value); err != nil { return nil, err } tablets[n] = &TabletInfo{Tablet: tablet, version: listResults[n].Version} @@ -363,7 +363,7 @@ func (ts *Server) UpdateTablet(ctx context.Context, ti *TabletInfo) error { span.Annotate("tablet", topoproto.TabletAliasString(ti.Alias)) defer span.Finish() - data, err := proto.Marshal(ti.Tablet) + data, err := ti.Tablet.MarshalVT() if err != nil { return err } @@ -441,7 +441,7 @@ func (ts *Server) CreateTablet(ctx context.Context, tablet *topodatapb.Tablet) e return err } - data, err := proto.Marshal(tablet) + data, err := tablet.MarshalVT() if err != nil { return err } diff --git a/go/vt/topo/test/watch.go b/go/vt/topo/test/watch.go index 24e831718d1..08dec8cd56f 100644 --- a/go/vt/topo/test/watch.go +++ b/go/vt/topo/test/watch.go @@ -57,7 +57,7 @@ func waitForInitialValue(t *testing.T, conn topo.Conn, srvKeyspace *topodatapb.S break } got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(current.Contents, got); err != nil { + if err := got.UnmarshalVT(current.Contents); err != nil { cancel() t.Fatalf("cannot proto-unmarshal data: %v", err) } @@ -100,7 +100,7 @@ func waitForInitialValueRecursive(t *testing.T, conn topo.Conn, srvKeyspace *top break } got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(current[0].Contents, got); err != nil { + if err := got.UnmarshalVT(current[0].Contents); err != nil { cancel() t.Fatalf("cannot proto-unmarshal data: %v", err) } @@ -173,7 +173,7 @@ func checkWatch(t *testing.T, ts *topo.Server) { t.Fatalf("watch interrupted: %v", wd.Err) } got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, got); err != nil { + if err := got.UnmarshalVT(wd.Contents); err != nil { t.Fatalf("cannot proto-unmarshal data: %v", err) } @@ -210,7 +210,7 @@ func checkWatch(t *testing.T, ts *topo.Server) { } // we got something, better be the right value got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, got); err != nil { + if err := got.UnmarshalVT(wd.Contents); err != nil { t.Fatalf("cannot proto-unmarshal data: %v", err) } if got.Partitions[0].ShardReferences[0].Name == "new_name" { @@ -278,7 +278,7 @@ func checkWatchInterrupt(t *testing.T, ts *topo.Server) { } // we got something, better be the right value got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, got); err != nil { + if err := got.UnmarshalVT(wd.Contents); err != nil { t.Fatalf("cannot proto-unmarshal data: %v", err) } if got.Partitions[0].ShardReferences[0].Name == "name" { @@ -356,7 +356,7 @@ func checkWatchRecursive(t *testing.T, ts *topo.Server) { t.Fatalf("watch interrupted: %v", wd.Err) } got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, got); err != nil { + if err := got.UnmarshalVT(wd.Contents); err != nil { t.Fatalf("cannot proto-unmarshal data: %v", err) } @@ -394,7 +394,7 @@ func checkWatchRecursive(t *testing.T, ts *topo.Server) { } // we got something, better be the right value got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, got); err != nil { + if err := got.UnmarshalVT(wd.Contents); err != nil { t.Fatalf("cannot proto-unmarshal data: %v", err) } if got.Partitions[0].ShardReferences[0].Name == "new_name" { @@ -424,7 +424,7 @@ func checkWatchRecursive(t *testing.T, ts *topo.Server) { } // we got something, better be the right value got := &topodatapb.SrvKeyspace{} - if err := proto.Unmarshal(wd.Contents, got); err != nil { + if err := got.UnmarshalVT(wd.Contents); err != nil { t.Fatalf("cannot proto-unmarshal data: %v", err) } if got.Partitions[0].ShardReferences[0].Name == "name" { diff --git a/go/vt/topo/topotests/shard_watch_test.go b/go/vt/topo/topotests/shard_watch_test.go index 89be0064f31..a8333251a2d 100644 --- a/go/vt/topo/topotests/shard_watch_test.go +++ b/go/vt/topo/topotests/shard_watch_test.go @@ -151,7 +151,7 @@ func TestWatchShard(t *testing.T) { t.Fatalf("expected an initial error setting watch on bad content, but got: %v", err) } - data, err := proto.Marshal(wanted) + data, err := wanted.MarshalVT() if err != nil { t.Fatalf("error marshalling proto data: %v", err) } diff --git a/go/vt/topo/vschema.go b/go/vt/topo/vschema.go index 85f763fc7bf..a2503673deb 100644 --- a/go/vt/topo/vschema.go +++ b/go/vt/topo/vschema.go @@ -39,7 +39,7 @@ func (ts *Server) SaveVSchema(ctx context.Context, keyspace string, vschema *vsc } nodePath := path.Join(KeyspacesPath, keyspace, VSchemaFile) - data, err := proto.Marshal(vschema) + data, err := vschema.MarshalVT() if err != nil { return err } @@ -97,7 +97,7 @@ func (ts *Server) EnsureVSchema(ctx context.Context, keyspace string) error { // SaveRoutingRules saves the routing rules into the topo. func (ts *Server) SaveRoutingRules(ctx context.Context, routingRules *vschemapb.RoutingRules) error { - data, err := proto.Marshal(routingRules) + data, err := routingRules.MarshalVT() if err != nil { return err } @@ -124,7 +124,7 @@ func (ts *Server) GetRoutingRules(ctx context.Context) (*vschemapb.RoutingRules, } return nil, err } - err = proto.Unmarshal(data, rr) + err = rr.UnmarshalVT(data) if err != nil { return nil, vterrors.Wrapf(err, "bad routing rules data: %q", data) } @@ -133,7 +133,7 @@ func (ts *Server) GetRoutingRules(ctx context.Context) (*vschemapb.RoutingRules, // SaveShardRoutingRules saves the shard routing rules into the topo. func (ts *Server) SaveShardRoutingRules(ctx context.Context, shardRoutingRules *vschemapb.ShardRoutingRules) error { - data, err := proto.Marshal(shardRoutingRules) + data, err := shardRoutingRules.MarshalVT() if err != nil { return err } @@ -159,7 +159,7 @@ func (ts *Server) GetShardRoutingRules(ctx context.Context) (*vschemapb.ShardRou } return nil, err } - err = proto.Unmarshal(data, srr) + err = srr.UnmarshalVT(data) if err != nil { return nil, vterrors.Wrapf(err, "invalid shard routing rules: %q", data) } diff --git a/go/vt/topo/workflow.go b/go/vt/topo/workflow.go index 24b40aabe1e..54d4ecbbea1 100644 --- a/go/vt/topo/workflow.go +++ b/go/vt/topo/workflow.go @@ -21,8 +21,6 @@ import ( "context" - "google.golang.org/protobuf/proto" - workflowpb "vitess.io/vitess/go/vt/proto/workflow" ) @@ -62,7 +60,7 @@ func (ts *Server) GetWorkflowNames(ctx context.Context) ([]string, error) { // WorkflowInfo. func (ts *Server) CreateWorkflow(ctx context.Context, w *workflowpb.Workflow) (*WorkflowInfo, error) { // Pack the content. - contents, err := proto.Marshal(w) + contents, err := w.MarshalVT() if err != nil { return nil, err } @@ -90,7 +88,7 @@ func (ts *Server) GetWorkflow(ctx context.Context, uuid string) (*WorkflowInfo, // Unpack the contents. w := &workflowpb.Workflow{} - if err := proto.Unmarshal(contents, w); err != nil { + if err := w.UnmarshalVT(contents); err != nil { return nil, err } @@ -104,7 +102,7 @@ func (ts *Server) GetWorkflow(ctx context.Context, uuid string) (*WorkflowInfo, // good any more, ErrBadVersion is returned. func (ts *Server) SaveWorkflow(ctx context.Context, wi *WorkflowInfo) error { // Pack the content. - contents, err := proto.Marshal(wi.Workflow) + contents, err := wi.Workflow.MarshalVT() if err != nil { return err } diff --git a/go/vt/vitessdriver/driver.go b/go/vt/vitessdriver/driver.go index b525084493c..2426a4b0532 100644 --- a/go/vt/vitessdriver/driver.go +++ b/go/vt/vitessdriver/driver.go @@ -26,7 +26,6 @@ import ( "fmt" "google.golang.org/grpc" - "google.golang.org/protobuf/proto" "vitess.io/vitess/go/sqltypes" querypb "vitess.io/vitess/go/vt/proto/query" @@ -354,7 +353,7 @@ func newSessionTokenRow(session *vtgatepb.Session, c *converter) (driver.Rows, e } func sessionToSessionToken(session *vtgatepb.Session) (string, error) { - b, err := proto.Marshal(session) + b, err := session.MarshalVT() if err != nil { return "", err } @@ -369,7 +368,7 @@ func sessionTokenToSession(sessionToken string) (*vtgatepb.Session, error) { } session := &vtgatepb.Session{} - err = proto.Unmarshal(b, session) + err = session.UnmarshalVT(b) if err != nil { return nil, err } diff --git a/go/vt/vtgate/engine/ordered_aggregate.go b/go/vt/vtgate/engine/ordered_aggregate.go index 05f0e0ffe00..60ba39fbd6d 100644 --- a/go/vt/vtgate/engine/ordered_aggregate.go +++ b/go/vt/vtgate/engine/ordered_aggregate.go @@ -25,8 +25,6 @@ import ( "vitess.io/vitess/go/vt/sqlparser" - "google.golang.org/protobuf/proto" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/vtgate/evalengine" @@ -402,7 +400,7 @@ func convertRow(row []sqltypes.Value, preProcess bool, aggregates []*AggregatePa Shard: row[aggr.Col+1].ToString(), Gtid: row[aggr.Col].ToString(), }) - data, _ := proto.Marshal(vgtid) + data, _ := vgtid.MarshalVT() val, _ := sqltypes.NewValue(sqltypes.VarBinary, data) newRow[aggr.Col] = val } @@ -516,7 +514,7 @@ func merge( if err != nil { return nil, nil, err } - err = proto.Unmarshal(rowBytes, vgtid) + err = vgtid.UnmarshalVT(rowBytes) if err != nil { return nil, nil, err } @@ -525,7 +523,7 @@ func merge( Shard: row2[aggr.Col+1].ToString(), Gtid: row2[aggr.Col].ToString(), }) - data, _ := proto.Marshal(vgtid) + data, _ := vgtid.MarshalVT() val, _ := sqltypes.NewValue(sqltypes.VarBinary, data) result[aggr.Col] = val case AggregateRandom: @@ -575,7 +573,7 @@ func convertFinal(current []sqltypes.Value, aggregates []*AggregateParams) ([]sq if err != nil { return nil, err } - err = proto.Unmarshal(currentBytes, vgtid) + err = vgtid.UnmarshalVT(currentBytes) if err != nil { return nil, err } diff --git a/go/vt/vttablet/tabletserver/schema/historian.go b/go/vt/vttablet/tabletserver/schema/historian.go index 75f48dc0518..889536cab50 100644 --- a/go/vt/vttablet/tabletserver/schema/historian.go +++ b/go/vt/vttablet/tabletserver/schema/historian.go @@ -22,8 +22,6 @@ import ( "sort" "sync" - "google.golang.org/protobuf/proto" - "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/log" @@ -206,7 +204,7 @@ func (h *historian) readRow(row []sqltypes.Value) (*trackedSchema, int64, error) if err != nil { return nil, 0, err } - if err := proto.Unmarshal(rowBytes, sch); err != nil { + if err := sch.UnmarshalVT(rowBytes); err != nil { return nil, 0, err } log.V(vl).Infof("Read tracked schema from db: id %d, pos %v, ddl %s, schema len %d, time_updated %d \n", diff --git a/go/vt/vttablet/tabletserver/schema/historian_test.go b/go/vt/vttablet/tabletserver/schema/historian_test.go index c1a9a6416d4..8bdfa1c0d7f 100644 --- a/go/vt/vttablet/tabletserver/schema/historian_test.go +++ b/go/vt/vttablet/tabletserver/schema/historian_test.go @@ -21,7 +21,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" "vitess.io/vitess/go/sqltypes" binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" @@ -65,7 +64,7 @@ func getDbSchemaBlob(t *testing.T, tables map[string]*binlogdatapb.MinimalTable) t.PKColumns = pks dbSchema.Tables = append(dbSchema.Tables, t) } - blob, err := proto.Marshal(dbSchema) + blob, err := dbSchema.MarshalVT() require.NoError(t, err) return string(blob) } diff --git a/go/vt/vttablet/tabletserver/vstreamer/vstreamer_flaky_test.go b/go/vt/vttablet/tabletserver/vstreamer/vstreamer_flaky_test.go index c2a1a03c1c3..97556e3f70d 100644 --- a/go/vt/vttablet/tabletserver/vstreamer/vstreamer_flaky_test.go +++ b/go/vt/vttablet/tabletserver/vstreamer/vstreamer_flaky_test.go @@ -279,7 +279,7 @@ func TestVersion(t *testing.T) { Name: "t1", }}, } - blob, _ := proto.Marshal(dbSchema) + blob, _ := dbSchema.MarshalVT() engine.se.Reload(context.Background()) gtid := "MariaDB/0-41983-20" testcases := []testcase{{ diff --git a/go/vt/wrangler/testlib/vtctl_topo_test.go b/go/vt/wrangler/testlib/vtctl_topo_test.go index d3dd5d8cb21..bd3e4134d62 100644 --- a/go/vt/wrangler/testlib/vtctl_topo_test.go +++ b/go/vt/wrangler/testlib/vtctl_topo_test.go @@ -82,7 +82,7 @@ keyspace_type:SNAPSHOT } expected := &topodatapb.Keyspace{KeyspaceType: topodatapb.KeyspaceType_NORMAL} got := &topodatapb.Keyspace{} - if err = proto.Unmarshal(contents, got); err != nil { + if err = got.UnmarshalVT(contents); err != nil { t.Fatalf("bad keyspace data %v", err) } if !proto.Equal(got, expected) {