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

sql: report contention on writes in EXPLAIN ANALYZE #106354

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Jul 7, 2023

This commit adds the contention events listener to planNodeToRowSource which allows us to add contention time information for mutation planNodes to be shown in EXPLAIN ANALYZE.

Fixes: #106266.

Release note (sql change): CockroachDB now reports contention time encountered while executing mutation statements (INSERT, UPSERT, UPDATE, DELETE) when run via EXPLAIN ANALYZE.

@yuzefovich yuzefovich added the backport-23.1.x Flags PRs that need to be backported to 23.1 label Jul 7, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich marked this pull request as ready for review July 7, 2023 00:52
@yuzefovich yuzefovich requested a review from a team as a code owner July 7, 2023 00:52
Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm: Great work!

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @cucaroach)

Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice!

Reviewed 3 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @cucaroach and @yuzefovich)


-- commits line 10 at r1:
typo: s/ran/run


pkg/sql/opt/exec/explain/output_test.go line 290 at r1 (raw file):

		closedSem = true
		// Allow the main goroutine's mutation to experience contention.
		time.Sleep(3 * time.Second)

nit: Instead of a sleep, I think it would be more reliable to receive something sent from the main goroutine on a channel. Maybe it could re-use sem? Or use another channel?

This commit adds the contention events listener to `planNodeToRowSource`
which allows us to add contention time information for mutation
planNodes to be shown in EXPLAIN ANALYZE.

Release note (sql change): CockroachDB now reports contention time
encountered while executing mutation statements (INSERT, UPSERT, UPDATE,
DELETE) when run via EXPLAIN ANALYZE.
Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @cucaroach, @DrewKimball, and @michae2)


pkg/sql/opt/exec/explain/output_test.go line 290 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

nit: Instead of a sleep, I think it would be more reliable to receive something sent from the main goroutine on a channel. Maybe it could re-use sem? Or use another channel?

It's a bit tricky since EXPLAIN ANALYZE UPSERT query will be blocked by the open txn, so we cannot do both things (execute the contending mutation and send on the channel) from the main goroutine, so I added another worker goroutine into the mix. The sleep is still present, but only to ensure non-trivial contention time (i.e. give the contending mutation a chance to get to the KV layer in its lifecycle).

Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @cucaroach, @DrewKimball, and @yuzefovich)


pkg/sql/opt/exec/explain/output_test.go line 290 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

It's a bit tricky since EXPLAIN ANALYZE UPSERT query will be blocked by the open txn, so we cannot do both things (execute the contending mutation and send on the channel) from the main goroutine, so I added another worker goroutine into the mix. The sleep is still present, but only to ensure non-trivial contention time (i.e. give the contending mutation a chance to get to the KV layer in its lifecycle).

Ah, right! Thanks.

@craig
Copy link
Contributor

craig bot commented Jul 7, 2023

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: expose contention time for write operators
4 participants