From 2d34688a2efd9038965467724198bc3521407f6e Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Thu, 2 Jan 2025 14:54:54 +0100 Subject: [PATCH] Fix failing tests Signed-off-by: Rohit Nayak --- .../vreplication/global_routing_test.go | 38 ++++--------------- go/vt/vtgate/vindexes/vschema.go | 12 ++++-- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/go/test/endtoend/vreplication/global_routing_test.go b/go/test/endtoend/vreplication/global_routing_test.go index 43fd2887e0a..2cdd5770cd8 100644 --- a/go/test/endtoend/vreplication/global_routing_test.go +++ b/go/test/endtoend/vreplication/global_routing_test.go @@ -47,11 +47,7 @@ type grTestExpectations struct { postKsU1, postKsU2, postKsS1 func(t *testing.T) } -type grTestCase struct { - markAsGlobal bool - unshardedHasVSchema bool -} - +// Scope helpers to this test file so we don't pollute the global namespace. type grHelpers struct { t *testing.T } @@ -162,24 +158,9 @@ func (h *grHelpers) isAmbiguous(t *testing.T, tables []string) bool { return asExpected } -func (h *grHelpers) getExpectations() *map[grTestCase]*grTestExpectations { - var exp = make(map[grTestCase]*grTestExpectations) - exp[grTestCase{unshardedHasVSchema: false, markAsGlobal: false}] = &grTestExpectations{ - postKsU1: func(t *testing.T) { - require.True(t, h.isGlobal(t, []string{"t1", "t2", "t3"}, grTestConfig.ksU1)) - }, - postKsU2: func(t *testing.T) { - require.True(t, h.isNotGlobal(t, []string{"t1", "t2", "t3"})) - require.True(t, h.isNotGlobal(t, []string{"t4", "t5"})) - }, - postKsS1: func(t *testing.T) { - require.True(t, h.isGlobal(t, []string{"t2", "t4"}, grTestConfig.ksS1)) - require.True(t, h.isNotGlobal(t, []string{"t1", "t3"})) - require.True(t, h.isNotGlobal(t, []string{"t5"})) - require.True(t, h.isGlobal(t, []string{"t6"}, grTestConfig.ksS1)) - }, - } - exp[grTestCase{unshardedHasVSchema: false, markAsGlobal: true}] = &grTestExpectations{ +func (h *grHelpers) getExpectations() *map[bool]*grTestExpectations { + var exp = make(map[bool]*grTestExpectations) + exp[false] = &grTestExpectations{ postKsU1: func(t *testing.T) { require.True(t, h.isGlobal(t, []string{"t1", "t2", "t3"}, grTestConfig.ksU1)) }, @@ -195,7 +176,7 @@ func (h *grHelpers) getExpectations() *map[grTestCase]*grTestExpectations { require.True(t, h.isGlobal(t, []string{"t6"}, grTestConfig.ksS1)) }, } - exp[grTestCase{unshardedHasVSchema: true, markAsGlobal: false}] = &grTestExpectations{ + exp[true] = &grTestExpectations{ postKsU1: func(t *testing.T) { require.True(t, h.isGlobal(t, []string{"t1", "t2", "t3"}, grTestConfig.ksU1)) }, @@ -210,8 +191,6 @@ func (h *grHelpers) getExpectations() *map[grTestCase]*grTestExpectations { require.True(t, h.isGlobal(t, []string{"t5"}, grTestConfig.ksU2)) }, } - exp[grTestCase{unshardedHasVSchema: true, markAsGlobal: true}] = - exp[grTestCase{unshardedHasVSchema: true, markAsGlobal: false}] return &exp } @@ -246,17 +225,16 @@ func (h *grHelpers) rebuildGraphs(t *testing.T, keyspaces []string) { func TestGlobalRouting(t *testing.T) { h := grHelpers{t} exp := *h.getExpectations() - for tc, funcs := range exp { + for unshardedHasVSchema, funcs := range exp { require.NotNil(t, funcs) - testGlobalRouting(t, tc.markAsGlobal, tc.unshardedHasVSchema, funcs) + testGlobalRouting(t, unshardedHasVSchema, funcs) } } -func testGlobalRouting(t *testing.T, markAsGlobal, unshardedHasVSchema bool, funcs *grTestExpectations) { +func testGlobalRouting(t *testing.T, unshardedHasVSchema bool, funcs *grTestExpectations) { h := grHelpers{t: t} setSidecarDBName("_vt") vttablet.InitVReplicationConfigDefaults() - extraVTGateArgs = append(extraVTGateArgs, fmt.Sprintf("--mark_unique_unsharded_tables_as_global=%t", markAsGlobal)) vc = NewVitessCluster(t, nil) defer vc.TearDown() diff --git a/go/vt/vtgate/vindexes/vschema.go b/go/vt/vtgate/vindexes/vschema.go index caafe286cac..fbae70705ea 100644 --- a/go/vt/vtgate/vindexes/vschema.go +++ b/go/vt/vtgate/vindexes/vschema.go @@ -25,10 +25,9 @@ import ( "strings" "time" - "vitess.io/vitess/go/ptr" - "vitess.io/vitess/go/json2" "vitess.io/vitess/go/mysql/collations" + "vitess.io/vitess/go/ptr" "vitess.io/vitess/go/sqlescape" "vitess.io/vitess/go/sqltypes" querypb "vitess.io/vitess/go/vt/proto/query" @@ -494,7 +493,14 @@ func AddAdditionalGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) { if _, found := vschema.globalTables[tname]; !found { _, ok := newTables[tname] if !ok { - table.Keyspace = ksvschema.Keyspace + ks2 := ksvschema.Keyspace + if ks2 == nil { + ks2 = &Keyspace{Name: ksname} + } + if ks2.Name == "" { + ks2.Name = ksname + } + table.Keyspace = ks2 newTables[tname] = &tableInfo{table: table, cnt: 0} } newTables[tname].cnt++