-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix for Query Serving when Toposerver is Down #7484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4477665
added e2e test for query serving even when topo server is down
harshit-gangal bfceeb3
do not evict cache if unable to connect to topo server
harshit-gangal 2755dce
make sure to keep data even when topo server is deleted
systay 04353cf
added toposerver down testing for zk, consul and etcd
harshit-gangal df439ab
added to ci tests
harshit-gangal 2c28656
fixed e2e test config for zk and consul
harshit-gangal f5384de
test in right shard
harshit-gangal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| /* | ||
| 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 consul | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "vitess.io/vitess/go/vt/log" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| "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 | ||
| cell = "zone1" | ||
| hostname = "localhost" | ||
| KeyspaceName = "customer" | ||
| SchemaSQL = ` | ||
| CREATE TABLE t1 ( | ||
| c1 BIGINT NOT NULL, | ||
| c2 BIGINT NOT NULL, | ||
| c3 BIGINT, | ||
| c4 varchar(100), | ||
| PRIMARY KEY (c1), | ||
| UNIQUE KEY (c2), | ||
| UNIQUE KEY (c3), | ||
| UNIQUE KEY (c4) | ||
| ) ENGINE=Innodb;` | ||
| VSchema = ` | ||
| { | ||
| "sharded": false, | ||
| "tables": { | ||
| "t1": {} | ||
| } | ||
| } | ||
| ` | ||
| ) | ||
|
|
||
| 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 | ||
| clusterInstance.TopoFlavor = "consul" | ||
| if err := clusterInstance.StartTopo(); err != nil { | ||
| return 1 | ||
| } | ||
|
|
||
| // Start keyspace | ||
| Keyspace := &cluster.Keyspace{ | ||
| Name: KeyspaceName, | ||
| SchemaSQL: SchemaSQL, | ||
| VSchema: VSchema, | ||
| } | ||
| if err := clusterInstance.StartUnshardedKeyspace(*Keyspace, 0, false); err != nil { | ||
| log.Fatal(err.Error()) | ||
| return 1 | ||
| } | ||
|
|
||
| // Start vtgate | ||
| if err := clusterInstance.StartVtgate(); err != nil { | ||
| log.Fatal(err.Error()) | ||
| return 1 | ||
| } | ||
|
|
||
| return m.Run() | ||
| }() | ||
| os.Exit(exitCode) | ||
| } | ||
|
|
||
| func TestTopoDownServingQuery(t *testing.T) { | ||
| defer cluster.PanicHandler(t) | ||
| ctx := context.Background() | ||
| vtParams := mysql.ConnParams{ | ||
| Host: "localhost", | ||
| Port: clusterInstance.VtgateMySQLPort, | ||
| } | ||
| conn, err := mysql.Connect(ctx, &vtParams) | ||
| require.Nil(t, err) | ||
| defer conn.Close() | ||
|
|
||
| defer exec(t, conn, `delete from t1`) | ||
|
|
||
| execMulti(t, conn, `insert into t1(c1, c2, c3, c4) values (300,100,300,'abc'); ;; insert into t1(c1, c2, c3, c4) values (301,101,301,'abcd');;`) | ||
| assertMatches(t, conn, `select c1,c2,c3 from t1`, `[[INT64(300) INT64(100) INT64(300)] [INT64(301) INT64(101) INT64(301)]]`) | ||
| clusterInstance.TopoProcess.TearDown(clusterInstance.Cell, clusterInstance.OriginalVTDATAROOT, clusterInstance.CurrentVTDATAROOT, true, *clusterInstance.TopoFlavorString()) | ||
| time.Sleep(3 * time.Second) | ||
| assertMatches(t, conn, `select c1,c2,c3 from t1`, `[[INT64(300) INT64(100) INT64(300)] [INT64(301) INT64(101) INT64(301)]]`) | ||
| } | ||
|
|
||
| func exec(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 | ||
| } | ||
|
|
||
| func execMulti(t *testing.T, conn *mysql.Conn, query string) []*sqltypes.Result { | ||
| t.Helper() | ||
| var res []*sqltypes.Result | ||
| qr, more, err := conn.ExecuteFetchMulti(query, 1000, true) | ||
| res = append(res, qr) | ||
| require.NoError(t, err) | ||
| for more == true { | ||
| qr, more, _, err = conn.ReadQueryResult(1000, true) | ||
| require.NoError(t, err) | ||
| res = append(res, qr) | ||
| } | ||
| return res | ||
| } | ||
|
|
||
| func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) { | ||
| t.Helper() | ||
| qr := exec(t, conn, query) | ||
| got := fmt.Sprintf("%v", qr.Rows) | ||
| diff := cmp.Diff(expected, got) | ||
| if diff != "" { | ||
| t.Errorf("Query: %s (-want +got):\n%s", query, diff) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /* | ||
| 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 ectd2 | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "vitess.io/vitess/go/vt/log" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| "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 | ||
| cell = "zone1" | ||
| hostname = "localhost" | ||
| KeyspaceName = "customer" | ||
| SchemaSQL = ` | ||
| CREATE TABLE t1 ( | ||
| c1 BIGINT NOT NULL, | ||
| c2 BIGINT NOT NULL, | ||
| c3 BIGINT, | ||
| c4 varchar(100), | ||
| PRIMARY KEY (c1), | ||
| UNIQUE KEY (c2), | ||
| UNIQUE KEY (c3), | ||
| UNIQUE KEY (c4) | ||
| ) ENGINE=Innodb;` | ||
| VSchema = ` | ||
| { | ||
| "sharded": false, | ||
| "tables": { | ||
| "t1": {} | ||
| } | ||
| } | ||
| ` | ||
| ) | ||
|
|
||
| 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: SchemaSQL, | ||
| VSchema: VSchema, | ||
| } | ||
| if err := clusterInstance.StartUnshardedKeyspace(*Keyspace, 0, false); err != nil { | ||
| log.Fatal(err.Error()) | ||
| return 1 | ||
| } | ||
|
|
||
| // Start vtgate | ||
| if err := clusterInstance.StartVtgate(); err != nil { | ||
| log.Fatal(err.Error()) | ||
| return 1 | ||
| } | ||
|
|
||
| return m.Run() | ||
| }() | ||
| os.Exit(exitCode) | ||
| } | ||
|
|
||
| func TestTopoDownServingQuery(t *testing.T) { | ||
| defer cluster.PanicHandler(t) | ||
| ctx := context.Background() | ||
| vtParams := mysql.ConnParams{ | ||
| Host: "localhost", | ||
| Port: clusterInstance.VtgateMySQLPort, | ||
| } | ||
| conn, err := mysql.Connect(ctx, &vtParams) | ||
| require.Nil(t, err) | ||
| defer conn.Close() | ||
|
|
||
| defer exec(t, conn, `delete from t1`) | ||
|
|
||
| execMulti(t, conn, `insert into t1(c1, c2, c3, c4) values (300,100,300,'abc'); ;; insert into t1(c1, c2, c3, c4) values (301,101,301,'abcd');;`) | ||
| assertMatches(t, conn, `select c1,c2,c3 from t1`, `[[INT64(300) INT64(100) INT64(300)] [INT64(301) INT64(101) INT64(301)]]`) | ||
| clusterInstance.TopoProcess.TearDown(clusterInstance.Cell, clusterInstance.OriginalVTDATAROOT, clusterInstance.CurrentVTDATAROOT, true, *clusterInstance.TopoFlavorString()) | ||
| time.Sleep(3 * time.Second) | ||
| assertMatches(t, conn, `select c1,c2,c3 from t1`, `[[INT64(300) INT64(100) INT64(300)] [INT64(301) INT64(101) INT64(301)]]`) | ||
| } | ||
|
|
||
| func exec(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 | ||
| } | ||
|
|
||
| func execMulti(t *testing.T, conn *mysql.Conn, query string) []*sqltypes.Result { | ||
| t.Helper() | ||
| var res []*sqltypes.Result | ||
| qr, more, err := conn.ExecuteFetchMulti(query, 1000, true) | ||
| res = append(res, qr) | ||
| require.NoError(t, err) | ||
| for more == true { | ||
| qr, more, _, err = conn.ReadQueryResult(1000, true) | ||
| require.NoError(t, err) | ||
| res = append(res, qr) | ||
| } | ||
| return res | ||
| } | ||
|
|
||
| func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) { | ||
| t.Helper() | ||
| qr := exec(t, conn, query) | ||
| got := fmt.Sprintf("%v", qr.Rows) | ||
| diff := cmp.Diff(expected, got) | ||
| if diff != "" { | ||
| t.Errorf("Query: %s (-want +got):\n%s", query, diff) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.