Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a1d50b1
added failing tests
harshit-gangal Apr 16, 2021
e85e6b7
reconnect reserved connection if tablet is not serving
systay Apr 16, 2021
8f55ff9
separated end2end tests to make them less fragile
systay Apr 16, 2021
88385be
add test config
systay Apr 16, 2021
8f768da
upadte e2e test to be more compact
harshit-gangal Apr 18, 2021
9233352
check and send to new tablet on the same targed based on the error re…
harshit-gangal Apr 18, 2021
968a32b
updated e2e test
harshit-gangal Apr 18, 2021
85039b3
fix unit test
harshit-gangal Apr 19, 2021
88be8f2
added test for invalid target
harshit-gangal Apr 19, 2021
e5de1c7
added ping command to e2e test to make rdonly available
harshit-gangal Apr 19, 2021
f5bf2f4
return query service using alias only if the query service is serving…
harshit-gangal Apr 19, 2021
44e99bc
moved few errors and regex to vterrors as were used at multiple place…
harshit-gangal Apr 19, 2021
cb593e0
added unit test for query served through different tablet if the curr…
harshit-gangal Apr 19, 2021
8f15813
added logic to check and reset shard session and also to acquire new …
harshit-gangal Apr 19, 2021
3311045
added unit test to check query serving if the alias tablet target is …
harshit-gangal Apr 19, 2021
c161aba
check target only if it is not nil
harshit-gangal Apr 20, 2021
10a03d3
refactor
systay Apr 20, 2021
7aad79c
Merge remote-tracking branch 'upstream/master' into rc-t-fix
systay Apr 20, 2021
7614155
more refactor
harshit-gangal Apr 20, 2021
992ed58
addressed review comments
systay Apr 21, 2021
987b0ed
check for invalid and wrong keyworkd in regex
harshit-gangal Apr 22, 2021
a225828
making test more robust
harshit-gangal Apr 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions go/test/endtoend/vtgate/reservedconn/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ func TestMain(m *testing.M) {
}

// Start vtgate
clusterInstance.VtGateExtraArgs = []string{"-lock_heartbeat_time", "2s"}
vtgateProcess := clusterInstance.NewVtgateInstance()
vtgateProcess.SysVarSetEnabled = true
if err := vtgateProcess.Setup(); err != nil {
clusterInstance.VtGateExtraArgs = []string{"-lock_heartbeat_time", "2s", "-enable_system_settings=true"} // enable reserved connection.
if err := clusterInstance.StartVtgate(); err != nil {
return 1
}

Expand Down
150 changes: 150 additions & 0 deletions go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
Copyright 2021 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 reservedconn

import (
"context"
"flag"
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
clusterInstance *cluster.LocalProcessCluster
vtParams mysql.ConnParams
keyspaceName = "ks"
cell = "zone1"
hostname = "localhost"
sqlSchema = `create table test(id bigint primary key)Engine=InnoDB;`

vSchema = `
{
"sharded":true,
"vindexes": {
"hash_index": {
"type": "hash"
}
},
"tables": {
"test":{
"column_vindexes": [
{
"column": "id",
"name": "hash_index"
}
]
}
}
}
`
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitCode := func() int {
clusterInstance = cluster.NewCluster(cell, hostname)
defer clusterInstance.Teardown()

// Start topo server
if err := clusterInstance.StartTopo(); err != nil {
return 1
}

// Start keyspace
keyspace := &cluster.Keyspace{
Name: keyspaceName,
SchemaSQL: sqlSchema,
VSchema: vSchema,
}
if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true); err != nil {
return 1
}

// Start vtgate
clusterInstance.VtGateExtraArgs = []string{"-lock_heartbeat_time", "2s", "-enable_system_settings=true"} // enable reserved connection.
if err := clusterInstance.StartVtgate(); err != nil {
return 1
}

vtParams = mysql.ConnParams{
Host: clusterInstance.Hostname,
Port: clusterInstance.VtgateMySQLPort,
}
return m.Run()
}()
os.Exit(exitCode)
}

func TestServingChange(t *testing.T) {
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()

checkedExec(t, conn, "use @rdonly")
checkedExec(t, conn, "set sql_mode = ''")

// to see rdonly is available and
// also this will create reserved connection on rdonly on -80 and 80- shards.
_, err = exec(t, conn, "select * from test")
for err != nil {
_, err = exec(t, conn, "select * from test")
}

// changing rdonly tablet to spare (non serving).
rdonlyTablet := clusterInstance.Keyspaces[0].Shards[0].Rdonly()
err = clusterInstance.VtctlclientProcess.ExecuteCommand("ChangeTabletType", rdonlyTablet.Alias, "spare")
require.NoError(t, err)

// this should fail as there is no rdonly present
_, err = exec(t, conn, "select * from test")
require.Error(t, err)

// changing replica tablet to rdonly to make rdonly available for serving.
replicaTablet := clusterInstance.Keyspaces[0].Shards[0].Replica()
err = clusterInstance.VtctlclientProcess.ExecuteCommand("ChangeTabletType", replicaTablet.Alias, "rdonly")
require.NoError(t, err)

// to see/make the new rdonly available
err = clusterInstance.VtctlclientProcess.ExecuteCommand("Ping", replicaTablet.Alias)
require.NoError(t, err)

// this should pass now as there is rdonly present
_, err = exec(t, conn, "select * from test")
assert.NoError(t, err)
}

