Skip to content

Commit

Permalink
allow query timeout hints on shard targeting
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed May 9, 2024
1 parent b57ccd7 commit d3076f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion go/vt/vtgate/engine/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type Send struct {
MultishardAutocommit bool

ReservedConnectionNeeded bool

// QueryTimeout contains the optional timeout (in milliseconds) to apply to this query
QueryTimeout int
}

// ShardName as key for setting shard name in bind variables map
Expand Down Expand Up @@ -88,7 +91,7 @@ func (s *Send) GetTableName() string {

// TryExecute implements Primitive interface
func (s *Send) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
ctx, cancelFunc := addQueryTimeout(ctx, vcursor, 0)
ctx, cancelFunc := addQueryTimeout(ctx, vcursor, s.QueryTimeout)
defer cancelFunc()

rss, err := s.checkAndReturnShards(ctx, vcursor)
Expand Down Expand Up @@ -192,6 +195,7 @@ func (s *Send) description() PrimitiveDescription {
"ShardNameNeeded": s.ShardNameNeeded,
"MultishardAutocommit": s.MultishardAutocommit,
"ReservedConnectionNeeded": s.ReservedConnectionNeeded,
"QueryTimeout": s.QueryTimeout,
}
return PrimitiveDescription{
OperatorType: "Send",
Expand Down
10 changes: 9 additions & 1 deletion go/vt/vtgate/planbuilder/bypass.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ func buildPlanForBypass(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vsc
}
}

hints := &queryHints{}
if comments, ok := stmt.(sqlparser.Commented); ok {
if qh := getHints(comments.GetParsedComments()); qh != nil {
hints = qh
}
}

send := &engine.Send{
Keyspace: keyspace,
TargetDestination: vschema.Destination(),
Query: sqlparser.String(stmt),
IsDML: sqlparser.IsDMLStatement(stmt),
SingleShardOnly: false,
MultishardAutocommit: sqlparser.MultiShardAutocommitDirective(stmt),
MultishardAutocommit: hints.multiShardAutocommit,
QueryTimeout: hints.queryTimeout,
}
return newPlanResult(send), nil
}
Expand Down

0 comments on commit d3076f3

Please sign in to comment.