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

query routing: multi-table plan options #4833

Merged
merged 7 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion go/cmd/topo2topo/topo2topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
doShards = flag.Bool("do-shards", false, "copies the shard information")
doShardReplications = flag.Bool("do-shard-replications", false, "copies the shard replication information")
doTablets = flag.Bool("do-tablets", false, "copies the tablet information")
doRoutingRules = flag.Bool("do-routing-rules", false, "copies the routing rules")
)

func main() {
Expand Down Expand Up @@ -87,7 +88,9 @@ func copyTopos(ctx context.Context, fromTS, toTS *topo.Server) {
if *doTablets {
helpers.CopyTablets(ctx, fromTS, toTS)
}

if *doRoutingRules {
helpers.CopyRoutingRules(ctx, fromTS, toTS)
}
}

func compareTopos(ctx context.Context, fromTS, toTS *topo.Server) {
Expand Down
198 changes: 151 additions & 47 deletions go/vt/proto/vschema/vschema.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func (node *Stream) walkSubtree(visit Visit) error {
// the row and re-inserts with new values. For that reason we keep it as an Insert struct.
// Replaces are currently disallowed in sharded schemas because
// of the implications the deletion part may have on vindexes.
// If you add fields here, consider adding them to calls to validateSubquerySamePlan.
// If you add fields here, consider adding them to calls to validateUnshardedRoute.
type Insert struct {
Action string
Comments Comments
Expand Down Expand Up @@ -584,7 +584,7 @@ func (Values) iInsertRows() {}
func (*ParenSelect) iInsertRows() {}

// Update represents an UPDATE statement.
// If you add fields here, consider adding them to calls to validateSubquerySamePlan.
// If you add fields here, consider adding them to calls to validateUnshardedRoute.
type Update struct {
Comments Comments
Ignore string
Expand Down Expand Up @@ -618,7 +618,7 @@ func (node *Update) walkSubtree(visit Visit) error {
}

// Delete represents a DELETE statement.
// If you add fields here, consider adding them to calls to validateSubquerySamePlan.
// If you add fields here, consider adding them to calls to validateUnshardedRoute.
type Delete struct {
Comments Comments
Targets TableNames
Expand Down
17 changes: 17 additions & 0 deletions go/vt/topo/helpers/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package helpers
import (
"reflect"

"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/topo"
Expand Down Expand Up @@ -179,3 +180,19 @@ func CompareShardReplications(ctx context.Context, fromTS, toTS *topo.Server) er
}
return nil
}

// CompareRoutingRules will compare the routing rules in the destination topo.
func CompareRoutingRules(ctx context.Context, fromTS, toTS *topo.Server) error {
rrFrom, err := fromTS.GetRoutingRules(ctx)
if err != nil {
return vterrors.Wrapf(err, "GetKeyspace(from)")
}
rrTo, err := toTS.GetRoutingRules(ctx)
if err != nil {
return vterrors.Wrapf(err, "GetKeyspace(to)")
}
if !proto.Equal(rrFrom, rrTo) {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "routing rules: %v does not match %v", rrFrom, rrTo)
}
return nil
}
12 changes: 12 additions & 0 deletions go/vt/topo/helpers/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ func TestBasicCompare(t *testing.T) {
if err != nil {
t.Fatalf("Compare tablets failed: %v", err)
}

err = CompareRoutingRules(ctx, fromTS, toTS)
if err == nil {
t.Fatalf("Compare routing rules is not failing when topos are not in sync")
}

CopyRoutingRules(ctx, fromTS, toTS)

err = CompareRoutingRules(ctx, fromTS, toTS)
if err != nil {
t.Fatalf("Compare routing rules failed: %v", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should test here that routing rules are the same after Copy.

11 changes: 11 additions & 0 deletions go/vt/topo/helpers/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,14 @@ func CopyShardReplications(ctx context.Context, fromTS, toTS *topo.Server) {
}
}
}

// CopyRoutingRules will create the routing rules in the destination topo.
func CopyRoutingRules(ctx context.Context, fromTS, toTS *topo.Server) {
rr, err := fromTS.GetRoutingRules(ctx)
if err != nil {
log.Fatalf("GetRoutingRules: %v", err)
}
if err := toTS.SaveRoutingRules(ctx, rr); err != nil {
log.Errorf("SaveRoutingRules(%v): %v", rr, err)
}
}
Loading