-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: reserved connection retry logic when vttablet or mysql is down (#…
…10005) (#10052) * fix: when mysql is down and vttablet is up Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: in reserved conn with no transaction if the queryservice i.e vttablet is down then it should go through gateway Signed-off-by: Harshit Gangal <harshit@planetscale.com> * refactor: execute and streamExecute should be able to reset the shard if needed and not executeLock Signed-off-by: Harshit Gangal <harshit@planetscale.com> * test: e2e test for bug fix Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: when mysql is down, query should go through gateway to elect new healthy tablet for the given tablet_type Signed-off-by: Harshit Gangal <harshit@planetscale.com>
- Loading branch information
1 parent
cad4bc0
commit 4e12193
Showing
7 changed files
with
261 additions
and
12 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go
This file contains 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,96 @@ | ||
/* | ||
Copyright 2022 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/require" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"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;` | ||
) | ||
|
||
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, | ||
} | ||
if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false); err != nil { | ||
return 1 | ||
} | ||
|
||
// Start vtgate | ||
clusterInstance.VtGateExtraArgs = []string{"--enable_system_settings=true"} | ||
if err := clusterInstance.StartVtgate(); err != nil { | ||
return 1 | ||
} | ||
|
||
vtParams = mysql.ConnParams{ | ||
Host: clusterInstance.Hostname, | ||
Port: clusterInstance.VtgateMySQLPort, | ||
} | ||
return m.Run() | ||
}() | ||
os.Exit(exitCode) | ||
} | ||
|
||
func TestMysqlDownServingChange(t *testing.T) { | ||
conn, err := mysql.Connect(context.Background(), &vtParams) | ||
require.NoError(t, err) | ||
defer conn.Close() | ||
|
||
_, err = conn.ExecuteFetch("set default_week_format = 1", 5, false) | ||
require.NoError(t, err) | ||
_, err = conn.ExecuteFetch("select /*vt+ PLANNER=gen4 */ * from test", 5, false) | ||
require.NoError(t, err) | ||
|
||
primaryTablet := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet() | ||
require.NoError(t, | ||
primaryTablet.MysqlctlProcess.Stop()) | ||
require.NoError(t, | ||
clusterInstance.VtctlclientProcess.ExecuteCommand("EmergencyReparentShard", "-keyspace_shard", "ks/0")) | ||
|
||
// This should work without any error. | ||
_, err = conn.ExecuteFetch("select /*vt+ PLANNER=gen4 */ * from test", 5, false) | ||
require.NoError(t, err) | ||
} |
98 changes: 98 additions & 0 deletions
98
go/test/endtoend/vtgate/reservedconn/reconnect4/main_test.go
This file contains 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,98 @@ | ||
/* | ||
Copyright 2022 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/require" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"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;` | ||
) | ||
|
||
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, | ||
} | ||
if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false); err != nil { | ||
return 1 | ||
} | ||
|
||
// Start vtgate | ||
clusterInstance.VtGateExtraArgs = []string{"--enable_system_settings=true"} | ||
if err := clusterInstance.StartVtgate(); err != nil { | ||
return 1 | ||
} | ||
|
||
vtParams = mysql.ConnParams{ | ||
Host: clusterInstance.Hostname, | ||
Port: clusterInstance.VtgateMySQLPort, | ||
} | ||
return m.Run() | ||
}() | ||
os.Exit(exitCode) | ||
} | ||
|
||
func TestVttabletDownServingChange(t *testing.T) { | ||
conn, err := mysql.Connect(context.Background(), &vtParams) | ||
require.NoError(t, err) | ||
defer conn.Close() | ||
|
||
_, err = conn.ExecuteFetch("set default_week_format = 1", 5, false) | ||
require.NoError(t, err) | ||
_, err = conn.ExecuteFetch("select /*vt+ PLANNER=gen4 */ * from test", 5, false) | ||
require.NoError(t, err) | ||
|
||
primaryTablet := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet() | ||
require.NoError(t, | ||
primaryTablet.MysqlctlProcess.Stop()) | ||
// kill vttablet process | ||
_ = primaryTablet.VttabletProcess.TearDown() | ||
require.NoError(t, | ||
clusterInstance.VtctlclientProcess.ExecuteCommand("EmergencyReparentShard", "-keyspace_shard", "ks/0")) | ||
|
||
// This should work without any error. | ||
_, err = conn.ExecuteFetch("select /*vt+ PLANNER=gen4 */ * from test", 5, false) | ||
require.NoError(t, err) | ||
} |
This file contains 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 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 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 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 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