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: modernize the SQL API calls #76434

Merged
merged 1 commit into from
Feb 11, 2022
Merged

Conversation

knz
Copy link
Contributor

@knz knz commented Feb 11, 2022

Needed for #76433.

This brings the cli (sub-)packages kicking and screaming into the
post-go1.8 era, by adding the missing context arguments.

Also,
Fixes #76432.

Release note (bug fix): Some of the cockroach node subcommands did
not handle --timeout properly. This is now fixed.

@knz knz requested review from rafiss and otan February 11, 2022 15:37
@knz knz requested review from a team as code owners February 11, 2022 15:37
@knz knz requested review from a team and dt and removed request for a team February 11, 2022 15:37
@cockroach-teamcity
Copy link
Member

This change is Reviewable

This brings the cli (sub-)packages kicking and screaming into the
post-go1.8 era, by adding the missing context arguments.

Release note (bug fix): Some of the `cockroach node` subcommands did
not handle `--timeout` properly. This is now fixed.
@knz knz force-pushed the 20220211-sql-cancel2 branch from f5f4316 to aa30839 Compare February 11, 2022 16:28
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.

nice!

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


pkg/cli/node.go, line 65 at r1 (raw file):

	ctx := context.Background()

	// TODO(knz): This can use a context deadline instead, now that

might be worth keeping as-is anyway, so that timeouts still work when connected to older CRDB versions. (or mention that in this comment.) ditto in other comments.


pkg/cli/clisqlclient/conn.go, line 166 at r1 (raw file):

		//
		// TODO(knz): CockroachDB servers do not properly fill SQLSTATE
		// (28P01) for password auth errors, so we have to "make do"

Would it be valuable to extend the change in #69106 so it uses 28P01 for passwords? Initially, I intentionally didn't use 28P01, but seems worthwhile if it improves UX

Copy link
Contributor Author

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

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


pkg/cli/node.go, line 65 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

might be worth keeping as-is anyway, so that timeouts still work when connected to older CRDB versions. (or mention that in this comment.) ditto in other comments.

This change is backward-compatible! Previous versions know how to parse string INTERVAL values too.


pkg/cli/clisqlclient/conn.go, line 166 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

Would it be valuable to extend the change in #69106 so it uses 28P01 for passwords? Initially, I intentionally didn't use 28P01, but seems worthwhile if it improves UX

Yes I agree. Different PR though, and then we'll need to wait at least 1 version to use it here.

@knz
Copy link
Contributor Author

knz commented Feb 11, 2022

bors r=rafiss

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.

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


pkg/cli/node.go, line 65 at r1 (raw file):

Previously, knz (kena) wrote…

This change is backward-compatible! Previous versions know how to parse string INTERVAL values too.

oh sorry, to clarify, i meant "it might be better not to do the task mentioned in the TODO comment"

if the CLI were to only use context deadlines, then timeouts wouldn't work against older CRDB versions.

Copy link
Contributor Author

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

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


pkg/cli/node.go, line 65 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

oh sorry, to clarify, i meant "it might be better not to do the task mentioned in the TODO comment"

if the CLI were to only use context deadlines, then timeouts wouldn't work against older CRDB versions.

Correct. But after 22.1 is released, we can safely address the todo.

craig bot pushed a commit that referenced this pull request Feb 11, 2022
76427: cli,sql: do not exit interactive shells with Ctrl+C r=rafiss a=knz

First commit from #76434.
Needed for #76433.

This change is a preface to making the interactive shell support
Ctrl+C to cancel a currently executing query.

When that happens, we need to ensure that Ctrl+C *only* cancels the
current query, and not the entire shell. This is because there is no
deterministic boundary in time for a user to decide whether the key
press will cancel only the query, or stop the shell. If they care
about keeping their shell alive, they would never "dare" to press
Ctrl+C while a query is executing.

Incidentally, this is also what `psql` does, for pretty much the same
reason.

Note that the new behavior is restricted to *interactive* shells, when
stdin is a terminal. The behavior for non-interactive shells remains
unchanged, where Ctrl+C will terminate everything. This is also what
other SQL shells do.

Release note (cli change): `cockroach sql` (and `demo`) now continue
to accept user input when Ctrl+C is pressed at the interactive prompt
and the current input line is empty. Previously, it would terminate
the shell.  To terminate the shell, the client-side command `\q` is
still supported. The user can also terminate the input altogether via
EOF (Ctrl+D).
The behavior in non-interactive use remains unchanged.

Co-authored-by: Raphael 'kena' Poss <[email protected]>
@craig craig bot merged commit aa30839 into cockroachdb:master Feb 11, 2022
@ajwerner
Copy link
Contributor

bors seems confused about this one because this commit was merged in #76427.

bors r-

@craig
Copy link
Contributor

craig bot commented Feb 12, 2022

Canceled.

@knz knz deleted the 20220211-sql-cancel2 branch February 12, 2022 09:48
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: the --timeout flag is improperly handled
4 participants