Skip to content
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

Online DDL: support 'SHOW VITESS_MIGRATIONS' queries #7638

Merged
merged 26 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c8d4d4b
Online DDL: support 'SHOW VITESS_MIGRATIONS' queries
shlomi-noach Mar 8, 2021
823d1dc
fulklk parse for 'show vitess_migrations'
shlomi-noach Mar 8, 2021
0b5adde
parser & ast: use ShowBasic instead of ShowLegacy for vitess_migrations
systay Mar 8, 2021
ae739f4
use vtgate 'SHOW VITESS_MIGRATIONS'
shlomi-noach Mar 8, 2021
1d112ab
added FROM and build engine primitive
systay Mar 8, 2021
2ddaeb2
Merge branch 'online-ddl-sql-interface' of github.com:planetscale/vit…
systay Mar 8, 2021
aab5701
add executor test for show vitess_migrations
systay Mar 8, 2021
7d00e70
use send primitive for show vitess_migrations
harshit-gangal Mar 9, 2021
606807b
fix test setup to use sharded keyspace
harshit-gangal Mar 9, 2021
a9a7ee6
stricter SHOW VITESS_MIGRATONS query; formatting improvements
shlomi-noach Mar 9, 2021
dad0e47
endtoend online ddl gh-ost tests: fixed sharded keyspace
shlomi-noach Mar 9, 2021
237e223
fixed unit test
shlomi-noach Mar 9, 2021
3896ca8
endtoend online ddl revert tests: using SHOW VITESS_MIGRATIONS
shlomi-noach Mar 9, 2021
a420c31
endtoend online ddl stress tests: using SHOW VITESS_MIGRATIONS
shlomi-noach Mar 9, 2021
7227937
refactor: consolidate utility functions
shlomi-noach Mar 9, 2021
4bffce9
fixed vtgate unit test
shlomi-noach Mar 9, 2021
3d570ec
fixed test number of shards
shlomi-noach Mar 9, 2021
b2788bd
fixed per review
shlomi-noach Mar 9, 2021
fc66891
remove unneeded code
shlomi-noach Mar 10, 2021
b0282e3
added go/test/endtoend/onlineddl
shlomi-noach Mar 10, 2021
a328a49
general purpose testing package for online-ddl tests
shlomi-noach Mar 10, 2021
b228da2
correct package name
shlomi-noach Mar 10, 2021
c90ec62
use new shared package
shlomi-noach Mar 10, 2021
38bdc9c
restructure directories
shlomi-noach Mar 10, 2021
86ad32a
rename package names
shlomi-noach Mar 10, 2021
cea6361
update paths
shlomi-noach Mar 10, 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
61 changes: 61 additions & 0 deletions go/test/endtoend/cluster/query_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2019 The Vitess Authors.
shlomi-noach marked this conversation as resolved.
Show resolved Hide resolved

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 cluster

import (
"io"
"strings"

"vitess.io/vitess/go/sqltypes"

"github.com/olekukonko/tablewriter"
)

// printQueryResult will pretty-print a QueryResult to the logger.
shlomi-noach marked this conversation as resolved.
Show resolved Hide resolved
func PrintQueryResult(writer io.Writer, qr *sqltypes.Result) {
if qr == nil {
return
}
if len(qr.Rows) == 0 {
return
}

table := tablewriter.NewWriter(writer)
table.SetAutoFormatHeaders(false)

// Make header.
header := make([]string, 0, len(qr.Fields))
for _, field := range qr.Fields {
header = append(header, field.Name)
}
table.SetHeader(header)

// Add rows.
for _, row := range qr.Rows {
vals := make([]string, 0, len(row))
for _, val := range row {
v := val.ToString()
v = strings.ReplaceAll(v, "\r", " ")
v = strings.ReplaceAll(v, "\n", " ")
vals = append(vals, v)
}
table.Append(vals)
}

// Print table.
table.Render()
}
47 changes: 47 additions & 0 deletions go/test/endtoend/cluster/vtgate_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2019 The Vitess Authors.
shlomi-noach marked this conversation as resolved.
Show resolved Hide resolved

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 cluster

