-
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
cli: additional enhancements after switching to jackc/pgx #82101
Conversation
ee5e38b
to
25302bf
Compare
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.) |
That's what I intended to do here. Anyway, the other PR should get merged soon, so this will look better soon. |
43f1fd9
to
b25839a
Compare
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.
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() |
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.
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)
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.
done
return | ||
case <-intCh: | ||
go func() { | ||
for { |
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.
was there a test for this functionality somewhere?
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.
ah there is - can you rename test_interrupt.tcl.disabled
back to test_interrupt.tcl
?
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.
done
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.
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.
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: 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.
🤦 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 |
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 |
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.
Reviewable status: 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.
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.
Reviewable status: 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
@knz ping in case you had any thoughts on this:
|
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.
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: 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
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
Release note: None
Release note: None
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.
tftr! i've added your suggestion
bors r=knz,otan
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz, @otan, and @rafiss)
Build succeeded: |
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.