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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package onlineddl
package ghost

import (
"context"
Expand All @@ -33,6 +33,7 @@ import (
"vitess.io/vitess/go/vt/schema"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/onlineddl"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -85,11 +86,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 +170,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 +358,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 := onlineddl.VtgateExecQuery(t, &vtParams, showQuery, "")
fmt.Printf("# output for `%s`:\n", showQuery)
onlineddl.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
61 changes: 61 additions & 0 deletions go/test/endtoend/onlineddl/query_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
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 onlineddl

import (
"io"
"strings"

"vitess.io/vitess/go/sqltypes"

"github.com/olekukonko/tablewriter"
)

// PrintQueryResult will pretty-print a QueryResult to the logger.
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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package onlineddl
package revert

import (
"context"
Expand All @@ -23,7 +23,6 @@ import (
"math/rand"
"os"
"path"
"regexp"
"strings"
"sync"
"sync/atomic"
Expand All @@ -36,6 +35,7 @@ import (
"vitess.io/vitess/go/vt/schema"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/onlineddl"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -142,10 +142,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 +182,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 +532,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 := onlineddl.VtgateExecQuery(t, &vtParams, showQuery, "")
fmt.Printf("# output for `%s`:\n", showQuery)
onlineddl.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