Skip to content

sql: Temporarily revert per-statement context forking to address memory leak#17200

Merged
itsbilal merged 1 commit intocockroachdb:masterfrom
itsbilal:query-context-fork-revert
Jul 24, 2017
Merged

sql: Temporarily revert per-statement context forking to address memory leak#17200
itsbilal merged 1 commit intocockroachdb:masterfrom
itsbilal:query-context-fork-revert

Conversation

@itsbilal
Copy link
Copy Markdown
Contributor

Original PR: #17003

Not cancelling the context right after forking it was causing a memory leak. Simply cancelling the context after every statement doesn't work, since the heartbeat loop detects it and prematurely aborts the transaction (see the comment here).

While I work on a fix, here's a direct revert of just that part of the PR.

@itsbilal itsbilal self-assigned this Jul 24, 2017
@itsbilal itsbilal requested a review from petermattis July 24, 2017 21:23
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

LGTM

This doesn't cause any tests to fail? Seems like there is a hole in the testing of cancellation.

// Fork context for this statement.
queryMeta.ctx, queryMeta.cancel = context.WithCancel(session.Ctx())
// TODO(itsbilal): Fork a statement-specific context here, that gets cancelled
// upon request by user.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As mentioned privately, perhaps we should create a new context whenever a transaction starts.

@itsbilal
Copy link
Copy Markdown
Contributor Author

@petermattis Cancellation still works because CANCEL QUERY sets a flag in addition to cancelling the associated context, and most cancellation checks in planNodes check for that flag in addition to the context. I didn't write tests for context-cancellation-only cases since we don't expect them to happen in practice, hence the test success.

@itsbilal itsbilal merged commit 20b5f0d into cockroachdb:master Jul 24, 2017
@itsbilal itsbilal deleted the query-context-fork-revert branch July 24, 2017 21:52
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Jul 27, 2017
This reverts some of the changes made in PRs cockroachdb#17003 and cockroachdb#17200. In
particular:

17003 made new contexts for every statement, but didn't cancel them
after statement execution, resulting in a memory leak.
17200 did a quick-fix for that memory leak by not forking that context,
at the expense of not being able to leverage the context in
cancellation.

This PR restores the context cancellation behaviour introduced in cockroachdb#17003
, except at the transaction level - cancelling a query closes its
transaction's context.
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Jul 27, 2017
This reverts some of the changes made in PRs cockroachdb#17003 and cockroachdb#17200. In
particular:

17003 made new contexts for every statement, but didn't cancel them
after statement execution, resulting in a memory leak.
17200 did a quick-fix for that memory leak by not forking that context,
at the expense of not being able to leverage the context in
cancellation.

This PR restores the context cancellation behaviour introduced in cockroachdb#17003
, except at the transaction level - cancelling a query closes its
transaction's context.
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Jul 31, 2017
This reverts some of the changes made in PRs cockroachdb#17003 and cockroachdb#17200. In
particular:

17003 made new contexts for every statement, but didn't cancel them
after statement execution, resulting in a memory leak.
17200 did a quick-fix for that memory leak by not forking that context,
at the expense of not being able to leverage the context in
cancellation.

This PR restores the context cancellation behaviour introduced in cockroachdb#17003
, except at the transaction level - cancelling a query closes its
transaction's context.
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Aug 1, 2017
This reverts some of the changes made in PRs cockroachdb#17003 and cockroachdb#17200. In
particular:

17003 made new contexts for every statement, but didn't cancel them
after statement execution, resulting in a memory leak.
17200 did a quick-fix for that memory leak by not forking that context,
at the expense of not being able to leverage the context in
cancellation.

This PR restores the context cancellation behaviour introduced in cockroachdb#17003
, except at the transaction level - cancelling a query closes its
transaction's context.
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.

3 participants