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

Better handling of partial dml query exec in transaction #9269

Merged
merged 24 commits into from
Nov 29, 2021

Conversation

harshit-gangal
Copy link
Member

@harshit-gangal harshit-gangal commented Nov 19, 2021

Description

This PR reverses the effect of partial dml query execution instead of rolling back the complete transaction when the transaction is explicitly created by the user.

Related Issue(s)

Checklist

  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…erse the affect of partial dml exec

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…rmal) with correct commit order

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
harshit-gangal and others added 4 commits November 24, 2021 11:31
…ack to a savepoint

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…erriding it in nested execute calls

Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
…tant accross different vcursors

Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…ns when there is already an open transaction

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal marked this pull request as ready for review November 25, 2021 20:10
go/vt/vtgate/executor.go Outdated Show resolved Hide resolved
@@ -40,6 +40,11 @@ type SafeSession struct {
mustRollback bool
autocommitState autocommitState
commitOrder vtgatepb.CommitOrder
savepointState savepointState
// rollbackOnPartialExec is set if any DML was successfully
Copy link
Collaborator

Choose a reason for hiding this comment

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

set to what? why is this a string?

Copy link
Member Author

Choose a reason for hiding this comment

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

rollbackOnPartialExec will store the rollback to <savepoint> sql query which is generated randomly when doing MarkSavepoint.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should add ☝️ to the comment

@@ -423,6 +421,8 @@ func (vc *vcursorImpl) StreamExecutePrimitive(primitive engine.Primitive, bindVa
return vterrors.New(vtrpcpb.Code_UNAVAILABLE, "upstream shards are not available")
}

const txRollback = "Rollback Transaction"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: weird placement for a const

Copy link
Member Author

Choose a reason for hiding this comment

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

earlier it was near to usage, then the code the moved,
now moved it back to the usage.

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…ecord partial rollback query if the query even succeeds in one shard

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
go/vt/vtgate/executor_framework_test.go Outdated Show resolved Hide resolved
go/vt/vtgate/plan_execute.go Outdated Show resolved Hide resolved
go/vt/vtgate/safe_session.go Outdated Show resolved Hide resolved
go/vt/vttablet/sandboxconn/sandboxconn.go Outdated Show resolved Hide resolved
…ries

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
go/vt/vtexplain/vtexplain.go Outdated Show resolved Hide resolved
go/vt/vtgate/autocommit_test.go Outdated Show resolved Hide resolved
go/vt/vtgate/autocommit_test.go Outdated Show resolved Hide resolved
Copy link
Member

@frouioui frouioui left a comment

Choose a reason for hiding this comment

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

Looks good to me. Agreed with @systay on #9269 (comment), we should avoid the repetition in the test suite to make adding/changing tests easier

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal merged commit 9c86727 into vitessio:main Nov 29, 2021
@harshit-gangal harshit-gangal deleted the partial-exec branch November 29, 2021 18:12
}

func specialHandlingOfSavepoints(q *MysqlQuery) error {
if !strings.Contains(q.SQL, "savepoint") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can't we just skip this string check since we are looking at the type of the AST below?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just to avoid parsing overhead.

Copy link
Collaborator

@systay systay Nov 29, 2021

Choose a reason for hiding this comment

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

in vtexplain? doesn't feel like it's part of the code where we need to squeeze extra drops of performance.
¯_(ツ)_/¯

// Default state is savepointStateNotSet,
// if savepoint needed (spNeed true) then it will be set to savepointNeeded otherwise savepointNotNeeded.

func (session *SafeSession) SetSavepointState(spNeed bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment missing

Copy link
Member Author

Choose a reason for hiding this comment

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

there was extra line, comments are there :)

return len(session.ShardSessions) > 0 || len(session.PreSessions) > 0 || len(session.PostSessions) > 0
}

func (session *SafeSession) GetSessions() []*vtgatepb.Session_ShardSession {
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment missing

Copy link
Member Author

Choose a reason for hiding this comment

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

added in #9294

Copy link
Collaborator

@systay systay left a comment

Choose a reason for hiding this comment

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

I was too late to accept it, but I would have if given the chance :)

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Rollback of partial failed query in an explicit transaction
4 participants