Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: remove goCtx from session struct #5174

Merged
merged 8 commits into from
Nov 22, 2017

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Nov 21, 2017

  1. go context should not be stored
  2. change Executor interface to Open(goctx.Context)
  3. many other related changes forced by this refactor

Some side effect introduced in this COMMIT:

  1. builtin function Sleep() is broken, we can't cancel it right now.
  2. some executor maybe not cancelable, because the break of context chain.

I'll fix them in the following PRs.

@coocood

1. go context should not be stored
2. change Executor interface to Open(goctx.Context)
3. many other changes forced by this refactor
@tiancaiamao
Copy link
Contributor Author

tidb-test may also need update as a result of the change of some interfaces.

ast/ast.go Outdated
@@ -182,7 +182,7 @@ type Statement interface {
OriginText() string

// Exec executes SQL and gets a Recordset.
Exec(ctx context.Context) (RecordSet, error)
Exec(goCtx goctx.Context, ctx context.Context) (RecordSet, error)
Copy link
Member

Choose a reason for hiding this comment

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

Seems we don't need the second context.Context.
The Statement has one in its struct.

@@ -167,7 +168,7 @@ func (a *ExecStmt) IsReadOnly() bool {
// This function builds an Executor from a plan. If the Executor doesn't return result,
// like the INSERT, UPDATE statements, it executes in this function, if the Executor returns
// result, execution is done after this function returns, in the returned ast.RecordSet Next method.
func (a *ExecStmt) Exec(ctx context.Context) (ast.RecordSet, error) {
func (a *ExecStmt) Exec(goCtx goctx.Context, ctx context.Context) (ast.RecordSet, error) {
Copy link
Member

Choose a reason for hiding this comment

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

The second ctx can be removed.
We can set ctx of ExecStmt at creation time.

span1 := opentracing.StartSpan("executor.Compile", opentracing.ChildOf(span.Context()))
defer span1.Finish()
}
func (c *Compiler) Compile(goCtx goctx.Context, ctx context.Context, stmtNode ast.StmtNode) (*ExecStmt, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the second ctx, add it to the field of Compiler.

session.go Outdated
// goCtx is used for cancelling the execution of current transaction.
goCtx goctx.Context

// cancelFunc is used for cancelling the execution of current transaction.
cancelFunc goctx.CancelFunc
Copy link
Member

Choose a reason for hiding this comment

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

The cancelFunc may be accessed by another goroutine. Need to be protected by mutex.

executor/join.go Outdated
@@ -198,8 +199,8 @@ func (e *HashJoinExec) fetchOuterRows() {
}

select {
case <-e.ctx.GoCtx().Done():
return
// case <-e.ctx.GoCtx().Done():
Copy link
Member

Choose a reason for hiding this comment

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

why comment out these lines ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because ctx.GoCtx() method is removed, and we can't get a context to cancel the calculation.
As I've said

  1. some executor maybe not cancelable, because the break of context chain.

It will be fix in next PR soon, if Next() changed to Next(goctx.Context).
Comment the code rather than remove them, I can find it more easy next time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because ctx.GoCtx() method is removed, and we can't get a context to cancel the calculation.
As I've said

  1. some executor maybe not cancelable, because the break of context chain.

It will be fix in next PR soon, if Next() changed to Next(goctx.Context).
Comment the code rather than remove them, I can find it more easy next time.

@coocood
Copy link
Member

coocood commented Nov 22, 2017

LGTM

@coocood coocood added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 22, 2017
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 22, 2017
@tiancaiamao tiancaiamao merged commit 02f6bb2 into pingcap:master Nov 22, 2017
@tiancaiamao tiancaiamao deleted the remove-session-ctx branch November 22, 2017 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants