Skip to content

Commit

Permalink
Merge pull request #7071 from planetscale/rn-switch-order
Browse files Browse the repository at this point in the history
New VReplication workflows cli UX. Allow reads/writes to be switched independently
  • Loading branch information
rohit-nayak-ps authored Jan 3, 2021
2 parents 1300808 + 4b8eb39 commit 337e40b
Show file tree
Hide file tree
Showing 29 changed files with 2,552 additions and 368 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require (
github.com/klauspost/pgzip v1.2.4
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/krishicks/yaml-patch v0.0.10
github.com/looplab/fsm v0.2.0
github.com/magiconair/properties v1.8.1
github.com/martini-contrib/auth v0.0.0-20150219114609-fa62c19b7ae8
github.com/martini-contrib/gzip v0.0.0-20151124214156-6c035326b43f
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/krishicks/yaml-patch v0.0.10 h1:H4FcHpnNwVmw8u0MjPRjWyIXtco6zM2F78t+57oNM3E=
github.com/krishicks/yaml-patch v0.0.10/go.mod h1:Sm5TchwZS6sm7RJoyg87tzxm2ZcKzdRE4Q7TjNhPrME=
github.com/looplab/fsm v0.2.0 h1:M8hf5EF4AYLcT1FNKVUX8nu7D0xfp291iGeuigSxfrw=
github.com/looplab/fsm v0.2.0/go.mod h1:p+IElwgCnAByqr2DWMuNbPjgMwqcHvTRZZn3dvKEke0=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
Expand Down
4 changes: 4 additions & 0 deletions go/cmd/vtctlclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package main
import (
"errors"
"flag"
"fmt"
"os"
"strings"
"time"

"golang.org/x/net/context"
Expand Down Expand Up @@ -64,6 +66,8 @@ func main() {
logutil.LogEvent(logger, e)
})
if err != nil {
errStr := strings.Replace(err.Error(), "remote error: ", "", -1)
fmt.Printf("%s Error: %s\n", flag.Arg(0), errStr)
log.Error(err)
os.Exit(1)
}
Expand Down
3 changes: 2 additions & 1 deletion go/test/endtoend/vreplication/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

var (
debug = false // set to true to always use local env vtdataroot for local debugging
debug = false // set to true to always use local env vtdataroot for local debugging

originalVtdataroot string
vtdataroot string
)
Expand Down
22 changes: 20 additions & 2 deletions go/test/endtoend/vreplication/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ var (
initialProductSchema = `
create table product(pid int, description varbinary(128), primary key(pid));
create table customer(cid int, name varbinary(128), typ enum('individual','soho','enterprise'), sport set('football','cricket','baseball'),ts timestamp not null default current_timestamp, primary key(cid));
create table customer_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
create table merchant(mname varchar(128), category varchar(128), primary key(mname)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
create table orders(oid int, cid int, pid int, mname varchar(128), price int, primary key(oid));
create table customer_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
create table order_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
create table customer2(cid int, name varbinary(128), typ enum('individual','soho','enterprise'), sport set('football','cricket','baseball'),ts timestamp not null default current_timestamp, primary key(cid));
create table customer_seq2(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
`

initialProductVSchema = `
{
"tables": {
"product": {},
"customer": {},
"merchant": {},
"orders": {},
"customer": {},
"customer_seq": {
"type": "sequence"
},
"customer2": {},
"customer_seq2": {
"type": "sequence"
},
"order_seq": {
"type": "sequence"
}
Expand Down Expand Up @@ -47,6 +53,18 @@ create table order_seq(id int, next_id bigint, cache bigint, primary key(id)) co
"column": "cid",
"sequence": "customer_seq"
}
},
"customer2": {
"column_vindexes": [
{
"column": "cid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "cid",
"sequence": "customer_seq2"
}
}
}
Expand Down
29 changes: 24 additions & 5 deletions go/test/endtoend/vreplication/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/buger/jsonparser"
"github.com/stretchr/testify/require"

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

Expand Down Expand Up @@ -145,13 +144,16 @@ func getQueryCount(url string, query string) int {
if len(row) != len(headings) {
continue
}
filterChars := []string{"_", "`"}
//Queries seem to include non-printable characters at times and hence equality fails unless these are removed
re := regexp.MustCompile("[[:^ascii:]]")
foundQuery := re.ReplaceAllLiteralString(row[queryIndex], "")
foundQuery = strings.ReplaceAll(foundQuery, "_", "")
cleanQuery := re.ReplaceAllLiteralString(query, "")
cleanQuery = strings.ReplaceAll(cleanQuery, "_", "")
if foundQuery == cleanQuery {
for _, filterChar := range filterChars {
foundQuery = strings.ReplaceAll(foundQuery, filterChar, "")
cleanQuery = strings.ReplaceAll(cleanQuery, filterChar, "")
}
if foundQuery == cleanQuery || strings.Contains(foundQuery, cleanQuery) {
count, _ = strconv.Atoi(row[countIndex])
}
}
Expand Down Expand Up @@ -239,3 +241,20 @@ func printShardPositions(vc *VitessCluster, ksShards []string) {
}
}
}

func clearRoutingRules(t *testing.T, vc *VitessCluster) error {
if _, err := vc.VtctlClient.ExecuteCommandWithOutput("ApplyRoutingRules", "-rules={}"); err != nil {
return err
}
return nil
}

func printRoutingRules(t *testing.T, vc *VitessCluster, msg string) error {
var output string
var err error
if output, err = vc.VtctlClient.ExecuteCommandWithOutput("GetRoutingRules"); err != nil {
return err
}
fmt.Printf("Routing Rules::%s:\n%s\n", msg, output)
return nil
}
Loading

0 comments on commit 337e40b

Please sign in to comment.