-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
vreplication: reference tables #4839
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,8 @@ const ( | |
SelectNext | ||
// SelectDBA is for executing a DBA statement. | ||
SelectDBA | ||
// SelectReference is for fetching from a reference table. | ||
SelectReference | ||
) | ||
|
||
var routeName = map[RouteOpcode]string{ | ||
|
@@ -181,6 +183,7 @@ var routeName = map[RouteOpcode]string{ | |
SelectScatter: "SelectScatter", | ||
SelectNext: "SelectNext", | ||
SelectDBA: "SelectDBA", | ||
SelectReference: "SelectReference", | ||
} | ||
|
||
var ( | ||
|
@@ -212,16 +215,13 @@ func (route *Route) Execute(vcursor VCursor, bindVars map[string]*querypb.BindVa | |
} | ||
|
||
func (route *Route) execute(vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) { | ||
switch route.Opcode { | ||
case SelectNext, SelectDBA: | ||
return execAnyShard(vcursor, route.Query, bindVars, route.Keyspace) | ||
} | ||
|
||
var rss []*srvtopo.ResolvedShard | ||
var bvs []map[string]*querypb.BindVariable | ||
var err error | ||
switch route.Opcode { | ||
case SelectUnsharded, SelectScatter: | ||
case SelectUnsharded, SelectNext, SelectDBA, SelectReference: | ||
rss, bvs, err = route.paramsAnyShard(vcursor, bindVars) | ||
case SelectScatter: | ||
rss, bvs, err = route.paramsAllShards(vcursor, bindVars) | ||
case SelectEqual, SelectEqualUnique: | ||
rss, bvs, err = route.paramsSelectEqual(vcursor, bindVars) | ||
|
@@ -278,7 +278,9 @@ func (route *Route) StreamExecute(vcursor VCursor, bindVars map[string]*querypb. | |
defer cancel() | ||
} | ||
switch route.Opcode { | ||
case SelectUnsharded, SelectScatter: | ||
case SelectUnsharded, SelectNext, SelectDBA, SelectReference: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is adding SelectNext and SelectDBA here enabled by vreplication, or is this an incidental change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are essentially unreachable code paths or impractical use cases. But I decided to add these for the sake of correctness and completeness. Otherwise, it becomes hard to reason about why these got left out. |
||
rss, bvs, err = route.paramsAnyShard(vcursor, bindVars) | ||
case SelectScatter: | ||
rss, bvs, err = route.paramsAllShards(vcursor, bindVars) | ||
case SelectEqual, SelectEqualUnique: | ||
rss, bvs, err = route.paramsSelectEqual(vcursor, bindVars) | ||
|
@@ -343,6 +345,18 @@ func (route *Route) paramsAllShards(vcursor VCursor, bindVars map[string]*queryp | |
return rss, multiBindVars, nil | ||
} | ||
|
||
func (route *Route) paramsAnyShard(vcursor VCursor, bindVars map[string]*querypb.BindVariable) ([]*srvtopo.ResolvedShard, []map[string]*querypb.BindVariable, error) { | ||
rss, _, err := vcursor.ResolveDestinations(route.Keyspace.Name, nil, []key.Destination{key.DestinationAnyShard{}}) | ||
if err != nil { | ||
return nil, nil, vterrors.Wrap(err, "paramsAnyShard") | ||
} | ||
multiBindVars := make([]map[string]*querypb.BindVariable, len(rss)) | ||
for i := range multiBindVars { | ||
multiBindVars[i] = bindVars | ||
} | ||
return rss, multiBindVars, nil | ||
} | ||
|
||
func (route *Route) paramsSelectEqual(vcursor VCursor, bindVars map[string]*querypb.BindVariable) ([]*srvtopo.ResolvedShard, []map[string]*querypb.BindVariable, error) { | ||
key, err := route.Values[0].ResolveValue(bindVars) | ||
if err != nil { | ||
|
@@ -453,20 +467,6 @@ func resolveSingleShard(vcursor VCursor, vindex vindexes.Vindex, keyspace *vinde | |
return rss[0], ksid, nil | ||
} | ||
|
||
func execAnyShard(vcursor VCursor, query string, bindVars map[string]*querypb.BindVariable, keyspace *vindexes.Keyspace) (*sqltypes.Result, error) { | ||
rss, _, err := vcursor.ResolveDestinations(keyspace.Name, nil, []key.Destination{key.DestinationAnyShard{}}) | ||
if err != nil { | ||
// TODO(alainjobart): this eats the error code. Use vterrors.Wrapf instead. | ||
// And audit the entire file for it. | ||
return nil, fmt.Errorf("execAnyShard: %v", err) | ||
} | ||
if len(rss) != 1 { | ||
// This code is unreachable. It's just a sanity check. | ||
return nil, fmt.Errorf("no shards for keyspace: %s", keyspace.Name) | ||
} | ||
return vcursor.ExecuteStandalone(query, bindVars, rss[0]) | ||
} | ||
|
||
func execShard(vcursor VCursor, query string, bindVars map[string]*querypb.BindVariable, rs *srvtopo.ResolvedShard, isDML, canAutocommit bool) (*sqltypes.Result, error) { | ||
autocommit := canAutocommit && vcursor.AutocommitApproval() | ||
result, errs := vcursor.ExecuteMultiShard([]*srvtopo.ResolvedShard{rs}, []*querypb.BoundQuery{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this actually work earlier? I would have expected it to throw an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worked earlier, and two users ran into issues when they accidentally deployed sequences on a sharded keyspace. So, I fixed it as part of this change.