Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Jan 3, 2025
1 parent d7409c6 commit 427c5ba
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
41 changes: 35 additions & 6 deletions go/test/endtoend/vreplication/global_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package vreplication

import (
"bytes"
"context"
"fmt"
"github.com/stretchr/testify/require"
"strings"
"testing"
"text/template"
"time"

"github.com/stretchr/testify/require"
"vitess.io/vitess/go/sqltypes"

vttablet "vitess.io/vitess/go/vt/vttablet/common"
)
Expand Down Expand Up @@ -102,6 +103,31 @@ func (h *grHelpers) insertData(t *testing.T, keyspace string, table string, id i
require.NoError(t, err)
}

func (h *grHelpers) execWithRetry(t *testing.T, query string, timeoutSeconds int) {
vtgateConn, cancel := getVTGateConn()
defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds)*time.Second)
defer cancel()
ticker := time.NewTicker(defaultTick)
defer ticker.Stop()

var qr *sqltypes.Result
var err error
for {
qr, err = vtgateConn.ExecuteFetch(query, 1000, false)
if err == nil {
return qr
}
select {
case <-ctx.Done():
require.FailNow(t, fmt.Sprintf("query %q did not succeed before the timeout of %s; last seen result: %v",
query, timeout, qr))
case <-ticker.C:
log.Infof("query %q failed with error %v, retrying in %ds", query, err, defaultTick)
}
}
}

func (h *grHelpers) isGlobal(t *testing.T, tables []string, expectedVal string) bool {
vtgateConn, cancel := getVTGateConn()
defer cancel()
Expand Down Expand Up @@ -221,6 +247,9 @@ func (h *grHelpers) rebuildGraphs(t *testing.T, keyspaces []string) {
require.NoError(t, err)
}

// TestGlobalRouting tests global routing for unsharded and sharded keyspaces by setting up keyspaces
// with different table configurations and verifying that the tables are globally routed
// by querying via vtgate.
func TestGlobalRouting(t *testing.T) {
h := grHelpers{t}
exp := *h.getExpectations()
Expand Down Expand Up @@ -250,8 +279,8 @@ func testGlobalRouting(t *testing.T, unshardedHasVSchema bool, funcs *grTestExpe
}
keyspaces := []string{config.ksU1}
h.rebuildGraphs(t, keyspaces)
// FIXME: figure out how to ensure vtgate has processed the updated vschema
time.Sleep(5 * time.Second)
//// FIXME: figure out how to ensure vtgate has processed the updated vschema
//time.Sleep(5 * time.Second)
funcs.postKsU1(t)

vc.AddKeyspace(t, []*Cell{zone1}, config.ksU2, "0", h.getUnshardedVschema(unshardedHasVSchema, config.ksU2Tables),
Expand All @@ -265,7 +294,7 @@ func testGlobalRouting(t *testing.T, unshardedHasVSchema bool, funcs *grTestExpe
}
keyspaces = append(keyspaces, config.ksU2)
h.rebuildGraphs(t, keyspaces)
time.Sleep(5 * time.Second)
//time.Sleep(5 * time.Second)
funcs.postKsU2(t)

vc.AddKeyspace(t, []*Cell{zone1}, config.ksS1, "-80,80-", h.getShardedVSchema(config.ksS1Tables), h.getSchema(config.ksS1Tables),
Expand All @@ -279,6 +308,6 @@ func testGlobalRouting(t *testing.T, unshardedHasVSchema bool, funcs *grTestExpe
}
keyspaces = append(keyspaces, config.ksS1)
h.rebuildGraphs(t, keyspaces)
time.Sleep(5 * time.Second)
//time.Sleep(5 * time.Second)
funcs.postKsS1(t)
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func AddAdditionalGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) {
continue
}
for tname, table := range ksvschema.Tables {
// Ignore tables already global or ambiguous.
// Ignore tables already global (i.e. if specified in the vschema of an unsharded keyspace) or ambiguous.
if _, found := vschema.globalTables[tname]; !found {
_, ok := newTables[tname]
if !ok {
Expand Down
18 changes: 18 additions & 0 deletions go/vt/vtgate/vindexes/vschema_routing_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vindexes

import (
Expand All @@ -14,6 +30,8 @@ import (
"vitess.io/vitess/go/vt/sqlparser"
)

// TestAutoGlobalRoutingExt tests the global routing of tables across various keyspace configurations,
// including unsharded and sharded keyspaces, with and without the RequireExplicitRouting flag.
func TestAutoGlobalRoutingExt(t *testing.T) {
isTableGloballyRoutable := func(vschema *VSchema, tableName string) (isGlobal, isAmbiguous bool) {
table, err := vschema.FindTable("", tableName)
Expand Down

0 comments on commit 427c5ba

Please sign in to comment.