From 5bb885bee2c9f397dc75c652b091867934a4932c 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/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 +- .../tabletmanager/rpc_vreplication_test.go | 403 ++++++++++-------- .../tabletserver/vstreamer/testenv/testenv.go | 6 +- 14 files changed, 513 insertions(+), 330 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/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/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)