Skip to content

Commit

Permalink
Update Cleanup and docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hengfengli committed Aug 19, 2020
1 parent 0a6efd7 commit 614865e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
20 changes: 4 additions & 16 deletions spanner/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"encoding/gob"
"log"
"time"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -219,27 +218,16 @@ func (t *BatchReadOnlyTransaction) Close() {
// usable anywhere, including other clients/processes with which this
// transaction was shared.
//
// Calling Cleanup is optional, but recommended. If Cleanup is not called, the
// transaction's resources will be freed when the session expires on the backend
// and is deleted. For more information about recycled sessions, see
// https://cloud.google.com/spanner/docs/sessions.
// We must call Cleanup to free the session. Otherwise, the session will not be
// returned to the session pool, which leads to a session leak.
func (t *BatchReadOnlyTransaction) Cleanup(ctx context.Context) {
t.Close()
t.mu.Lock()
defer t.mu.Unlock()
sh := t.sh
if sh == nil {
return
}
t.sh = nil
sid, client := sh.getID(), sh.getClient()
err := client.DeleteSession(contextWithOutgoingMetadata(ctx, sh.getMetadata()), &sppb.DeleteSessionRequest{Name: sid})
if err != nil {
var logger *log.Logger
if sh.session != nil {
logger = sh.session.logger
}
logf(logger, "Failed to delete session %v. Error: %v", sid, err)
if sh != nil {
sh.recycle()
}
}

Expand Down
3 changes: 0 additions & 3 deletions spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ func (c *Client) ReadOnlyTransaction() *ReadOnlyTransaction {
// useful in batch processing pipelines where one wants to divide the work of
// reading from the database across multiple machines.
//
// Note: This transaction does not use the underlying session pool but creates a
// new session each time, and the session is reused across clients.
//
// You should call Close() after the txn is no longer needed on local
// client, and call Cleanup() when the txn is finished for all clients, to free
// the session.
Expand Down

0 comments on commit 614865e

Please sign in to comment.