Skip to content

Commit

Permalink
Merge pull request #10298 from knz/fix-retry-release
Browse files Browse the repository at this point in the history
sql: release discarded results from retried queries
  • Loading branch information
knz authored Oct 28, 2016
2 parents d2d3c7f + 8106979 commit 539acae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/sql/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ type StatementResults struct {

// Close ensures that the resources claimed by the results are released.
func (s *StatementResults) Close() {
for _, r := range s.ResultList {
s.ResultList.Close()
}

// Close ensures that the resources claimed by the results are released.
func (rl ResultList) Close() {
for _, r := range rl {
r.Close()
}
}
Expand Down Expand Up @@ -564,6 +569,10 @@ func (e *Executor) execRequest(session *Session, sql string, copymsg copyMsg) St
}

var err error
if results != nil {
// Some results were produced by a previous attempt. Discard them.
ResultList(results).Close()
}
results, remainingStmts, err = runTxnAttempt(e, planMaker, origState, txnState, opt, stmtsToExec)

// TODO(andrei): Until #7881 fixed.
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/txn_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,21 @@ CREATE TABLE t.test (k INT PRIMARY KEY, v TEXT, t DECIMAL);
// of txns (statements batched together with the BEGIN stmt) - are retried.
// We also exercise the SQL cluster logical timestamp in here, because
// this must be properly propagated across retries.
//
// The SELECT within the transaction also checks that discarded
// intermediate result sets are properly released: the result set it
// produces is accounted for by the session monitor, and if it is
// not properly released upon a retry the monitor will cause the
// server to panic (and thus the test to fail) when the connection
// is closed.
//
// TODO(knz) This test can be made more robust by exposing the
// current allocation count in monitor and checking that it has the
// same value at the beginning of each retry.
if _, err := sqlDB.Exec(`
INSERT INTO t.test(k, v, t) VALUES (1, 'boulanger', cluster_logical_timestamp());
BEGIN;
SELECT * FROM t.test;
INSERT INTO t.test(k, v, t) VALUES (2, 'dromedary', cluster_logical_timestamp());
INSERT INTO t.test(k, v, t) VALUES (3, 'fajita', cluster_logical_timestamp());
END;
Expand Down

0 comments on commit 539acae

Please sign in to comment.