Skip to content

Commit

Permalink
proto: Faster clone (vitessio#13914)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Sep 6, 2023
1 parent dd561ee commit 3404baa
Show file tree
Hide file tree
Showing 72 changed files with 13,832 additions and 257 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ $(PROTO_GO_OUTS): minimaltools install_protoc-gen-go proto/*.proto
--go_out=. --plugin protoc-gen-go="${VTROOTBIN}/protoc-gen-go" \
--go-grpc_out=. --plugin protoc-gen-go-grpc="${VTROOTBIN}/protoc-gen-go-grpc" \
--go-vtproto_out=. --plugin protoc-gen-go-vtproto="${VTROOTBIN}/protoc-gen-go-vtproto" \
--go-vtproto_opt=features=marshal+unmarshal+size+pool \
--go-vtproto_opt=features=marshal+unmarshal+size+pool+clone \
--go-vtproto_opt=pool=vitess.io/vitess/go/vt/proto/query.Row \
--go-vtproto_opt=pool=vitess.io/vitess/go/vt/proto/binlogdata.VStreamRowsResponse \
-I${PWD}/dist/vt-protoc-21.3/include:proto $(PROTO_SRCS)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/pires/go-proxyproto v0.6.2
github.com/pkg/errors v0.9.1
github.com/planetscale/pargzip v0.0.0-20201116224723-90c7fc03ea8a
github.com/planetscale/vtprotobuf v0.4.0
github.com/planetscale/vtprotobuf v0.5.0
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/common v0.43.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/planetscale/pargzip v0.0.0-20201116224723-90c7fc03ea8a h1:y0OpQ4+5tKxeh9+H+2cVgASl9yMZYV9CILinKOiKafA=
github.com/planetscale/pargzip v0.0.0-20201116224723-90c7fc03ea8a/go.mod h1:GJFUzQuXIoB2Kjn1ZfDhJr/42D5nWOqRcIQVgCxTuIE=
github.com/planetscale/vtprotobuf v0.4.0 h1:NEI+g4woRaAZgeZ3sAvbtyvMBRjIv5kE7EWYQ8m4JwY=
github.com/planetscale/vtprotobuf v0.4.0/go.mod h1:wm1N3qk9G/4+VM1WhpkLbvY/d8+0PbwYYpP5P5VhTks=
github.com/planetscale/vtprotobuf v0.5.0 h1:l8PXm6Colok5z6qQLNhAj2Jq5BfoMTIHxLER5a6nDqM=
github.com/planetscale/vtprotobuf v0.5.0/go.mod h1:wm1N3qk9G/4+VM1WhpkLbvY/d8+0PbwYYpP5P5VhTks=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down
8 changes: 3 additions & 5 deletions go/cmd/vtcombo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import (
"time"

"github.com/spf13/pflag"
"google.golang.org/protobuf/proto"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -165,7 +163,7 @@ func main() {
//
// We will use this to determine the shard structure when keyspaces
// get recreated.
originalTopology := proto.Clone(&tpb).(*vttestpb.VTTestTopology)
originalTopology := (&tpb).CloneVT()

// default cell to "test" if unspecified
if len(tpb.Cells) == 0 {
Expand Down Expand Up @@ -240,7 +238,7 @@ func main() {
// will end up with the same number of shards.
for _, originalKs := range originalTopology.Keyspaces {
if originalKs.Name == ks.Name {
ks = proto.Clone(originalKs).(*vttestpb.Keyspace)
ks = originalKs.CloneVT()
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/sqltypes/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (result *Result) Copy() *Result {
if result.Fields != nil {
out.Fields = make([]*querypb.Field, len(result.Fields))
for i, f := range result.Fields {
out.Fields[i] = proto.Clone(f).(*querypb.Field)
out.Fields[i] = f.CloneVT()
}
}
if result.Rows != nil {
Expand Down
6 changes: 3 additions & 3 deletions go/vt/discovery/fake_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ func (fhc *FakeHealthCheck) BroadcastAll() {
func simpleCopy(th *TabletHealth) *TabletHealth {
return &TabletHealth{
Conn: th.Conn,
Tablet: proto.Clone(th.Tablet).(*topodatapb.Tablet),
Target: proto.Clone(th.Target).(*querypb.Target),
Stats: proto.Clone(th.Stats).(*querypb.RealtimeStats),
Tablet: th.Tablet.CloneVT(),
Target: th.Target.CloneVT(),
Stats: th.Stats.CloneVT(),
LastError: th.LastError,
PrimaryTermStartTime: th.PrimaryTermStartTime,
Serving: th.Serving,
Expand Down
9 changes: 4 additions & 5 deletions go/vt/discovery/topology_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func checkWatcher(t *testing.T, refreshKnownTablets bool) {
// if refreshKnownTablets is disabled, this case is *not*
// detected and the tablet remains in the topo using the
// old key
origTablet := proto.Clone(tablet).(*topodatapb.Tablet)
origTablet := tablet.CloneVT()
origKey := TabletToMapKey(tablet)
tablet.PortMap["vt"] = 456
if _, err := ts.UpdateTabletFields(context.Background(), tablet.Alias, func(t *topodatapb.Tablet) error {
Expand Down Expand Up @@ -246,9 +246,8 @@ func checkWatcher(t *testing.T, refreshKnownTablets bool) {
// tablet2 happens to land on the host:port that tablet 1 used to be on.
// This can only be tested when we refresh known tablets.
if refreshKnownTablets {
origTablet := proto.Clone(tablet).(*topodatapb.Tablet)
origTablet2 := proto.Clone(tablet2).(*topodatapb.Tablet)

origTablet := tablet.CloneVT()
origTablet2 := tablet2.CloneVT()
if _, err := ts.UpdateTabletFields(context.Background(), tablet2.Alias, func(t *topodatapb.Tablet) error {
t.Hostname = tablet.Hostname
t.PortMap = tablet.PortMap
Expand Down Expand Up @@ -607,7 +606,7 @@ func TestFilterByKeypsaceSkipsIgnoredTablets(t *testing.T) {
allTablets = fhc.GetAllTablets()
assert.Len(t, allTablets, 1)
origKey := TabletToMapKey(tablet)
tabletWithNewPort := proto.Clone(tablet).(*topodatapb.Tablet)
tabletWithNewPort := tablet.CloneVT()
tabletWithNewPort.PortMap["vt"] = 456
keyWithNewPort := TabletToMapKey(tabletWithNewPort)
assert.Contains(t, allTablets, origKey)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/tmutils/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (f *TableFilter) Includes(tableName string, tableType string) bool {
// (tables), no denied tables (excludeTables) and optionally
// views (includeViews).
func FilterTables(sd *tabletmanagerdatapb.SchemaDefinition, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error) {
copy := proto.Clone(sd).(*tabletmanagerdatapb.SchemaDefinition)
copy := sd.CloneVT()
copy.TableDefinitions = make([]*tabletmanagerdatapb.TableDefinition, 0, len(sd.TableDefinitions))

f, err := NewTableFilter(tables, excludeTables, includeViews)
Expand Down
Loading

0 comments on commit 3404baa

Please sign in to comment.