-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
server: support separate transactions on sql api #108447
Conversation
b1ce810
to
6a6eb1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @THardy98)
pkg/server/api_v2_sql.go
line 377 at r1 (raw file):
err = timeutil.RunWithTimeout(ctx, "run-sql-via-api", timeout, func(ctx context.Context) error { if !requestPayload.SeparateTxns { execRes, _, err := a.runSingleTxn(ctx, 0, 0, username, requestPayload, requestPayload.Statements, options)
I feel there is a lot of code duplication here.
Can you perhaps simplify the control flow a bit? Something like this:
knz@62099b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz and @THardy98)
pkg/server/api_v2_sql.go
line 209 at r1 (raw file):
Execute bool `json:"execute"` SeparateTxns bool `json:"separate_txns"` Statements []statement `json:"statements"`
Would it be better to make an array of transactions and each transaction has an array of stmts? That way it's more flexible and matches the response with multiple txns and each has multiple stmts.
6a6eb1a
to
d116a38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @knz)
pkg/server/api_v2_sql.go
line 209 at r1 (raw file):
Previously, j82w (Jake) wrote…
Would it be better to make an array of transactions and each transaction has an array of stmts? That way it's more flexible and matches the response with multiple txns and each has multiple stmts.
I agree, but I chose this approach because its additive, non-breaking and this functionality is currently blocking some other UI work. Changing the request/response format means changing the sql api UI-side and its corresponding usages.
pkg/server/api_v2_sql.go
line 377 at r1 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
I feel there is a lot of code duplication here.
Can you perhaps simplify the control flow a bit? Something like this:
knz@62099b2
Yes that's a much better idea. I've refactored to follow this instead, much smaller code diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 3 files at r1, 1 of 2 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @THardy98)
pkg/server/api_v2_sql.go
line 208 at r2 (raw file):
ApplicationName string `json:"application_name"` Execute bool `json:"execute"` SeparateTxns bool `json:"separate_txns"`
May I recommend you add another bool field StopOnError
which decides whether or not to stop subsequent txns/stmts from executing when an error is encountered.
From experience, there are valid use cases for both.
Previously, THardy98 (Thomas Hardy) wrote…
We could keep the current stmts and just add the txns property. Then in the db just treat the old stmts array as first txn. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @knz)
pkg/server/api_v2_sql.go
line 209 at r1 (raw file):
Previously, j82w (Jake) wrote…
We could keep the current stmts and just add the txns property. Then in the db just treat the old stmts array as first txn.
Yea that could work. I'm still a bit hesitant with this because we'd have to change the txnResult
shape, or more safely, introduce a new field in execResult
to hold txns that return multiple statement results, which weirdly would hold 2 fields for transaction results (one for single stmt, one for multi-stmt). WDYT? Is that fine?
Previously, THardy98 (Thomas Hardy) wrote…
nvm, I thought |
d116a38
to
e2e4448
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @knz)
pkg/server/api_v2_sql.go
line 208 at r2 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
May I recommend you add another bool field
StopOnError
which decides whether or not to stop subsequent txns/stmts from executing when an error is encountered.From experience, there are valid use cases for both.
Added.
Does the stmtErr need to be combined with the outerErr? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @knz)
pkg/server/api_v2_sql.go
line 400 at r3 (raw file):
Previously, j82w (Jake) wrote…
Does the stmtErr need to be combined with the outerErr?
I decided for the outerErr
to be a generic message when we're running separate txns. stmtErr
in this case is captured only at the stmt level. My thinking is that separate txns = separate errors, no need to capture it again at the top-level response error. I initially thought about combining stmtErr
into outerErr
but thought with an unbounded number of stmts, it can become hard to read and a bit redundant.
Previously, THardy98 (Thomas Hardy) wrote…
Does the ui show and/or log the inner stmt error? My concern is it only check if the txn fails and then stops. It doesn't bother checking the inner errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @knz)
pkg/server/api_v2_sql.go
line 400 at r3 (raw file):
Previously, j82w (Jake) wrote…
Does the ui show and/or log the inner stmt error? My concern is it only check if the txn fails and then stops. It doesn't bother checking the inner errors.
That's correct. I think this is an easy UI side change though. We can add a small change when we format responses to also log stmt-level errors. I do this in a follow-up PR handling stmt-level errors on the db page.
RFAL / any remaining feedback/thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but you also need a review approval from your team.
Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @THardy98)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @j82w and @THardy98)
TYFR |
bors r+ |
Build failed (retrying...): |
Build failed (retrying...): |
Build failed (retrying...): |
bors r- The CI failure indicates a real problem. |
Canceled. |
You should filter out the |
e2e4448
to
629ecd6
Compare
Done. |
Part of: cockroachdb#102386 This change introduces a `separate_txns` field to the sql api endpoint. This field allows callers to run provided statements in separate transactions. Failures in separate transactions are scoped to their respective transaction and do not interfere with the execution of subsequent transactions. The exception to this case is if the max response size is exceeded. If the response size is exceeded in an earlier transaction, it will still exceed the limit in subsequent transactions. The response-level error using `separate_txns` is a generic message: `separate transaction payload encountered transaction error(s)`, indicating that an error has occurred in at least one of the transactions. We additionally add a `stop_on_error` field to allow callers to stop execution of subsequent txns (i.e. in the case where `separate_txns` is true). Release note: None
629ecd6
to
b1a4dce
Compare
bors r+ |
Build succeeded: |
Part of: #102386
This change introduces a
separate_txns
field to the sql api endpoint.This field allows callers to run provided statements in separate
transactions. Failures in separate transactions are scoped to their
respective transaction and do not interfere with the execution of
subsequent transactions. The exception to this case is if the max
response size is exceeded. If the response size is exceeded in an
earlier transaction, it will still exceed the limit in subsequent
transactions. The response-level error using
separate_txns
is ageneric message:
separate transaction payload encountered transaction error(s)
, indicating that an error has occurred in at least one of thetransactions.
We additionally add a
stop_on_error
field to allow callers to stopexecution of subsequent txns (i.e. in the case where
separate_txns
istrue).
Release note: None