sql: support lock_timeout session variable#68042
sql: support lock_timeout session variable#68042craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
9d003c5 to
b3fa491
Compare
|
Awesome! I feel like most of the salient changes here are in the KV interface, no? I think we'd want a KV reviewer too. One thing that I'd like to call to @rafiss's attention: This is a different definition than Postgres's |
Absolutely, this cuts across SQL and KV, so we'll want a KV reviewer on the first two commits. I had pulled those out into #68026 so they can be reviewed separately. This PR is really just about the third commit. But also, there's no rush on this, so no need to review before #68026 is merged and the first two commits are rebased away.
If anything, I was thinking that not deviating from Postgres here would put us in trouble. It would lead to behavior where the |
|
Oh, sorry, I ignored your disclaimer about the first 2 commit by accident. Makes sense. |
yuzefovich
left a comment
There was a problem hiding this comment.
Seems like a pretty useful feature! The reasoning about the deviation from Postgres sgtm, and the last commit , but I'd like to hear Rafi's opinion about the deviation too.
Reviewed 32 of 32 files at r3.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis)
Is the concern that people may be surprised to see non-locking read transactions get cancelled due to I don't know either way if this is a significant/painful divergence. My personal feeling based on no data is that this divergence is acceptable. One thing that might go a long way to making it more acceptable is if we make two changes in the message:
|
Fixes cockroachdb#67513. In cockroachdb#68026, we added support for a new `lock_timeout` field on the `BatchRequest.Header` struct. A batch's lock_timeout specifies the maximum amount of time that it will wait while attempting to acquire a lock on a key or while blocking on an existing lock in order to perform a non-locking read on a key. The time limit applies separately to each lock acquisition attempt. If the timeout elapses when waiting for a lock, a WriteIntentError is returned. This extension to the KV API allows us to properly support the `lock_timeout` session variable in SQL, which matches these semantics closely. When configured, this session variable aborts any statement that waits longer than the specified amount of time while attempting to acquire a single lock. The only deviation from Postgres' behavior is that the lock_timeout configuration applies to non-locking reads in read-write and read-only transactions. This is because unlike in Postgres, where where non-locking reads do not wait on conflicting locks, in CockroachDB, non-locking reads do wait for conflicting locks to be released. Release note (sql change): The lock_timeout session variable is now supported. The configuration can be used to abort a query with an error if it waits longer than the configured duration while blocking on a single row-level lock acquisition.
b3fa491 to
38da713
Compare
My guess is that no more than those who may be surprised to see non-locking reads block on locks. And once people understand that non-locking reads block on locks (which isn't crazy in serializable isolation, it's just not how PG works), they'll be happy that this setting applies there as well.
Good idea. I removed the "while locking row" language of the error message and made it more general.
This is also a great idea! Unfortunately, it doesn't look like we have any documentation about CockroachDB's locking behavior. cc. @rmloveland. bors r+ |
68042: sql: support lock_timeout session variable r=nvanbenschoten a=nvanbenschoten Fixes #67513. Please ignore the first two commits, which are from #68026. In #68026, we added support for a new `lock_timeout` field on the `BatchRequest.Header` struct. A batch's lock_timeout specifies the maximum amount of time that it will wait while attempting to acquire a lock on a key or while blocking on an existing lock in order to perform a non-locking read on a key. The time limit applies separately to each lock acquisition attempt. If the timeout elapses when waiting for a lock, a WriteIntentError is returned. This extension to the KV API allows us to properly support the `lock_timeout` session variable in SQL, which matches these semantics closely. When configured, this session variable aborts any statement that waits longer than the specified amount of time while attempting to acquire a single lock. The only deviation from Postgres' behavior is that the lock_timeout configuration applies to non-locking reads in read-write and read-only transactions. This is because unlike in Postgres, where where non-locking reads do not wait on conflicting locks, in CockroachDB, non-locking reads do wait for conflicting locks to be released. Release note (sql change): The lock_timeout session variable is now supported. The configuration can be used to abort a query with an error if it waits longer than the configured duration while blocking on a single row-level lock acquisition. @jordanlewis I'm adding you for the review, but feel free to re-assign. Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
|
Timed out. |
|
bors r+ |
|
Build succeeded: |
@nvanbenschoten we have some stuff on concurrency control that was added to the Transaction Layer architecture docs in cockroachdb/docs#7020 But given that this PR adds a session var, do you mean that we should add something focused on SQL users? E.g., something similar to the PG locking docs? If so I can create an issue, just wanted to be sure I understand ~what is needed Right now I think the only things on locking we have in SQL user docs are a few mentions scattered around Indexes, Oracle migration, and the |
I think this would be a fantastic addition! I also think our discussion about "Transactions, locking, and concurrency control" on the Oracle migration doc is great. Have we considered adding a similar discussion to the Postgres migration page? I imagine that that would be a useful resource for people comparing Cockroach's behavior to Postgres'.
That all said, I don't think improving the documentation on locking is a firm prerequisite to documenting this new session var. |
|
Nathan VanBenschoten ***@***.***> writes:
> E.g., something similar to the PG locking docs? If so I can
> create an issue, just wanted to be sure I understand ~what is
> needed
I think this would be a fantastic addition! I also think our
discussion about "Transactions, locking, and concurrency control" on
the Oracle migration doc is great. Have we considered adding a similar
discussion to the Postgres migration page? I imagine that that would
be a useful resource for people comparing Cockroach's behavior to
Postgres'.
Thanks for the suggestion Nathan! Filed the following docs issues based
on this convo:
- cockroachdb/docs#11102 (add section on locking/concurrency to Migrate
from Postgres doc)
- cockroachdb/docs#11104 (add docs on SQL-level locking behavior)
> But given that this PR adds a session var, do you mean that we
> should add something focused on SQL users?
That all said, I don't think improving the documentation on locking is
a firm prerequisite to documenting this new session var.
Totes agreed, docs for this var will happen with/without the other
things mentioned above
|
Fixes #67513.
Please ignore the first two commits, which are from #68026.
In #68026, we added support for a new
lock_timeoutfield on theBatchRequest.Headerstruct.A batch's lock_timeout specifies the maximum amount of time that it will wait while attempting to acquire a lock on a key or while blocking on an existing lock in order to perform a non-locking read on a key. The time limit applies separately to each lock acquisition attempt. If the timeout elapses when waiting for a lock, a WriteIntentError is returned.
This extension to the KV API allows us to properly support the
lock_timeoutsession variable in SQL, which matches these semantics closely. When configured, this session variable aborts any statement that waits longer than the specified amount of time while attempting to acquire a single lock.The only deviation from Postgres' behavior is that the lock_timeout configuration applies to non-locking reads in read-write and read-only transactions. This is because unlike in Postgres, where where non-locking reads do not wait on conflicting locks, in CockroachDB, non-locking reads do wait for conflicting locks to be released.
Release note (sql change): The lock_timeout session variable is now supported. The configuration can be used to abort a query with an error if it waits longer than the configured duration while blocking on a single row-level lock acquisition.
@jordanlewis I'm adding you for the review, but feel free to re-assign.