import (
"context"
"testing"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// VtgateExecQuery runs a query on VTGate using given query params
func VtgateExecQuery(t *testing.T, vtParams *mysql.ConnParams, query string, expectError string) *sqltypes.Result {
t.Helper()

ctx := context.Background()
conn, err := mysql.Connect(ctx, vtParams)
require.Nil(t, err)
defer conn.Close()

qr, err := conn.ExecuteFetch(query, 1000, true)
if expectError == "" {
require.NoError(t, err)
} else {
require.Error(t, err, "error should not be nil")
assert.Contains(t, err.Error(), expectError, "Unexpected error")
}
return qr
}
77 changes: 60 additions & 17 deletions go/test/endtoend/onlineddl_ghost/onlineddl_ghost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,53 @@ var (
DROP TABLE %s`
onlineDDLDropTableIfExistsStatement = `
DROP TABLE IF EXISTS %s`

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

func fullWordUUIDRegexp(uuid, searchWord string) *regexp.Regexp {
return regexp.MustCompile(uuid + `.*?\b` + searchWord + `\b`)
}
func fullWordRegexp(searchWord string) *regexp.Regexp {
return regexp.MustCompile(`.*?\b` + searchWord + `\b`)
}
Expand Down Expand Up @@ -127,13 +169,11 @@ func TestMain(m *testing.M) {

// Start keyspace
keyspace := &cluster.Keyspace{
Name: keyspaceName,
Name: keyspaceName,
VSchema: vSchema,
}

if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, true); err != nil {
return 1, err
}
if err := clusterInstance.StartKeyspace(*keyspace, []string{"1"}, 1, false); err != nil {
if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, false); err != nil {
return 1, err
}

Expand Down Expand Up @@ -317,15 +357,18 @@ func checkTablesCount(t *testing.T, tablet *cluster.Vttablet, showTableName stri
// +------------------+-------+--------------+----------------------+--------------------------------------+----------+---------------------+---------------------+------------------+

func checkRecentMigrations(t *testing.T, uuid string, expectStatus schema.OnlineDDLStatus) {
result, err := clusterInstance.VtctlclientProcess.OnlineDDLShowRecent(keyspaceName)
assert.NoError(t, err)
fmt.Println("# 'vtctlclient OnlineDDL show recent' output (for debug purposes):")
fmt.Println(result)
assert.Equal(t, len(clusterInstance.Keyspaces[0].Shards), strings.Count(result, uuid))
// We ensure "full word" regexp becuase some column names may conflict
expectStatusRegexp := fullWordUUIDRegexp(uuid, string(expectStatus))
m := expectStatusRegexp.FindAllString(result, -1)
assert.Equal(t, len(clusterInstance.Keyspaces[0].Shards), len(m))
showQuery := fmt.Sprintf("show vitess_migrations like '%s'", uuid)
r := cluster.VtgateExecQuery(t, &vtParams, showQuery, "")
fmt.Printf("# output for `%s`:\n", showQuery)
cluster.PrintQueryResult(os.Stdout, r)

count := 0
for _, row := range r.Named().Rows {
if row["migration_uuid"].ToString() == uuid && row["migration_status"].ToString() == string(expectStatus) {
count++
}
}
assert.Equal(t, len(clusterInstance.Keyspaces[0].Shards), count)
}

// checkCancelMigration attempts to cancel a migration, and expects rejection
Expand Down
36 changes: 13 additions & 23 deletions go/test/endtoend/onlineddl_revert/onlineddl_revert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"math/rand"
"os"
"path"
"regexp"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -142,10 +141,6 @@ const (
maxConcurrency = 5
)

func fullWordUUIDRegexp(uuid, searchWord string) *regexp.Regexp {
return regexp.MustCompile(uuid + `.*?\b` + searchWord + `\b`)
}

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
Expand Down Expand Up @@ -186,10 +181,7 @@ func TestMain(m *testing.M) {
}

// No need for replicas in this stress test
if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 0, false); err != nil {
return 1, err
}
if err := clusterInstance.StartKeyspace(*keyspace, []string{"1"}, 1, false); err != nil {
if err := clusterInstance.StartKeyspace(*keyspace, []string{"1"}, 0, false); err != nil {
return 1, err
}

Expand Down Expand Up @@ -539,20 +531,18 @@ func checkTablesCount(t *testing.T, tablet *cluster.Vttablet, showTableName stri
// +------------------+-------+--------------+-------------+--------------------------------------+----------+---------------------+---------------------+------------------+

func checkRecentMigrations(t *testing.T, uuid string, expectStatus schema.OnlineDDLStatus) {
result, err := clusterInstance.VtctlclientProcess.OnlineDDLShowRecent(keyspaceName)
assert.NoError(t, err)
fmt.Println("# 'vtctlclient OnlineDDL show recent' output (for debug purposes):")
fmt.Println(result)
assert.Equal(t, len(clusterInstance.Keyspaces[0].Shards), strings.Count(result, uuid))
// We ensure "full word" regexp because some column names may conflict
expectStatusRegexp := fullWordUUIDRegexp(uuid, string(expectStatus))
m := expectStatusRegexp.FindAllString(result, -1)
assert.Equal(t, len(clusterInstance.Keyspaces[0].Shards), len(m))

result, err = clusterInstance.VtctlclientProcess.VExec(keyspaceName, uuid, `select migration_status, message from _vt.schema_migrations`)
assert.NoError(t, err)
fmt.Println("# 'vtctlclient VExec' output (for debug purposes):")
fmt.Println(result)
showQuery := fmt.Sprintf("show vitess_migrations like '%s'", uuid)
r := cluster.VtgateExecQuery(t, &vtParams, showQuery, "")
fmt.Printf("# output for `%s`:\n", showQuery)
cluster.PrintQueryResult(os.Stdout, r)

count := 0
for _, row := range r.Named().Rows {
if row["migration_uuid"].ToString() == uuid && row["migration_status"].ToString() == string(expectStatus) {
count++
}
}
assert.Equal(t, len(clusterInstance.Keyspaces[0].Shards), count)
}

// checkMigratedTables checks the CREATE STATEMENT of a table after migration
Expand Down
Loading