From e9319d3fc99f2a02912074697f926860379421dd Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Sun, 5 Jan 2025 13:36:45 -0500 Subject: [PATCH] Fix unit tests Signed-off-by: Matt Lord --- go/test/utils/diff.go | 2 +- go/vt/topo/test/vschema.go | 16 +- go/vt/topo/topotests/srv_vschema_test.go | 16 +- go/vt/topo/vschema.go | 23 +- go/vt/vtctl/grpcvtctldserver/server.go | 33 +- go/vt/vtctl/grpcvtctldserver/server_test.go | 100 +++-- go/vt/vtctl/workflow/lookup_vindex.go | 8 +- go/vt/vtctl/workflow/materializer_env_test.go | 4 +- go/vt/vtctl/workflow/materializer_test.go | 160 ++++--- go/vt/vtctl/workflow/resharder_test.go | 18 +- go/vt/vtctl/workflow/server.go | 10 +- go/vt/vtctl/workflow/server_test.go | 39 +- go/vt/vtctl/workflow/traffic_switcher_test.go | 21 +- go/vt/vtctld/api_test.go | 6 +- .../executorcontext/vcursor_impl_test.go | 4 +- .../tabletmanager/rpc_vreplication_test.go | 403 ++++++++++-------- .../tabletserver/vstreamer/testenv/testenv.go | 6 +- go/vt/wrangler/materializer_test.go | 136 ++++-- go/vt/wrangler/resharder_test.go | 41 +- go/vt/wrangler/traffic_switcher_env_test.go | 35 +- go/vt/wrangler/traffic_switcher_test.go | 7 +- 21 files changed, 709 insertions(+), 379 deletions(-) diff --git a/go/test/utils/diff.go b/go/test/utils/diff.go index 014d4760d87..2344c027c39 100644 --- a/go/test/utils/diff.go +++ b/go/test/utils/diff.go @@ -68,7 +68,7 @@ func MustMatchFn(ignoredFields ...string) func(t *testing.T, want, got any, errM t.Helper() diff := cmp.Diff(want, got, diffOpts...) if diff != "" { - t.Fatalf("%v: (-want +got)\n%v", errMsg, diff) + require.FailNow(t, "%v: (-want +got)\n%v", errMsg, diff) } } } diff --git a/go/vt/topo/test/vschema.go b/go/vt/topo/test/vschema.go index 5063addaefd..384e777ac38 100644 --- a/go/vt/topo/test/vschema.go +++ b/go/vt/topo/test/vschema.go @@ -44,9 +44,12 @@ func checkVSchema(t *testing.T, ctx context.Context, ts *topo.Server) { t.Error(err) } - err = ts.SaveVSchema(ctx, "test_keyspace", &vschemapb.Keyspace{ - Tables: map[string]*vschemapb.Table{ - "unsharded": {}, + err = ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "test_keyspace", + Keyspace: &vschemapb.Keyspace{ + Tables: map[string]*vschemapb.Table{ + "unsharded": {}, + }, }, }) if err != nil { @@ -64,8 +67,11 @@ func checkVSchema(t *testing.T, ctx context.Context, ts *topo.Server) { t.Errorf("GetVSchema: %s, want %s", got, want) } - err = ts.SaveVSchema(ctx, "test_keyspace", &vschemapb.Keyspace{ - Sharded: true, + err = ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "test_keyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + }, }) require.NoError(t, err) diff --git a/go/vt/topo/topotests/srv_vschema_test.go b/go/vt/topo/topotests/srv_vschema_test.go index 8fd818150b0..fda3582527a 100644 --- a/go/vt/topo/topotests/srv_vschema_test.go +++ b/go/vt/topo/topotests/srv_vschema_test.go @@ -21,6 +21,7 @@ import ( "google.golang.org/protobuf/proto" + "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -76,7 +77,10 @@ func TestRebuildVSchema(t *testing.T) { keyspace1 := &vschemapb.Keyspace{ Sharded: true, } - if err := ts.SaveVSchema(ctx, "ks1", keyspace1); err != nil { + if err := ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks1", + Keyspace: keyspace1, + }); err != nil { t.Fatalf("SaveVSchema(ks1) failed: %v", err) } if err := ts.RebuildSrvVSchema(ctx, cells); err != nil { @@ -118,7 +122,10 @@ func TestRebuildVSchema(t *testing.T) { }, }, } - if err := ts.SaveVSchema(ctx, "ks2", keyspace2); err != nil { + if err := ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks2", + Keyspace: keyspace2, + }); err != nil { t.Fatalf("SaveVSchema(ks1) failed: %v", err) } if err := ts.RebuildSrvVSchema(ctx, []string{"cell1"}); err != nil { @@ -182,7 +189,10 @@ func TestRebuildVSchema(t *testing.T) { wanted4.RoutingRules = rr // Delete a keyspace, checks vschema entry in map goes away. - if err := ts.SaveVSchema(ctx, "ks2", &vschemapb.Keyspace{}); err != nil { + if err := ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks2", + Keyspace: &vschemapb.Keyspace{}, + }); err != nil { t.Fatalf("SaveVSchema(ks1) failed: %v", err) } if err := ts.DeleteKeyspace(ctx, "ks2"); err != nil { diff --git a/go/vt/topo/vschema.go b/go/vt/topo/vschema.go index e9e679ffeb9..c68688ee711 100644 --- a/go/vt/topo/vschema.go +++ b/go/vt/topo/vschema.go @@ -20,8 +20,6 @@ import ( "context" "path" - "google.golang.org/protobuf/proto" - "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/vterrors" @@ -39,11 +37,17 @@ type KeyspaceVSchemaInfo struct { } func (k *KeyspaceVSchemaInfo) CloneVT() *KeyspaceVSchemaInfo { - return &KeyspaceVSchemaInfo{ - Name: k.Name, - Keyspace: k.Keyspace.CloneVT(), - version: Version(k.version), + if k == nil { + return (*KeyspaceVSchemaInfo)(nil) + } + kc := &KeyspaceVSchemaInfo{ + Name: k.Name, + version: Version(k.version), } + if k.Keyspace != nil { + kc.Keyspace = k.Keyspace.CloneVT() + } + return kc } // SaveVSchema saves a Vschema. A valid Vschema should be passed in. It does not verify its correctness. @@ -91,14 +95,15 @@ func (ts *Server) GetVSchema(ctx context.Context, keyspace string) (*KeyspaceVSc if err != nil { return nil, err } - var vs vschemapb.Keyspace - err = proto.Unmarshal(data, &vs) + + vs := &vschemapb.Keyspace{} + err = vs.UnmarshalVT(data) if err != nil { return nil, vterrors.Wrapf(err, "bad vschema data: %q", data) } return &KeyspaceVSchemaInfo{ Name: keyspace, - Keyspace: &vs, + Keyspace: vs, version: version, }, nil } diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index f0c8337b5dc..1a802b79eed 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -937,34 +937,37 @@ func (s *VtctldServer) CreateKeyspace(ctx context.Context, req *vtctldatapb.Crea } if req.Type == topodatapb.KeyspaceType_SNAPSHOT { - // Copy vschema from the base keyspace. bksvs, err := s.ts.GetVSchema(ctx, req.BaseKeyspace) - ksvs := &topo.KeyspaceVSchemaInfo{ - Name: req.Name, - } if err != nil { log.Infof("error from GetVSchema(%v) = %v", req.BaseKeyspace, err) if topo.IsErrType(err, topo.NoNode) { log.Infof("base keyspace %v does not exist; continuing with bare, unsharded vschema", req.BaseKeyspace) - // Create an empty vschema for the keyspace. - ksvs.Keyspace = &vschemapb.Keyspace{ - Sharded: false, - Tables: map[string]*vschemapb.Table{}, - Vindexes: map[string]*vschemapb.Vindex{}, + bksvs = &topo.KeyspaceVSchemaInfo{ + Name: req.Name, + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + Tables: map[string]*vschemapb.Table{}, + Vindexes: map[string]*vschemapb.Vindex{}, + }, } } else { return nil, err } } - // Copy the vschema from the base keyspace to the new one. - ksvs.Keyspace = bksvs.Keyspace.CloneVT() + // We don't want to clone the base keyspace's key version + // so we do NOT call bksvs.CloneVT() here. We instead only + // clone the vschemapb.Keyspace field for the new snapshot + // keyspace. + sksvs := &topo.KeyspaceVSchemaInfo{ + Name: req.Name, + Keyspace: bksvs.Keyspace.CloneVT(), + } // SNAPSHOT keyspaces are excluded from global routing. - ksvs.RequireExplicitRouting = true + sksvs.RequireExplicitRouting = true - if err = s.ts.SaveVSchema(ctx, ksvs); err != nil { - err = fmt.Errorf("SaveVSchema(%v) = %w", ksvs, err) - return nil, err + if err = s.ts.SaveVSchema(ctx, sksvs); err != nil { + return nil, fmt.Errorf("SaveVSchema(%v) = %w", sksvs, err) } } diff --git a/go/vt/vtctl/grpcvtctldserver/server_test.go b/go/vt/vtctl/grpcvtctldserver/server_test.go index 31220918211..252efc7d894 100644 --- a/go/vt/vtctl/grpcvtctldserver/server_test.go +++ b/go/vt/vtctl/grpcvtctldserver/server_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "google.golang.org/protobuf/proto" + _flag "vitess.io/vitess/go/internal/flag" "vitess.io/vitess/go/vt/vtctl/reparentutil" "vitess.io/vitess/go/vt/vtctl/reparentutil/policy" @@ -608,15 +610,18 @@ func TestApplyVSchema(t *testing.T) { }, }) - origVSchema := &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "v1": { - Type: "hash", + origVSchema := &topo.KeyspaceVSchemaInfo{ + Name: tt.req.Keyspace, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "v1": { + Type: "hash", + }, }, }, } - err := ts.SaveVSchema(ctx, tt.req.Keyspace, origVSchema) + err := ts.SaveVSchema(ctx, origVSchema) require.NoError(t, err) origSrvVSchema := &vschemapb.SrvVSchema{ @@ -2577,12 +2582,12 @@ func TestCreateKeyspace(t *testing.T) { tests := []struct { name string topo map[string]*topodatapb.Keyspace - vschemas map[string]*vschemapb.Keyspace + vschemas map[string]*topo.KeyspaceVSchemaInfo req *vtctldatapb.CreateKeyspaceRequest expected *vtctldatapb.CreateKeyspaceResponse shouldErr bool vschemaShouldExist bool - expectedVSchema *vschemapb.Keyspace + expectedVSchema *topo.KeyspaceVSchemaInfo }{ { name: "normal keyspace", @@ -2600,8 +2605,11 @@ func TestCreateKeyspace(t *testing.T) { }, }, vschemaShouldExist: true, - expectedVSchema: &vschemapb.Keyspace{ - Sharded: false, + expectedVSchema: &topo.KeyspaceVSchemaInfo{ + Name: "testkeyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + }, }, shouldErr: false, }, @@ -2612,12 +2620,15 @@ func TestCreateKeyspace(t *testing.T) { KeyspaceType: topodatapb.KeyspaceType_NORMAL, }, }, - vschemas: map[string]*vschemapb.Keyspace{ + vschemas: map[string]*topo.KeyspaceVSchemaInfo{ "testkeyspace": { - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "h1": { - Type: "hash", + Name: "testkeyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "h1": { + Type: "hash", + }, }, }, }, @@ -2643,14 +2654,17 @@ func TestCreateKeyspace(t *testing.T) { }, }, vschemaShouldExist: true, - expectedVSchema: &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "h1": { - Type: "hash", + expectedVSchema: &topo.KeyspaceVSchemaInfo{ + Name: "testkeyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "h1": { + Type: "hash", + }, }, + RequireExplicitRouting: true, }, - RequireExplicitRouting: true, }, shouldErr: false, }, @@ -2696,9 +2710,12 @@ func TestCreateKeyspace(t *testing.T) { }, }, vschemaShouldExist: true, - expectedVSchema: &vschemapb.Keyspace{ - Sharded: false, - RequireExplicitRouting: true, + expectedVSchema: &topo.KeyspaceVSchemaInfo{ + Name: "testsnapshot", + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + RequireExplicitRouting: true, + }, }, shouldErr: false, }, @@ -2748,8 +2765,11 @@ func TestCreateKeyspace(t *testing.T) { }, }, vschemaShouldExist: true, - expectedVSchema: &vschemapb.Keyspace{ - Sharded: false, + expectedVSchema: &topo.KeyspaceVSchemaInfo{ + Name: "testkeyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + }, }, shouldErr: false, }, @@ -2772,7 +2792,8 @@ func TestCreateKeyspace(t *testing.T) { vschemaShouldExist: false, expectedVSchema: nil, shouldErr: false, - }, { + }, + { name: "keyspace with durability policy specified", topo: nil, req: &vtctldatapb.CreateKeyspaceRequest{ @@ -2790,8 +2811,11 @@ func TestCreateKeyspace(t *testing.T) { }, }, vschemaShouldExist: true, - expectedVSchema: &vschemapb.Keyspace{ - Sharded: false, + expectedVSchema: &topo.KeyspaceVSchemaInfo{ + Name: "testkeyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + }, }, shouldErr: false, }, @@ -2820,7 +2844,7 @@ func TestCreateKeyspace(t *testing.T) { } for name, vs := range tt.vschemas { - require.NoError(t, ts.SaveVSchema(ctx, name, vs), "error in SaveVSchema(%v, %+v)", name, vs) + require.NoError(t, ts.SaveVSchema(ctx, vs), "error in SaveVSchema(%v, %+v)", name, vs) } // Create the keyspace and make some assertions @@ -2829,7 +2853,6 @@ func TestCreateKeyspace(t *testing.T) { assert.Error(t, err) return } - assert.NoError(t, err) testutil.AssertKeyspacesEqual(t, tt.expected.Keyspace, resp.Keyspace, "%+v\n%+v\n", tt.expected.Keyspace, resp.Keyspace) @@ -2858,7 +2881,7 @@ func TestCreateKeyspace(t *testing.T) { return } assert.NoError(t, err) - utils.MustMatch(t, tt.expectedVSchema, vs) + require.True(t, proto.Equal(tt.expectedVSchema, vs), "expected vschema for %s: %+v, got: %+v", tt.req.Name, tt.expectedVSchema, vs) }) } } @@ -8382,11 +8405,14 @@ func TestGetVSchema(t *testing.T) { }) t.Run("found", func(t *testing.T) { - err := ts.SaveVSchema(ctx, "testkeyspace", &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "v1": { - Type: "hash", + err := ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "testkeyspace", + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "v1": { + Type: "hash", + }, }, }, }) diff --git a/go/vt/vtctl/workflow/lookup_vindex.go b/go/vt/vtctl/workflow/lookup_vindex.go index 15204b57a37..8a453380725 100644 --- a/go/vt/vtctl/workflow/lookup_vindex.go +++ b/go/vt/vtctl/workflow/lookup_vindex.go @@ -144,8 +144,12 @@ func (lv *lookupVindex) prepareCreate(ctx context.Context, workflow, keyspace st materializeQuery = generateMaterializeQuery(vInfo, vindex, sourceVindexColumns) // Save a copy of the original vschema if we modify it and need to provide - // a cancelFunc. - origTargetVSchema := targetVSchema.CloneVT() + // a cancelFunc. We do NOT want to clone the key version as we explicitly + // want to go back in time. So we only clone the internal vschema.Keyspace. + origTargetVSchema := &topo.KeyspaceVSchemaInfo{ + Name: vInfo.targetKeyspace, + Keyspace: targetVSchema.Keyspace.CloneVT(), + } targetChanged := false // Update targetVSchema. diff --git a/go/vt/vtctl/workflow/materializer_env_test.go b/go/vt/vtctl/workflow/materializer_env_test.go index fb5064137cd..c7c66f4fd29 100644 --- a/go/vt/vtctl/workflow/materializer_env_test.go +++ b/go/vt/vtctl/workflow/materializer_env_test.go @@ -86,10 +86,10 @@ func newTestMaterializerEnv(t *testing.T, ctx context.Context, ms *vtctldatapb.M } require.NoError(t, topoServ.CreateKeyspace(ctx, ms.SourceKeyspace, &topodatapb.Keyspace{})) - require.NoError(t, topoServ.SaveVSchema(ctx, ms.SourceKeyspace, &vschemapb.Keyspace{})) + require.NoError(t, topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{Name: ms.SourceKeyspace, Keyspace: &vschemapb.Keyspace{}})) if ms.SourceKeyspace != ms.TargetKeyspace { require.NoError(t, topoServ.CreateKeyspace(ctx, ms.TargetKeyspace, &topodatapb.Keyspace{})) - require.NoError(t, topoServ.SaveVSchema(ctx, ms.TargetKeyspace, &vschemapb.Keyspace{})) + require.NoError(t, topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{Name: ms.TargetKeyspace, Keyspace: &vschemapb.Keyspace{}})) } logger := logutil.NewConsoleLogger() require.NoError(t, topoServ.RebuildSrvVSchema(ctx, []string{"cell"})) diff --git a/go/vt/vtctl/workflow/materializer_test.go b/go/vt/vtctl/workflow/materializer_test.go index e430f740c1f..c28beb933e8 100644 --- a/go/vt/vtctl/workflow/materializer_test.go +++ b/go/vt/vtctl/workflow/materializer_test.go @@ -497,7 +497,10 @@ func TestAddTablesToVSchema(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := ts.SaveVSchema(ctx, srcks, tt.sourceVSchema) + err := ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: srcks, + Keyspace: tt.sourceVSchema, + }) require.NoError(t, err) err = ws.addTablesToVSchema(ctx, srcks, tt.inTargetVSchema, tt.tables, tt.copyVSchema) require.NoError(t, err) @@ -910,7 +913,10 @@ func TestShardedAutoIncHandling(t *testing.T) { } if tc.targetVSchema != nil { - err := env.ws.ts.SaveVSchema(ctx, ms.TargetKeyspace, tc.targetVSchema) + err := env.ws.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: tc.targetVSchema, + }) require.NoError(t, err) } @@ -1076,10 +1082,16 @@ func TestCreateLookupVindexFull(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, &vschemapb.Keyspace{}); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: &vschemapb.Keyspace{}, + }); err != nil { t.Fatal(err) } - if err := env.topoServ.SaveVSchema(ctx, ms.SourceKeyspace, sourceVSchema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: sourceVSchema, + }); err != nil { t.Fatal(err) } @@ -1133,7 +1145,7 @@ func TestCreateLookupVindexFull(t *testing.T) { } vschema, err := env.topoServ.GetVSchema(ctx, ms.SourceKeyspace) require.NoError(t, err) - utils.MustMatch(t, wantvschema, vschema) + utils.MustMatch(t, wantvschema, vschema.Keyspace) wantvschema = &vschemapb.Keyspace{ Tables: map[string]*vschemapb.Table{ @@ -1142,7 +1154,7 @@ func TestCreateLookupVindexFull(t *testing.T) { } vschema, err = env.topoServ.GetVSchema(ctx, ms.TargetKeyspace) require.NoError(t, err) - utils.MustMatch(t, wantvschema, vschema) + utils.MustMatch(t, wantvschema, vschema.Keyspace) } func TestCreateLookupVindexCreateDDL(t *testing.T) { @@ -1172,7 +1184,10 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) { }, } setStartingVschema := func() { - err := env.topoServ.SaveVSchema(ctx, ms.SourceKeyspace, vs) + err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vs, + }) require.NoError(t, err) } setStartingVschema() @@ -1209,25 +1224,28 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) { }, preFunc: func() { // The vschema entries will already exist and we will re-use them. - err := env.ws.ts.SaveVSchema(ctx, ms.SourceKeyspace, &vschemapb.Keyspace{ - Vindexes: map[string]*vschemapb.Vindex{ - "v": { - Type: "lookup_unique", - Params: map[string]string{ - "table": fmt.Sprintf("%s.lkp", ms.TargetKeyspace), - "from": "c1", - "to": "c2", - "write_only": "true", // It has not been externalized yet + err := env.ws.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: &vschemapb.Keyspace{ + Vindexes: map[string]*vschemapb.Vindex{ + "v": { + Type: "lookup_unique", + Params: map[string]string{ + "table": fmt.Sprintf("%s.lkp", ms.TargetKeyspace), + "from": "c1", + "to": "c2", + "write_only": "true", // It has not been externalized yet + }, + Owner: "t1", }, - Owner: "t1", }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Name: "v", - Column: "col2", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Name: "v", + Column: "col2", + }}, + }, }, }, }) @@ -1270,17 +1288,20 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) { preFunc: func() { // The existing vindex vschema entry differs from what we want to // create so we cannot re-use it. - err := env.ws.ts.SaveVSchema(ctx, ms.SourceKeyspace, &vschemapb.Keyspace{ - Vindexes: map[string]*vschemapb.Vindex{ - "v": { - Type: "lookup_unique", - Params: map[string]string{ - "table": fmt.Sprintf("%s.lkp", ms.TargetKeyspace), - "from": "c1", - "to": "c2", - "write_only": "false", // This vindex has been externalized + err := env.ws.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: &vschemapb.Keyspace{ + Vindexes: map[string]*vschemapb.Vindex{ + "v": { + Type: "lookup_unique", + Params: map[string]string{ + "table": fmt.Sprintf("%s.lkp", ms.TargetKeyspace), + "from": "c1", + "to": "c2", + "write_only": "false", // This vindex has been externalized + }, + Owner: "t1", }, - Owner: "t1", }, }, }) @@ -1319,13 +1340,16 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) { preFunc: func() { // The existing ColumnVindexes vschema entry differs from what we // want to create so we cannot re-use it. - err := env.ws.ts.SaveVSchema(ctx, ms.SourceKeyspace, &vschemapb.Keyspace{ - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Name: "v", - Columns: []string{"col1", "col2"}, - }}, + err := env.ws.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: &vschemapb.Keyspace{ + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Name: "v", + Columns: []string{"col1", "col2"}, + }}, + }, }, }, }) @@ -1757,10 +1781,16 @@ func TestCreateLookupVindexSourceVSchema(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, &vschemapb.Keyspace{}); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: &vschemapb.Keyspace{}, + }); err != nil { t.Fatal(err) } - if err := env.topoServ.SaveVSchema(ctx, ms.SourceKeyspace, tcase.sourceVSchema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: tcase.sourceVSchema, + }); err != nil { t.Fatal(err) } @@ -1799,7 +1829,10 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { }, }, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, sourcevs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: sourcevs, + }); err != nil { t.Fatal(err) } @@ -1997,7 +2030,10 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { }}, } specs.Vindexes["v"].Params["table"] = fmt.Sprintf("%s.%s", ms.TargetKeyspace, tcase.targetTable) - if err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, tcase.targetVSchema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: tcase.targetVSchema, + }); err != nil { t.Fatal(err) } @@ -2013,7 +2049,7 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { // withTable is a vschema that already contains the table and thus // we don't make any vschema changes and there's nothing to cancel. require.True(t, (cancelFunc != nil) == (tcase.targetVSchema != withTable)) - utils.MustMatch(t, tcase.out, got, tcase.description) + utils.MustMatch(t, tcase.out, got.Keyspace, tcase.description) }) } } @@ -2120,7 +2156,10 @@ func TestCreateLookupVindexSameKeyspace(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -2247,7 +2286,10 @@ func TestCreateCustomizedVindex(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -2366,7 +2408,10 @@ func TestCreateLookupVindexIgnoreNulls(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -2447,7 +2492,10 @@ func TestStopAfterCopyFlag(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(ctx, ms.SourceKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -2529,7 +2577,10 @@ func TestCreateLookupVindexFailures(t *testing.T) { }, }, } - err := env.topoServ.SaveVSchema(ctx, ms.TargetKeyspace, vs) + err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: vs, + }) require.NoError(t, err) testcases := []struct { @@ -2868,7 +2919,7 @@ func TestCreateLookupVindexFailures(t *testing.T) { // definition. cvs, err := env.ws.ts.GetVSchema(ctx, ms.TargetKeyspace) require.NoError(t, err) - require.True(t, proto.Equal(vs, cvs), "expected: %+v, got: %+v", vs, cvs) + require.True(t, proto.Equal(vs, cvs.Keyspace), "expected: %+v, got: %+v", vs, cvs) }) } } @@ -3130,7 +3181,10 @@ func TestKeyRangesEqualOptimization(t *testing.T) { defer env.close() // Target is always sharded. - err := env.ws.ts.SaveVSchema(ctx, targetKs, targetVSchema) + err := env.ws.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: targetVSchema, + }) require.NoError(t, err, "SaveVSchema failed: %v", err) for _, tablet := range env.tablets { diff --git a/go/vt/vtctl/workflow/resharder_test.go b/go/vt/vtctl/workflow/resharder_test.go index 6fe1afb0c70..2840030e7e0 100644 --- a/go/vt/vtctl/workflow/resharder_test.go +++ b/go/vt/vtctl/workflow/resharder_test.go @@ -369,10 +369,13 @@ func TestReadRefStreams(t *testing.T) { }, }, workflow: "wf", - vschema: &vschemapb.Keyspace{ - Tables: map[string]*vschemapb.Table{ - "t1": { - Type: vindexes.TypeReference, + vschema: &topo.KeyspaceVSchemaInfo{ + Name: targetKeyspace.KeyspaceName, + Keyspace: &vschemapb.Keyspace{ + Tables: map[string]*vschemapb.Table{ + "t1": { + Type: vindexes.TypeReference, + }, }, }, }, @@ -485,8 +488,11 @@ func TestBlsIsReference(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { rs := &resharder{ - vschema: &vschemapb.Keyspace{ - Tables: tc.tables, + vschema: &topo.KeyspaceVSchemaInfo{ + Name: "ks", + Keyspace: &vschemapb.Keyspace{ + Tables: tc.tables, + }, }, } diff --git a/go/vt/vtctl/workflow/server.go b/go/vt/vtctl/workflow/server.go index e63e510e0d1..fac2373aedd 100644 --- a/go/vt/vtctl/workflow/server.go +++ b/go/vt/vtctl/workflow/server.go @@ -806,7 +806,9 @@ func (s *Server) moveTablesCreate(ctx context.Context, req *vtctldatapb.MoveTabl s.Logger().Infof("Successfully opened external topo: %+v", externalTopo) } - var origVSchema *topo.KeyspaceVSchemaInfo // If we need to rollback a failed create + origVSchema := &topo.KeyspaceVSchemaInfo{ // If we need to rollback a failed create + Name: targetKeyspace, + } vschema, err := s.ts.GetVSchema(ctx, targetKeyspace) if err != nil { return nil, err @@ -863,8 +865,10 @@ func (s *Server) moveTablesCreate(ctx context.Context, req *vtctldatapb.MoveTabl if !vschema.Sharded { // Save the original in case we need to restore it for a late failure in - // the defer(). - origVSchema = vschema.CloneVT() + // the defer(). We do NOT want to clone the version field as we will + // intentionally be going back in time. So we only clone the internal + // vschemapb.Keyspace field. + origVSchema.Keyspace = vschema.Keyspace.CloneVT() if err := s.addTablesToVSchema(ctx, sourceKeyspace, vschema.Keyspace, tables, externalTopo == nil); err != nil { return nil, err } diff --git a/go/vt/vtctl/workflow/server_test.go b/go/vt/vtctl/workflow/server_test.go index 26d722f1de0..15c20197ee8 100644 --- a/go/vt/vtctl/workflow/server_test.go +++ b/go/vt/vtctl/workflow/server_test.go @@ -994,11 +994,14 @@ func TestWorkflowDelete(t *testing.T) { }, }, preFunc: func(t *testing.T, env *testEnv) { - err := env.ts.SaveVSchema(ctx, targetKeyspaceName, &vschemapb.Keyspace{ - Sharded: true, - MultiTenantSpec: &vschemapb.MultiTenantSpec{ - TenantIdColumnName: "tenant_id", - TenantIdColumnType: sqltypes.Int64, + err := env.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKeyspaceName, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + MultiTenantSpec: &vschemapb.MultiTenantSpec{ + TenantIdColumnName: "tenant_id", + TenantIdColumnType: sqltypes.Int64, + }, }, }) require.NoError(t, err) @@ -1104,11 +1107,14 @@ func TestWorkflowDelete(t *testing.T) { }, }, preFunc: func(t *testing.T, env *testEnv) { - err := env.ts.SaveVSchema(ctx, targetKeyspaceName, &vschemapb.Keyspace{ - Sharded: true, - MultiTenantSpec: &vschemapb.MultiTenantSpec{ - TenantIdColumnName: "tenant_id", - TenantIdColumnType: sqltypes.Int64, + err := env.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKeyspaceName, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + MultiTenantSpec: &vschemapb.MultiTenantSpec{ + TenantIdColumnName: "tenant_id", + TenantIdColumnType: sqltypes.Int64, + }, }, }) require.NoError(t, err) @@ -1164,11 +1170,14 @@ func TestWorkflowDelete(t *testing.T) { }, }, preFunc: func(t *testing.T, env *testEnv) { - err := env.ts.SaveVSchema(ctx, targetKeyspaceName, &vschemapb.Keyspace{ - Sharded: true, - MultiTenantSpec: &vschemapb.MultiTenantSpec{ - TenantIdColumnName: "tenant_id", - TenantIdColumnType: sqltypes.Int64, + err := env.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKeyspaceName, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + MultiTenantSpec: &vschemapb.MultiTenantSpec{ + TenantIdColumnName: "tenant_id", + TenantIdColumnType: sqltypes.Int64, + }, }, }) require.NoError(t, err) diff --git a/go/vt/vtctl/workflow/traffic_switcher_test.go b/go/vt/vtctl/workflow/traffic_switcher_test.go index b06c95b6c16..2cf998eb8e4 100644 --- a/go/vt/vtctl/workflow/traffic_switcher_test.go +++ b/go/vt/vtctl/workflow/traffic_switcher_test.go @@ -534,9 +534,15 @@ func TestGetTargetSequenceMetadata(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - err := env.ts.SaveVSchema(ctx, sourceKeyspace.KeyspaceName, tc.sourceVSchema) + err := env.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: sourceKeyspace.KeyspaceName, + Keyspace: tc.sourceVSchema, + }) require.NoError(t, err) - err = env.ts.SaveVSchema(ctx, targetKeyspace.KeyspaceName, tc.targetVSchema) + err = env.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKeyspace.KeyspaceName, + Keyspace: tc.targetVSchema, + }) require.NoError(t, err) err = env.ts.RebuildSrvVSchema(ctx, nil) require.NoError(t, err) @@ -750,10 +756,13 @@ func TestAddTenantFilter(t *testing.T) { defer env.close() env.tmc.schema = schema - err := env.ts.SaveVSchema(ctx, targetKeyspaceName, &vschema.Keyspace{ - MultiTenantSpec: &vschema.MultiTenantSpec{ - TenantIdColumnName: "tenant_id", - TenantIdColumnType: sqltypes.Int64, + err := env.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKeyspaceName, + Keyspace: &vschema.Keyspace{ + MultiTenantSpec: &vschema.MultiTenantSpec{ + TenantIdColumnName: "tenant_id", + TenantIdColumnType: sqltypes.Int64, + }, }, }) require.NoError(t, err) diff --git a/go/vt/vtctld/api_test.go b/go/vt/vtctld/api_test.go index 4166ca3293b..2809c37540d 100644 --- a/go/vt/vtctld/api_test.go +++ b/go/vt/vtctld/api_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/require" "vitess.io/vitess/go/vt/servenv/testutils" + "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" "vitess.io/vitess/go/vt/vtctl/reparentutil/policy" "vitess.io/vitess/go/vt/vtenv" @@ -82,7 +83,10 @@ func TestAPI(t *testing.T) { }, }, } - ts.SaveVSchema(ctx, "ks1", vs) + ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks1", + Keyspace: vs, + }) tablet1 := topodatapb.Tablet{ Alias: &topodatapb.TabletAlias{Cell: "cell1", Uid: 100}, diff --git a/go/vt/vtgate/executorcontext/vcursor_impl_test.go b/go/vt/vtgate/executorcontext/vcursor_impl_test.go index 08e27be4c51..37f574f190c 100644 --- a/go/vt/vtgate/executorcontext/vcursor_impl_test.go +++ b/go/vt/vtgate/executorcontext/vcursor_impl_test.go @@ -30,6 +30,8 @@ import ( "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/sqltypes" binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" + "vitess.io/vitess/go/vt/proto/vschema" + "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/vtenv" "vitess.io/vitess/go/vt/vtgate/engine" "vitess.io/vitess/go/vt/vtgate/vtgateservice" @@ -56,7 +58,7 @@ func (f fakeVSchemaOperator) GetCurrentSrvVschema() *vschemapb.SrvVSchema { panic("implement me") } -func (f fakeVSchemaOperator) UpdateVSchema(ctx context.Context, ksName string, vschema *vschemapb.SrvVSchema) error { +func (f fakeVSchemaOperator) UpdateVSchema(ctx context.Context, ksvs *topo.KeyspaceVSchemaInfo, srvvs *vschema.SrvVSchema) error { panic("implement me") } diff --git a/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go b/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go index 762b384a5f6..53e9d4564a4 100644 --- a/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go +++ b/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go @@ -336,31 +336,37 @@ func TestMoveTablesUnsharded(t *testing.T) { globalTablet := tenv.addTablet(t, 500, globalKs, globalShard) defer tenv.deleteTablet(globalTablet.tablet) - err := tenv.ts.SaveVSchema(ctx, globalKs, &vschemapb.Keyspace{ - Sharded: false, - Tables: map[string]*vschemapb.Table{ - "t1_seq": { - Type: vindexes.TypeSequence, + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: globalKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + Tables: map[string]*vschemapb.Table{ + "t1_seq": { + Type: vindexes.TypeSequence, + }, }, }, }) require.NoError(t, err) - err = tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "hash": { - Type: "hash", + err = tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "hash": { + Type: "hash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "id", - Name: "hash", - }}, - AutoIncrement: &vschemapb.AutoIncrement{ - Column: "id", - Sequence: "t1_seq", + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "id", + Name: "hash", + }}, + AutoIncrement: &vschemapb.AutoIncrement{ + Column: "id", + Sequence: "t1_seq", + }, }, }, }, @@ -599,31 +605,37 @@ func TestMoveTablesSharded(t *testing.T) { globalTablet := tenv.addTablet(t, 500, globalKs, globalShard) defer tenv.deleteTablet(globalTablet.tablet) - err := tenv.ts.SaveVSchema(ctx, globalKs, &vschemapb.Keyspace{ - Sharded: false, - Tables: map[string]*vschemapb.Table{ - "t1_seq": { - Type: vindexes.TypeSequence, + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: globalKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: false, + Tables: map[string]*vschemapb.Table{ + "t1_seq": { + Type: vindexes.TypeSequence, + }, }, }, }) require.NoError(t, err) - err = tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "hash": { - Type: "hash", + err = tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "hash": { + Type: "hash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "id", - Name: "hash", - }}, - AutoIncrement: &vschemapb.AutoIncrement{ - Column: "id", - Sequence: "t1_seq", + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "id", + Name: "hash", + }}, + AutoIncrement: &vschemapb.AutoIncrement{ + Column: "id", + Sequence: "t1_seq", + }, }, }, }, @@ -1203,36 +1215,42 @@ func TestSourceShardSelection(t *testing.T) { ws := workflow.NewServer(vtenv.NewTestEnv(), tenv.ts, tenv.tmc) - err := tenv.ts.SaveVSchema(ctx, sourceKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "hash": { - Type: "hash", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: sourceKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "hash": { + Type: "hash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "id", - Name: "hash", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "id", + Name: "hash", + }}, + }, }, }, }) require.NoError(t, err) - err = tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "hash": { - Type: "hash", + err = tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "hash": { + Type: "hash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "id", - Name: "hash", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "id", + Name: "hash", + }}, + }, }, }, }) @@ -1334,7 +1352,11 @@ func TestSourceShardSelection(t *testing.T) { tenv.tmc.SetSchema(tt.schema) if tt.vschema != nil { - err = tenv.ts.SaveVSchema(ctx, targetKs, tt.vschema) + ksvs := &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: tt.vschema, + } + err = tenv.ts.SaveVSchema(ctx, ksvs) require.NoError(t, err) } @@ -1522,7 +1544,7 @@ func TestFailedMoveTablesCreateCleanup(t *testing.T) { // Check that our vschema changes were also rolled back. vs2, err := tenv.ts.GetVSchema(ctx, targetKs) require.NoError(t, err, "failed to get target vschema") - require.Equal(t, vs, vs2, "expected vschema to be unchanged") + require.Equal(t, vs.Keyspace, vs2.Keyspace, "expected vschema to be unchanged; expected: %+v, got: %+v", vs.Keyspace, vs2.Keyspace) } // TestHasVReplicationWorkflows tests the simple RPC to be sure @@ -2035,7 +2057,11 @@ func TestExternalizeLookupVindex(t *testing.T) { for _, tcase := range testcases { t.Run(tcase.request.Name, func(t *testing.T) { // Resave the source schema for every iteration. - err := tenv.ts.SaveVSchema(ctx, tcase.request.Keyspace, sourceVschema) + ksvs := &topo.KeyspaceVSchemaInfo{ + Name: tcase.request.Keyspace, + Keyspace: sourceVschema, + } + err := tenv.ts.SaveVSchema(ctx, ksvs) require.NoError(t, err) err = tenv.ts.RebuildSrvVSchema(ctx, []string{tenv.cells[0]}) require.NoError(t, err) @@ -2276,19 +2302,22 @@ func TestMaterializerOneToMany(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "xxhash": { - Type: "xxhash", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "xxhash": { + Type: "xxhash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "c1", - Name: "xxhash", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "c1", + Name: "xxhash", + }}, + }, }, }, }) @@ -2385,19 +2414,22 @@ func TestMaterializerManyToMany(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "xxhash": { - Type: "xxhash", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "xxhash": { + Type: "xxhash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "c1", - Name: "xxhash", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "c1", + Name: "xxhash", + }}, + }, }, }, }) @@ -2495,22 +2527,25 @@ func TestMaterializerMulticolumnVindex(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "region": { - Type: "region_experimental", - Params: map[string]string{ - "region_bytes": "1", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "region": { + Type: "region_experimental", + Params: map[string]string{ + "region_bytes": "1", + }, }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Columns: []string{"c1", "c2"}, - Name: "region", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Columns: []string{"c1", "c2"}, + Name: "region", + }}, + }, }, }, }) @@ -2749,22 +2784,25 @@ func TestMaterializerExplicitColumns(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "region": { - Type: "region_experimental", - Params: map[string]string{ - "region_bytes": "1", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "region": { + Type: "region_experimental", + Params: map[string]string{ + "region_bytes": "1", + }, }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Columns: []string{"c1", "c2"}, - Name: "region", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Columns: []string{"c1", "c2"}, + Name: "region", + }}, + }, }, }, }) @@ -2859,22 +2897,25 @@ func TestMaterializerRenamedColumns(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "region": { - Type: "region_experimental", - Params: map[string]string{ - "region_bytes": "1", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "region": { + Type: "region_experimental", + Params: map[string]string{ + "region_bytes": "1", + }, }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Columns: []string{"c1", "c2"}, - Name: "region", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Columns: []string{"c1", "c2"}, + Name: "region", + }}, + }, }, }, }) @@ -3025,8 +3066,11 @@ func TestMaterializerNoTargetVSchema(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + }, }) require.NoError(t, err) @@ -3426,24 +3470,27 @@ func TestMaterializerNoGoodVindex(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "lookup_unique": { - Type: "lookup_unique", - Params: map[string]string{ - "table": "t1", - "from": "c1", - "to": "c2", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "lookup_unique": { + Type: "lookup_unique", + Params: map[string]string{ + "table": "t1", + "from": "c1", + "to": "c2", + }, }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "c1", - Name: "lookup_unique", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "c1", + Name: "lookup_unique", + }}, + }, }, }, }) @@ -3509,19 +3556,22 @@ func TestMaterializerComplexVindexExpression(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "xxhash": { - Type: "xxhash", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "xxhash": { + Type: "xxhash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "c1", - Name: "xxhash", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "c1", + Name: "xxhash", + }}, + }, }, }, }) @@ -3587,19 +3637,22 @@ func TestMaterializerNoVindexInExpression(t *testing.T) { }), } - err := tenv.ts.SaveVSchema(ctx, targetKs, &vschemapb.Keyspace{ - Sharded: true, - Vindexes: map[string]*vschemapb.Vindex{ - "xxhash": { - Type: "xxhash", + err := tenv.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + Vindexes: map[string]*vschemapb.Vindex{ + "xxhash": { + Type: "xxhash", + }, }, - }, - Tables: map[string]*vschemapb.Table{ - "t1": { - ColumnVindexes: []*vschemapb.ColumnVindex{{ - Column: "c1", - Name: "xxhash", - }}, + Tables: map[string]*vschemapb.Table{ + "t1": { + ColumnVindexes: []*vschemapb.ColumnVindex{{ + Column: "c1", + Name: "xxhash", + }}, + }, }, }, }) diff --git a/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go b/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go index 632579551c0..552a713b145 100644 --- a/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go +++ b/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go @@ -205,7 +205,11 @@ func (te *Env) SetVSchema(vs string) error { if err := json2.UnmarshalPB([]byte(vs), &kspb); err != nil { return err } - if err := te.TopoServ.SaveVSchema(ctx, te.KeyspaceName, &kspb); err != nil { + ksvs := &topo.KeyspaceVSchemaInfo{ + Name: te.KeyspaceName, + Keyspace: &kspb, + } + if err := te.TopoServ.SaveVSchema(ctx, ksvs); err != nil { return err } te.SchemaEngine.Reload(ctx) diff --git a/go/vt/wrangler/materializer_test.go b/go/vt/wrangler/materializer_test.go index 1871d778c6b..b4e50952f42 100644 --- a/go/vt/wrangler/materializer_test.go +++ b/go/vt/wrangler/materializer_test.go @@ -34,6 +34,7 @@ import ( "vitess.io/vitess/go/test/utils" "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vtenv" @@ -329,10 +330,16 @@ func TestCreateLookupVindexFull(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.TargetKeyspace, &vschemapb.Keyspace{}); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: &vschemapb.Keyspace{}, + }); err != nil { t.Fatal(err) } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, sourceVSchema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: sourceVSchema, + }); err != nil { t.Fatal(err) } @@ -412,7 +419,10 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) { }, }, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -827,10 +837,16 @@ func TestCreateLookupVindexSourceVSchema(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.TargetKeyspace, &vschemapb.Keyspace{}); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: &vschemapb.Keyspace{}, + }); err != nil { t.Fatal(err) } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, tcase.sourceVSchema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: tcase.sourceVSchema, + }); err != nil { t.Fatal(err) } @@ -866,7 +882,10 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { }, }, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, sourcevs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: sourcevs, + }); err != nil { t.Fatal(err) } @@ -1063,7 +1082,10 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { }}, } specs.Vindexes["v"].Params["table"] = fmt.Sprintf("%s.%s", ms.TargetKeyspace, tcase.targetTable) - if err := env.topoServ.SaveVSchema(context.Background(), ms.TargetKeyspace, tcase.targetVSchema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.TargetKeyspace, + Keyspace: tcase.targetVSchema, + }); err != nil { t.Fatal(err) } @@ -1178,7 +1200,10 @@ func TestCreateLookupVindexSameKeyspace(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -1287,7 +1312,10 @@ func TestCreateCustomizedVindex(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -1402,7 +1430,10 @@ func TestCreateLookupVindexIgnoreNulls(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -1480,7 +1511,10 @@ func TestStopAfterCopyFlag(t *testing.T) { Schema: sourceSchema, }}, } - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, vschema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: vschema, + }); err != nil { t.Fatal(err) } @@ -1536,10 +1570,16 @@ func TestCreateLookupVindexFailures(t *testing.T) { }, }, } - if err := topoServ.SaveVSchema(context.Background(), "sourceks", vs); err != nil { + if err := topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "sourceks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } - if err := topoServ.SaveVSchema(context.Background(), "targetks", &vschemapb.Keyspace{}); err != nil { + if err := topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: &vschemapb.Keyspace{}, + }); err != nil { t.Fatal(err) } @@ -1861,7 +1901,10 @@ func TestExternalizeVindex(t *testing.T) { }} for _, tcase := range testcases { // Resave the source schema for every iteration. - if err := env.topoServ.SaveVSchema(context.Background(), ms.SourceKeyspace, sourceVSchema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: ms.SourceKeyspace, + Keyspace: sourceVSchema, + }); err != nil { t.Fatal(err) } if tcase.vrResponse != nil { @@ -2012,7 +2055,10 @@ func TestMaterializerOneToMany(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2069,7 +2115,10 @@ func TestMaterializerManyToMany(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2130,7 +2179,10 @@ func TestMaterializerMulticolumnVindex(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2267,7 +2319,10 @@ func TestMaterializerExplicitColumns(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2327,7 +2382,10 @@ func TestMaterializerRenamedColumns(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2399,7 +2457,10 @@ func TestMaterializerNoTargetVSchema(t *testing.T) { Sharded: true, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } env.tmc.expectVRQuery(200, mzSelectFrozenQuery, &sqltypes.Result{}) @@ -2619,7 +2680,10 @@ func TestMaterializerNoGoodVindex(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2660,7 +2724,10 @@ func TestMaterializerComplexVindexExpression(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -2701,7 +2768,10 @@ func TestMaterializerNoVindexInExpression(t *testing.T) { }, } - if err := env.topoServ.SaveVSchema(context.Background(), "targetks", vs); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -3138,11 +3208,17 @@ func TestMaterializerSourceShardSelection(t *testing.T) { for _, tcase := range testcases { t.Run(tcase.name, func(t *testing.T) { env, ctx := newTestMaterializerEnv(t, ms, tcase.sourceShards, tcase.targetShards) - if err := env.topoServ.SaveVSchema(ctx, "targetks", tcase.targetVSchema); err != nil { + if err := env.topoServ.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "targetks", + Keyspace: tcase.targetVSchema, + }); err != nil { t.Fatal(err) } if tcase.sourceVSchema != nil { - if err := env.topoServ.SaveVSchema(context.Background(), "sourceks", tcase.sourceVSchema); err != nil { + if err := env.topoServ.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: "sourceks", + Keyspace: tcase.sourceVSchema, + }); err != nil { t.Fatal(err) } } @@ -3395,7 +3471,10 @@ func TestAddTablesToVSchema(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ts.SaveVSchema(ctx, srcks, tt.sourceVSchema) + ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: srcks, + Keyspace: tt.sourceVSchema, + }) err := wr.addTablesToVSchema(ctx, srcks, tt.inTargetVSchema, tt.tables, tt.copyVSchema) require.NoError(t, err) require.Equal(t, tt.wantTargetVSchema, tt.inTargetVSchema) @@ -3587,7 +3666,10 @@ func TestKeyRangesEqualOptimization(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() // Target is always sharded. - err := env.wr.ts.SaveVSchema(ctx, targetKs, targetVSchema) + err := env.wr.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: targetKs, + Keyspace: targetVSchema, + }) require.NoError(t, err, "SaveVSchema failed: %v", err) for _, tablet := range env.tablets { diff --git a/go/vt/wrangler/resharder_test.go b/go/vt/wrangler/resharder_test.go index 4c47b3ebf14..2caa49c4f68 100644 --- a/go/vt/wrangler/resharder_test.go +++ b/go/vt/wrangler/resharder_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "vitess.io/vitess/go/sqltypes" + "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/vtgate/vindexes" binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" @@ -218,7 +219,10 @@ func TestResharderOneRefTable(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -272,7 +276,10 @@ func TestReshardStopFlags(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -325,7 +332,10 @@ func TestResharderOneRefStream(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -404,7 +414,10 @@ func TestResharderNoRefStream(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -627,7 +640,10 @@ func TestResharderUnnamedStream(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -677,7 +693,10 @@ func TestResharderMismatchedRefStreams(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -797,7 +816,10 @@ func TestResharderMixedTablesOrder1(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } @@ -866,7 +888,10 @@ func TestResharderMixedTablesOrder2(t *testing.T) { }, }, } - if err := env.wr.ts.SaveVSchema(context.Background(), env.keyspace, vs); err != nil { + if err := env.wr.ts.SaveVSchema(context.Background(), &topo.KeyspaceVSchemaInfo{ + Name: env.keyspace, + Keyspace: vs, + }); err != nil { t.Fatal(err) } diff --git a/go/vt/wrangler/traffic_switcher_env_test.go b/go/vt/wrangler/traffic_switcher_env_test.go index a99e6ba2c43..0c7f705bb2d 100644 --- a/go/vt/wrangler/traffic_switcher_env_test.go +++ b/go/vt/wrangler/traffic_switcher_env_test.go @@ -206,12 +206,18 @@ func newTestTableMigraterCustom(ctx context.Context, t *testing.T, sourceShards, } tme.setPrimarySchemas(schema) if len(sourceShards) != 1 { - if err := tme.ts.SaveVSchema(ctx, "ks1", vs); err != nil { + if err := tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks1", + Keyspace: vs, + }); err != nil { t.Fatal(err) } } if len(targetShards) != 1 { - if err := tme.ts.SaveVSchema(ctx, "ks2", vs); err != nil { + if err := tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks2", + Keyspace: vs, + }); err != nil { t.Fatal(err) } } @@ -232,7 +238,10 @@ func newTestTableMigraterCustom(ctx context.Context, t *testing.T, sourceShards, tabletID += 10 gfdb := fakesqldb.New(t) tme.additionalPrimaries = append(tme.additionalPrimaries, newFakeTablet(t, tme.wr, "cell1", uint32(tabletID), topodatapb.TabletType_PRIMARY, gfdb, TabletKeyspaceShard(t, "global", "0"))) - if err := tme.ts.SaveVSchema(ctx, "global", uvs); err != nil { + if err := tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "global", + Keyspace: uvs, + }); err != nil { t.Fatal(err) } @@ -246,7 +255,10 @@ func newTestTableMigraterCustom(ctx context.Context, t *testing.T, sourceShards, Column: "id", Sequence: "t2_seq", } - if err := tme.ts.SaveVSchema(ctx, "ks2", tks); err != nil { + if err := tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks2", + Keyspace: tks, + }); err != nil { t.Fatal(err) } @@ -459,9 +471,15 @@ func newTestTablePartialMigrater(ctx context.Context, t *testing.T, shards, shar }, }, } - err := tme.ts.SaveVSchema(ctx, "ks1", vs) + err := tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks1", + Keyspace: vs, + }) require.NoError(t, err) - err = tme.ts.SaveVSchema(ctx, "ks2", vs) + err = tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks2", + Keyspace: vs, + }) require.NoError(t, err) err = tme.ts.RebuildSrvVSchema(ctx, nil) require.NoError(t, err) @@ -630,7 +648,10 @@ func newTestShardMigrater(ctx context.Context, t *testing.T, sourceShards, targe }, }, } - if err := tme.ts.SaveVSchema(ctx, "ks", vs); err != nil { + if err := tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks", + Keyspace: vs, + }); err != nil { t.Fatal(err) } if err := tme.ts.RebuildSrvVSchema(ctx, nil); err != nil { diff --git a/go/vt/wrangler/traffic_switcher_test.go b/go/vt/wrangler/traffic_switcher_test.go index 5bc336f634e..4ee965ef96b 100644 --- a/go/vt/wrangler/traffic_switcher_test.go +++ b/go/vt/wrangler/traffic_switcher_test.go @@ -2170,8 +2170,11 @@ func TestNoOrphanedRoutingRulesOnFailedCreate(t *testing.T) { // fail. Let's also be sure that the routing rules are empty. err := topotools.SaveRoutingRules(ctx, tme.wr.ts, nil) require.NoError(t, err, "failed to save routing rules") - err = tme.ts.SaveVSchema(ctx, "ks2", &vschemapb.Keyspace{ - Sharded: true, + err = tme.ts.SaveVSchema(ctx, &topo.KeyspaceVSchemaInfo{ + Name: "ks2", + Keyspace: &vschemapb.Keyspace{ + Sharded: true, + }, }) require.NoError(t, err, "failed to save vschema") err = tme.ts.RebuildSrvVSchema(ctx, nil)