func exec(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
t.Helper()
return conn.ExecuteFetch(query, 1000, true)
}

func checkedExec(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result {
t.Helper()
qr, err := conn.ExecuteFetch(query, 1000, true)
require.NoError(t, err)
return qr
}
134 changes: 134 additions & 0 deletions go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
Copyright 2021 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 reservedconn

import (
"context"
"flag"
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
clusterInstance *cluster.LocalProcessCluster
vtParams mysql.ConnParams
keyspaceName = "ks"
cell = "zone1"
hostname = "localhost"
sqlSchema = `create table test(id bigint primary key)Engine=InnoDB;`

vSchema = `
{
"sharded":true,
"vindexes": {
"hash_index": {
"type": "hash"
}
},
"tables": {
"test":{
"column_vindexes": [
{
"column": "id",
"name": "hash_index"
}
]
}
}
}
`
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitCode := func() int {
clusterInstance = cluster.NewCluster(cell, hostname)
defer clusterInstance.Teardown()

// Start topo server
if err := clusterInstance.StartTopo(); err != nil {
return 1
}

// Start keyspace
keyspace := &cluster.Keyspace{
Name: keyspaceName,
SchemaSQL: sqlSchema,
VSchema: vSchema,
}
clusterInstance.VtTabletExtraArgs = []string{"-queryserver-config-transaction-timeout", "5"}
if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true); err != nil {
return 1
}

// Start vtgate
clusterInstance.VtGateExtraArgs = []string{"-lock_heartbeat_time", "2s", "-enable_system_settings=true"} // enable reserved connection.
if err := clusterInstance.StartVtgate(); err != nil {
return 1
}

vtParams = mysql.ConnParams{
Host: clusterInstance.Hostname,
Port: clusterInstance.VtgateMySQLPort,
}
return m.Run()
}()
os.Exit(exitCode)
}

func TestTabletChange(t *testing.T) {
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()

checkedExec(t, conn, "use @master")
checkedExec(t, conn, "set sql_mode = ''")

// this will create reserved connection on master on -80 and 80- shards.
checkedExec(t, conn, "select * from test")

// Change Master
err = clusterInstance.VtctlclientProcess.ExecuteCommand("PlannedReparentShard", "-keyspace_shard", fmt.Sprintf("%s/%s", keyspaceName, "-80"))
require.NoError(t, err)

// this should pass as there is new master tablet and is serving.
_, err = exec(t, conn, "select * from test")
assert.NoError(t, err)
}

func exec(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
t.Helper()
return conn.ExecuteFetch(query, 1000, true)
}

func checkedExec(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result {
t.Helper()
qr, err := conn.ExecuteFetch(query, 1000, true)
require.NoError(t, err)
return qr
}
19 changes: 12 additions & 7 deletions go/vt/discovery/fake_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@ import (
"sort"
"sync"

"vitess.io/vitess/go/sync2"

"github.com/golang/protobuf/proto"

"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

"vitess.io/vitess/go/sync2"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vttablet/queryservice"
"vitess.io/vitess/go/vt/vttablet/sandboxconn"

querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
)

var (
Expand Down Expand Up @@ -146,16 +144,23 @@ func (fhc *FakeHealthCheck) ReplaceTablet(old, new *topodatapb.Tablet) {
}

// TabletConnection returns the TabletConn of the given tablet.
func (fhc *FakeHealthCheck) TabletConnection(alias *topodatapb.TabletAlias) (queryservice.QueryService, error) {
func (fhc *FakeHealthCheck) TabletConnection(alias *topodatapb.TabletAlias, target *querypb.Target) (queryservice.QueryService, error) {
aliasStr := topoproto.TabletAliasString(alias)
fhc.mu.RLock()
defer fhc.mu.RUnlock()
for _, item := range fhc.items {
if proto.Equal(alias, item.ts.Tablet.Alias) {
if !item.ts.Serving {
return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, vterrors.NotServing)
}
if target != nil && !proto.Equal(item.ts.Target, target) {
return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "%s: target mismatch %v vs %v", vterrors.WrongTablet, item.ts.Target, target)
}

return item.ts.Conn, nil
}
}
return nil, vterrors.Errorf(vtrpc.Code_NOT_FOUND, "tablet %v not found", aliasStr)
return nil, vterrors.Errorf(vtrpcpb.Code_NOT_FOUND, "tablet %v not found", aliasStr)
}

// CacheStatus returns the status for each tablet
Expand Down
Loading