Skip to content

Commit

Permalink
fix(spanner): update PDML to take sessions from pool (#2736)
Browse files Browse the repository at this point in the history
* fix(spanner): update PDML to take sessions from pool
  • Loading branch information
hengfengli authored Aug 24, 2020
1 parent 5d56e13 commit e658318
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
17 changes: 6 additions & 11 deletions spanner/pdml.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,15 @@ func (c *Client) partitionedUpdate(ctx context.Context, statement Statement, opt
if err := checkNestedTxn(ctx); err != nil {
return 0, err
}
var (
s *session
sh *sessionHandle
)
// Create session.
s, err = c.sc.createSession(ctx)

sh, err := c.idleSessions.take(ctx)
if err != nil {
return 0, toSpannerError(err)
}
// Delete the session at the end of the request. If the PDML statement
// timed out or was cancelled, the DeleteSession request might not succeed,
// but the session will eventually be garbage collected by the server.
defer s.delete(ctx)
sh = &sessionHandle{session: s}
if sh != nil {
defer sh.recycle()
}

// Create the parameters and the SQL request, but without a transaction.
// The transaction reference will be added by the executePdml method.
params, paramTypes, err := statement.convertParams()
Expand Down
3 changes: 1 addition & 2 deletions spanner/pdml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ func TestPartitionedUpdate_Aborted(t *testing.T) {
}

gotReqs, err := shouldHaveReceived(server.TestSpanner, []interface{}{
&sppb.CreateSessionRequest{},
&sppb.BatchCreateSessionsRequest{},
&sppb.BeginTransactionRequest{},
&sppb.ExecuteSqlRequest{},
&sppb.BeginTransactionRequest{},
&sppb.ExecuteSqlRequest{},
&sppb.BeginTransactionRequest{},
&sppb.ExecuteSqlRequest{},
&sppb.DeleteSessionRequest{},
})
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit e658318

Please sign in to comment.