Skip to content

Conversation

@michae2
Copy link
Collaborator

@michae2 michae2 commented Sep 9, 2024

logictest: set session variables in connection URL

To execute SQL statements, logic tests use a sql.DB connection pool
managed by database/sql and backed by the lib/pq driver. This connection
pool can open new connections as necessary, but typically does not
because most query and statement commands block until the SQL
statement finishes, allowing the connection pool to continue reusing the
same single connection.

Occasionally, however, the connection pool does open a new connection,
for example whenever statement async and query async commands return
before the SQL statement has finished. Another example is when lib/pq
returns driver.ErrBadConn, telling the connection pool to retry a
query using a new connection.

These new connections are opened internally by the connection pool,
without going through getOrOpenClient, meaning they won't have any of
the session variables from getOrOpenClient set. This test failure was
one such case, where after a connection-pool-level retry the
default_transaction_isolation of an UPDATE statement was the default
of SERIALIZABLE.

To ensure these new connections have the correct session variables set,
this commit adds them to the connection URL passed to lib/pq. This will
set them on every new connection, even those opened internally by the
connection pool.

Fixes: #129921

Release note: None


logictest: fix another flake in select_for_share

While stressing select_for_share for #129921, I noticed another rare
flake, where we sometimes have an unexpected shared lock appear in
crdb_internal.cluster_locks after a single SELECT FOR SHARE statement.

I think what's happening here is that a retry of the SELECT FOR SHARE
statement interacts with the shared lock from the previous execution,
causing an entry to appear in crdb_internal.cluster_locks. (We don't
always immediately clean up locks after a transaction finishes, which is
expected.)

I've simply removed the query. I don't think it's necessary to prove
correctness, as long as the following SELECT FOR UPDATE SKIP LOCKED
returns the expected row.

Informs: #129921

Release note: None

@michae2 michae2 added backport-23.2.x PAST MAINTENANCE SUPPORT: 23.2 patch releases via ER request only backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.2.x labels Sep 9, 2024
@michae2 michae2 requested review from a team, arulajmani and rafiss September 9, 2024 23:31
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

commit #1 lgtm! nice find and fix!

i'm fine with commit #2 also, but i'm less familiar with the expected locking behavior.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani)

To execute SQL statements, logic tests use a `sql.DB` connection pool
managed by database/sql and backed by the lib/pq driver. This connection
pool can open new connections as necessary, but typically does not
because most `query` and `statement` commands block until the SQL
statement finishes, allowing the connection pool to continue reusing the
same single connection.

Occasionally, however, the connection pool does open a new connection,
for example whenever `statement async` and `query async` commands return
before the SQL statement has finished. Another example is when lib/pq
returns `driver.ErrBadConn`, telling the connection pool to retry a
query using a new connection.

These new connections are opened internally by the connection pool,
without going through `getOrOpenClient`, meaning they won't have any of
the session variables from `getOrOpenClient` set. This test failure was
one such case, where after a connection-pool-level retry the
`default_transaction_isolation` of an UPDATE statement was the default
of SERIALIZABLE.

To ensure these new connections have the correct session variables set,
this commit adds them to the connection URL passed to lib/pq. This will
set them on every new connection, even those opened internally by the
connection pool.

Fixes: cockroachdb#129921

Release note: None
While stressing select_for_share for cockroachdb#129921, I noticed another rare
flake, where we sometimes have an unexpected shared lock appear in
`crdb_internal.cluster_locks` after a single SELECT FOR SHARE statement.

I think what's happening here is that a retry of the SELECT FOR SHARE
statement interacts with the shared lock from the previous execution,
causing an entry to appear in `crdb_internal.cluster_locks`. (We don't
always immediately clean up locks after a transaction finishes, which is
expected.)

I've simply removed the query. I don't think it's necessary to prove
correctness, as long as the following SELECT FOR UPDATE SKIP LOCKED
returns the expected row.

Informs: cockroachdb#129921

Release note: None
@michae2
Copy link
Collaborator Author

michae2 commented Sep 23, 2024

TFTR!

bors r=rafiss

@craig craig bot merged commit 0463687 into cockroachdb:master Sep 23, 2024
@blathers-crl
Copy link

blathers-crl bot commented Sep 23, 2024

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #129921: branch-release-23.2, branch-release-24.1, branch-release-24.2.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl
Copy link

blathers-crl bot commented Sep 23, 2024

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from c340f4f to blathers/backport-release-23.2-130375: 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.


error creating merge commit from c340f4f to blathers/backport-release-24.1-130375: 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 24.1.x failed. See errors above.


error creating merge commit from c340f4f to blathers/backport-release-24.2-130375: 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 24.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-23.2.x PAST MAINTENANCE SUPPORT: 23.2 patch releases via ER request only backport-24.1.x Flags PRs that need to be backported to 24.1.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg/ccl/logictestccl/tests/local-read-committed/local-read-committed_test: TestReadCommittedLogic_select_for_share failed

3 participants