Skip to content

Commit

Permalink
vtcombo: close query service on drop database (vitessio#16606)
Browse files Browse the repository at this point in the history
Signed-off-by: Brendan Dougherty <[email protected]>
  • Loading branch information
brendar committed Aug 29, 2024
1 parent b21783f commit 4e708af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions go/test/endtoend/vtcombo/recreate/recreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -101,13 +102,33 @@ func TestDropAndRecreateWithSameShards(t *testing.T) {

cur := conn.Session(ks1+"@primary", nil)

mysqlConnCountBefore, err := getMySQLConnectionCount(ctx, cur)
require.Nil(t, err)

_, err = cur.Execute(ctx, "DROP DATABASE "+ks1, nil)
require.Nil(t, err)

_, err = cur.Execute(ctx, "CREATE DATABASE "+ks1, nil)
require.Nil(t, err)

assertTabletsPresent(t)

// Check the connection count after the CREATE. There will be zero connections after the DROP as the database
// no longer exists, but after it gets recreated any open pools will be able to reestablish connections.
mysqlConnCountAfter, err := getMySQLConnectionCount(ctx, cur)
require.Nil(t, err)

// Assert that we're not leaking mysql connections, but allow for some wiggle room due to transient connections
assert.InDelta(t, mysqlConnCountBefore, mysqlConnCountAfter, 5,
"not within allowable delta: mysqlConnCountBefore=%d, mysqlConnCountAfter=%d", mysqlConnCountBefore, mysqlConnCountAfter)
}

func getMySQLConnectionCount(ctx context.Context, session *vtgateconn.VTGateSession) (int, error) {
result, err := session.Execute(ctx, "select variable_value from performance_schema.global_status where variable_name='threads_connected'", nil)
if err != nil {
return 0, err
}
return strconv.Atoi(result.Rows[0][0].ToString())
}

func assertTabletsPresent(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion go/vt/vtcombo/tablet_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ func DeleteKs(
tablet.tm.Stop()
tablet.tm.Close()
tablet.qsc.SchemaEngine().Close()
err := ts.DeleteTablet(ctx, tablet.alias)
err := tablet.qsc.QueryService().Close(ctx)
if err != nil {
return err
}
err = ts.DeleteTablet(ctx, tablet.alias)
if err != nil {
return err
}
Expand Down

0 comments on commit 4e708af

Please sign in to comment.