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

cli: additional enhancements after switching to jackc/pgx #82101

Merged
merged 7 commits into from
Jun 6, 2022

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented May 31, 2022

Fixes #72065

Release note (cli change): Using COPY in the CLI is now
supported while inside an explicit transaction.

Release note (bug fix): The DateStyle session setting is no longer
ignored when using the CLI when set in the options URL parameter.

Release note (cli change): Ctrl+C (the interrupt signal) can now be used
in the CLI to attempt to cancel the currently executing SQL query.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss force-pushed the cli-pgx-combined branch from f16d82c to e487737 Compare May 31, 2022 19:00
@rafiss rafiss changed the title cli: switch to jackc/pgx cli: additional enhancements after switching to jackc/pgx May 31, 2022
@rafiss rafiss force-pushed the cli-pgx-combined branch 2 times, most recently from ee5e38b to 25302bf Compare May 31, 2022 22:52
@knz
Copy link
Contributor

knz commented Jun 1, 2022

i'd like to delay the review of this until the other PR has merged, because if there's a chance for a rebase that will make reviewable unhappy.

or alternatively, you can create a PR using the other PR as base branch, to facilitate the review. (The way I did for e.g. #82069.)

@rafiss
Copy link
Collaborator Author

rafiss commented Jun 1, 2022

or alternatively, you can create a PR using the other PR as base branch, to facilitate the review. (The way I did for e.g. #82069.)

That's what I intended to do here. Anyway, the other PR should get merged soon, so this will look better soon.

@rafiss rafiss force-pushed the cli-pgx-combined branch from 25302bf to f9b3e33 Compare June 1, 2022 20:53
@rafiss rafiss marked this pull request as ready for review June 1, 2022 20:54
@rafiss rafiss requested review from a team as code owners June 1, 2022 20:54
@rafiss rafiss requested review from knz, otan and a team and removed request for a team June 1, 2022 20:54
@rafiss rafiss force-pushed the cli-pgx-combined branch 3 times, most recently from 43f1fd9 to b25839a Compare June 1, 2022 22:14
Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

what a nice library pgx is :')

@@ -1857,13 +1856,6 @@ func (c *cliState) doRunStatements(nextState cliStateEnum) cliStateEnum {
}

func (c *cliState) beginCopyFrom(ctx context.Context, sql string) error {
c.refreshTransactionStatus()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit for this commit: should read



Release note (cli change): Using COPY in a CLI can now be used while inside a
transaction.

(normal COPY should still work)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

return
case <-intCh:
go func() {
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

was there a test for this functionality somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah there is - can you rename test_interrupt.tcl.disabled back to test_interrupt.tcl?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

pkg/cli/clisqlclient/rows.go Outdated Show resolved Hide resolved
pgx no longer requires us to have this limitation.

Release note (cli change): Using COPY in the CLI is now
supported while inside an explicit transaction.
@rafiss rafiss force-pushed the cli-pgx-combined branch from b25839a to 6b3d2a8 Compare June 2, 2022 02:34
Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

:lgtm: modulo missing release note.

also the interrupt test has an issue in CI? need to investigate further maybe.

Reviewed 1 of 3 files at r2, 1 of 59 files at r9, 19 of 19 files at r16, 2 of 2 files at r17, 1 of 1 files at r18, 6 of 6 files at r19, 13 of 13 files at r20, 3 of 3 files at r21, 7 of 7 files at r22, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @knz, @otan, and @rafiss)


-- commits line 12 at r18:
Maybe add a release note to explain that query cancellation is enabled in the CLI.

@rafiss
Copy link
Collaborator Author

rafiss commented Jun 2, 2022

also the interrupt test has an issue in CI? need to investigate further maybe.

🤦 looks like pgx has the same default behavior where cancelling the context actually closes the connection. it's defined by the context watcher here: https://github.com/jackc/pgconn/blob/7ddbd74d5e5a52cd24f750cacfc9be91d4f49f76/pgconn.go#L360

@rafiss rafiss force-pushed the cli-pgx-combined branch from 6b3d2a8 to ab7c311 Compare June 2, 2022 21:36
@rafiss
Copy link
Collaborator Author

rafiss commented Jun 2, 2022

I've updated things so it explicitly sends a cancel request instead of relying on context cancellation. i know this wasn't your first preference, so let me know what you think

Copy link
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz, @otan, and @rafiss)


pkg/cli/clisqlshell/sql.go line 2238 at r28 (raw file):

						break wait
					case <-tooLongTimer:
						fmt.Fprintln(c.iCtx.stderr, "server does not respond to query cancellation; a second interrupt will stop the shell.")

an alternative approach is to call the cancel() function (the one from line 2204 above) here. this would cause the connection to be closed, rather than exiting the shell.

Copy link
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz, @otan, and @rafiss)


pkg/cli/clisqlshell/sql.go line 2238 at r28 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

an alternative approach is to call the cancel() function (the one from line 2204 above) here. this would cause the connection to be closed, rather than exiting the shell.

oh nvm, that is not correct. we would have to call the cancel() function that's created in runWithInterruptableCtx

@rafiss
Copy link
Collaborator Author

rafiss commented Jun 4, 2022

@knz ping in case you had any thoughts on this:

I've updated things so it explicitly sends a cancel request instead of relying on context cancellation. i know this wasn't your first preference, so let me know what you think

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

This looks good with a tweak.

Reviewed 1 of 20 files at r23, 1 of 1 files at r24, 2 of 6 files at r25, 7 of 13 files at r26, 2 of 3 files at r27, 7 of 7 files at r28, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz, @otan, and @rafiss)


pkg/cli/clisqlshell/context.go line 79 at r28 (raw file):

	mu struct {
		syncutil.Mutex
		cancelFn func() error

can you make that take a context.Context argument


pkg/cli/clisqlshell/sql.go line 2221 at r28 (raw file):

				// Cancel the query's context, which should make the driver
				// send a cancellation message.
				if err := cancelFn(); err != nil {

then pass ctx as argument here


pkg/cli/clisqlshell/sql.go line 2268 at r28 (raw file):

	// Inform the Ctrl+C handler that this query is executing.
	c.iCtx.mu.Lock()
	c.iCtx.mu.cancelFn = func() error {

then simplify this .cancel = c.conn.Cancel

rafiss added 6 commits June 6, 2022 17:11
Release note (cli change): Ctrl+C (the interrupt signal) can now be used
in the CLI to attempt to cancel the currently executing SQL query.
The upgrade to pgx has fixed this.

Release note (bug fix): The DateStyle session setting is no longer
ignored when using the CLI when set in the `options` URL parameter.
Release note: None
Release note: None
@rafiss rafiss force-pushed the cli-pgx-combined branch from ab7c311 to aa02d14 Compare June 6, 2022 21:11
Copy link
Collaborator Author

@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.

tftr! i've added your suggestion

bors r=knz,otan

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz, @otan, and @rafiss)

@craig
Copy link
Contributor

craig bot commented Jun 6, 2022

Build succeeded:

@craig craig bot merged commit e280a7f into cockroachdb:master Jun 6, 2022
@rafiss rafiss deleted the cli-pgx-combined branch June 7, 2022 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: cockroach sql may override DateStyle when set with -c
4 participants