Skip to content

Transaction BEGIN statements should use the query timeout rather than…#5238

Merged
sougou merged 1 commit intovitessio:masterfrom
dasl-:begin-timeout
Oct 19, 2019
Merged

Transaction BEGIN statements should use the query timeout rather than…#5238
sougou merged 1 commit intovitessio:masterfrom
dasl-:begin-timeout

Conversation

@dasl-
Copy link
Member

@dasl- dasl- commented Sep 26, 2019

… the transaction pool timeout. According to docs: "query server transaction pool timeout, it is how long vttablet waits if tx pool is full (default 1)". When we execute the BEGIN statment, we have already grabbed a connection from the transaction pool. Thus it does not make sense to use the transaction pool timeout here. Furthermore, this makes BEGIN behave more like COMMIT -- they will both use the query timeout now.

At Etsy, we have our TxPoolTimeout set relatively low (one second), whereas we have an unlimited query timeout. We were seeing timeouts occur here for the BEGIN statement:

return nil, fmt.Errorf("%v before execution started", ctx.Err())

It's still an open question why one second was not enough (it should have been).

@dasl- dasl- requested a review from sougou as a code owner September 26, 2019 21:55
@dasl- dasl- force-pushed the begin-timeout branch 2 times, most recently from e5e5049 to bdfd194 Compare October 1, 2019 19:01
@sougou
Copy link
Contributor

sougou commented Oct 5, 2019

I think you misunderstood: the tabletserver BeginTimeout is (mostly) the time it takes to get a connection from the tx pool. If you drill down into the call graph, you'll see that this timeout is eventually used here: https://github.com/vitessio/vitess/blob/master/go/vt/vttablet/tabletserver/tx_pool.go#L236.

Basically, the Begin call is the one that allocates a connection for the transaction.

SREs wanted a different timeout for this because applications want to fail fast if they're not able to begin a transaction, whereas a query can reasonably take longer to complete because it has to do more work accessing the necessary data.

@dasl-
Copy link
Member Author

dasl- commented Oct 7, 2019

@sougou that makes sense. Previously, the BeginTimeout was used for two things:

  1. As you mentioned, getting a connection from the transaction pool:
    conn, err = axp.conns.Get(ctx)
  2. It is also used for executing the actual BEGIN statement:
    if _, err := conn.Exec(ctx, queries.openTransaction, 1, false); err != nil {

Thanks for pointing out (1) -- I missed that.

The intention of this PR is to use the TxPoolTimeout solely for (1) and to use the query timeout for (2).

@dasl- dasl- force-pushed the begin-timeout branch 3 times, most recently from 5ad67c4 to 98394e2 Compare October 8, 2019 14:53
Copy link
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

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

I see what you're trying to do, and I like this approach. The improvement I'd suggest is to delete BeginTimeout and use QueryTimeout everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch. We shoudl add a test for TransactionTimeout.

Copy link
Contributor

Choose a reason for hiding this comment

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

And one for TxPoolTimeout here.

@dasl- dasl- force-pushed the begin-timeout branch 2 times, most recently from ab6fd20 to 9603130 Compare October 14, 2019 21:42
When grabbing a connection from the transaction pool, we should use the queryserver-config-txpool-timeout.

BEGIN statements should not use the queryserver-config-txpool-timeout when executing the BEGIN query.

Signed-off-by: dleibovic <dleibovic@etsy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants