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

clisqlclient: only print the warning when there are secondary tenants #101128

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/cli/clisqlclient/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ func (c *sqlConn) GetServerMetadata(
// get either a go string or bool depending on the SQL driver in
// use.
if toString(val[0])[0] == 't' {
// There's always at least 1 row in the tenants table, for the
// system tenant.
val, err = c.QueryRow(ctx, `
SELECT EXISTS (SELECT 1 FROM system.public.tenants LIMIT 1)`)
SELECT (SELECT count(id) FROM system.public.tenants LIMIT 2)>1`)
if c.conn.IsClosed() {
return 0, "", "", MarkWithConnectionClosed(err)
}
Expand Down
28 changes: 25 additions & 3 deletions pkg/cli/interactive_tests/test_demo_cli_integration.tcl.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ end_test
start_test "Check that a SQL shell can connect to the app tenant without special arguments as root"
spawn $argv sql --no-line-editor -u root
eexpect "Welcome"
eexpect root@
expect {
"ATTENTION: YOU ARE CONNECTED TO THE SYSTEM TENANT" { exit 1 }
root@ {}
}
eexpect "defaultdb>"
send "table system.tenants;\r"
eexpect "ERROR"
Expand All @@ -50,7 +53,10 @@ eexpect eof

spawn $argv sql --no-line-editor -u root -d cluster:demoapp
eexpect "Welcome"
eexpect root@
expect {
"ATTENTION: YOU ARE CONNECTED TO THE SYSTEM TENANT" { exit 1 }
root@ {}
}
eexpect "demoapp/defaultdb>"
send "\\q\r"
eexpect eof
Expand Down Expand Up @@ -87,7 +93,10 @@ system "$argv sql -u root -e \"alter user root with password 'abc'\""
set ssldir $env(HOME)/.cockroach-demo
spawn $argv sql --no-line-editor --url "postgresql://root:abc@/defaultdb?host=$ssldir&port=26257"
eexpect "Welcome"
eexpect root@
expect {
"ATTENTION: YOU ARE CONNECTED TO THE SYSTEM TENANT" { exit 1 }
root@ {}
}
eexpect "defaultdb>"
send "table system.tenants;\r"
eexpect "ERROR"
Expand Down Expand Up @@ -168,6 +177,19 @@ set spawn_id $demo_spawn_id
send "\\q\r"
eexpect eof


start_test "Check that the warning for the system tenant is not printed when there are no secondary tenants"
spawn $argv demo --empty --no-line-editor --multitenant=false
eexpect "Welcome"
expect {
"ATTENTION: YOU ARE CONNECTED TO THE SYSTEM TENANT" { exit 1 }
demo@ {}
}
eexpect "defaultdb>"
send "\\q\r"
eexpect eof
end_test

# Regression test for #95135.
start_test "Verify that the demo command did not leave tenant directories around."
system "if ls tenant-* >logs/tenants 2>&1; then echo Strays; cat logs/tenants; exit 1; fi"
Expand Down