-
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
sql: mark implicit transactions with AOST as read-only #120097
Conversation
Should we backport this? I'd like to but am slightly worried that someone is inadvertently already using |
Is the current behavior well-defined and reasonable? What about the current behavior of |
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.
I'm guessing the current code could lead to an undefined behavior / broken assumptions somewhere, so I'd lean towards backporting it.
Reviewed 3 of 3 files at r1, 5 of 5 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @rafiss)
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.
super small nits. thanks for the fix!
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @michae2)
pkg/sql/conn_executor_exec.go
line 1298 at r1 (raw file):
return err } p.extendedEvalCtx.TxnReadOnly = ex.state.readOnly.Load()
nit: i think we may not need p.extendedEvalCtx.TxnReadOnly = ex.state.readOnly.Load()
here, since this should happen when reesetPlanner
is called later. but i don't think it hurts either.
pkg/sql/exec_util.go
line 3306 at r2 (raw file):
// call into the connEx, which modifies its TxnState. // NOTE(andrei): I couldn't find good documentation on transaction_read_only, // but I've tested its behavior in Postgres 11.
unrelated to your PR, but this comment could mention that transaction_read_only
/default_transaction_read_only
have similar behavior as transaction_isolation
/default_transaction_isolation
. (just to make it seem less like a scary special thing)
pkg/sql/logictest/testdata/logic_test/txn
line 1334 at r1 (raw file):
statement error cannot execute DELETE in a read-only transaction DELETE FROM kv
nit: seems like this is a duplicate of the existing line above this
In `handleAOST` we were setting the transaction AOST but not marking it as read-only. It needs to also be marked as read-only to disallow mutation statements and locking statements. Fixes: cockroachdb#120081 Release note (sql change): Mutation statements such as UPDATE and DELETE as well as locking statements such as SELECT FOR UPDATE are not allowed in read-only transactions or AS OF SYSTEM TIME transactions. Fix an oversight where we were allowing mutation statements and locking statements in implicit single-statement transactions using AS OF SYSTEM TIME.
Fixes: cockroachdb#44200 Release note (bug fix): Fix a bug in which it was possible to `SET transaction_read_only = false` during an AS OF SYSTEM TIME transaction.
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.
Is the current behavior well-defined and reasonable? What about the current behavior of
UPDATE
orDELETE
statements?
Good point, it is not well-defined. Might even allow corruption. I'll backport.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @rafiss and @yuzefovich)
pkg/sql/conn_executor_exec.go
line 1298 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
nit: i think we may not need
p.extendedEvalCtx.TxnReadOnly = ex.state.readOnly.Load()
here, since this should happen whenreesetPlanner
is called later. but i don't think it hurts either.
I left it in for consistency, since we're setting other fields of the evalctx here.
pkg/sql/exec_util.go
line 3306 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
unrelated to your PR, but this comment could mention that
transaction_read_only
/default_transaction_read_only
have similar behavior astransaction_isolation
/default_transaction_isolation
. (just to make it seem less like a scary special thing)
Good point, done.
pkg/sql/logictest/testdata/logic_test/txn
line 1334 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
nit: seems like this is a duplicate of the existing line above this
Whoops, thanks! Done.
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! thank you
YW, TFTRs! Failure is #119288 bors r=yuzefovich,rafiss |
Build succeeded: |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from 238ca33 to blathers/backport-release-23.1-120097: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 23.1.x failed. See errors above. error creating merge commit from 238ca33 to blathers/backport-release-23.2-120097: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 23.2.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
sql: mark implicit transactions with AOST as read-only
In
handleAOST
we were setting the transaction AOST but not marking it as read-only. It needs to also be marked as read-only to disallow mutation statements and locking statements.Fixes: #120081
Release note (sql change): Mutation statements such as UPDATE and DELETE as well as locking statements such as SELECT FOR UPDATE are not allowed in read-only transactions or AS OF SYSTEM TIME transactions. Fix an oversight where we were allowing mutation statements and locking statements in implicit single-statement transactions using AS OF SYSTEM TIME.
sql: disallow SET transaction_read_only = false during AOST txn
Fixes: #44200
Release note (bug fix): Fix a bug in which it was possible to
SET transaction_read_only = false
during an AS OF SYSTEM TIME transaction.