Skip to content

Commit

Permalink
conn: add skip preapre for control queries (#1412)
Browse files Browse the repository at this point in the history
Control queries only ever do reads on system tables but AWS MCS treats a
prepare as write which it blocks on system tables. We can avoid doing
preapres on selects as long as we get the result metadata.
  • Loading branch information
Zariel authored Feb 28, 2020
1 parent cd92c54 commit cd4b606
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) *Iter {
info *preparedStatment
)

if qry.shouldPrepare() {
if !qry.skipPrepare && qry.shouldPrepare() {
// Prepare all DML queries. Other queries can not be prepared.
var err error
info, err = c.prepareStatement(ctx, qry.stmt, qry.trace)
Expand Down Expand Up @@ -1361,6 +1361,8 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
func (c *Conn) query(ctx context.Context, statement string, values ...interface{}) (iter *Iter) {
q := c.session.Query(statement, values...).Consistency(One)
q.trace = nil
q.skipPrepare = true
q.disableSkipMetadata = true
return c.executeQuery(ctx, q)
}

Expand Down
4 changes: 4 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ type Query struct {

// getKeyspace is field so that it can be overriden in tests
getKeyspace func() string

// used by control conn queries to prevent triggering a write to systems
// tables in AWS MCS see
skipPrepare bool
}

func (q *Query) defaultsFromSession() {
Expand Down

0 comments on commit cd4b606

Please sign in to comment.