Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
95020: ui: clear tenant cookie when multitenant session expires r=Santamaura a=Santamaura

This change adds a method to clear the tenant cookie when the multitenant-session cookie has more than one tenant. The method is called on logout and if an api returns a 401 unauthorized error. This is to ensure that in a multitenant cluster when the session expires and the user is redirected to the login page, they will be able to do a multitenant login.

Fixes: cockroachdb#92843

Release note (ui change): clear tenant cookie on an api returning 401 error in order to allow for multitenant login again.

95029: sql: use crdb_internal for pg_proc.pronamespace when needed r=knz a=rafiss

fixes cockroachdb#94952

Release note (bug fix): The pronamespace column of the pg_proc table now correctly reports the crdb_internal schema for built-in functions that have the "crdb_internal" prefix.

---

comprules: support completion for qualified functions

The syntax completion engine now generates suggestion for user-defined
functions. It restricts the suggestions to only functions in the schema
name if one was provided, or else to the schemas in the search_path.

No release note since this functionality is new in v23.1.

95172: go.mod: bump Pebble to 90c810757fe6 r=nvanbenschoten a=nvanbenschoten

```
90c81075 cmd/pebble: add bench replay command
1e862340 db: scan a readState during format major version upgrades
dac60ce1 Revert "sstable: skip two known test flakes on windows"
78933282 ci: renable linux race
5bad2c1a sstable: avoid allocating up to maximum block size in valueBlockWriter
a4481627 deflake TestCompactionTombstones
06fbe6ae db: add DB.ApplyNoSyncWait for asynchronous apply
a60e75cf db: misc LazyValue tweaks, for testing, and simpler Clone invariant
ba575119 doc: fix
326549f0 db: metrics and stats for value blocks and lazy values
cc913bad db: don't validate version edits during a panic
```

Release note: None
Epic: None

Co-authored-by: Santamaura <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
4 people committed Jan 13, 2023
4 parents 45a3723 + 2f10222 + 83fca32 + 8167f46 commit 6f5d89e
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 127 deletions.
6 changes: 3 additions & 3 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1485,10 +1485,10 @@ def go_deps():
patches = [
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
],
sha256 = "1b070e4908697f78b0842d165521695413c7bac40b6f7e374d63b9748ee2ed83",
strip_prefix = "github.com/cockroachdb/[email protected]20230110150502-a80169845786",
sha256 = "dcef948c71b6b6f6e83c41a8c6b9f6bc3df953216534ac4bc7a817d54bcd3515",
strip_prefix = "github.com/cockroachdb/[email protected]20230112184329-90c810757fe6",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20230110150502-a80169845786.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20230112184329-90c810757fe6.zip",
],
)
go_repository(
Expand Down
2 changes: 1 addition & 1 deletion build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/google-api-go-client/com_github_cockroachdb_google_api_go_client-v0.80.1-0.20221117193156-6a9f7150cb93.zip": "b3378c579f4f4340403038305907d672c86f615f8233118a8873ebe4229c4f39",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20211118104740-dabe8e521a4f.zip": "1972c3f171f118add3fd9e64bcea6cbb9959a3b7fa0ada308e8a7310813fea74",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20230110150502-a80169845786.zip": "1b070e4908697f78b0842d165521695413c7bac40b6f7e374d63b9748ee2ed83",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20230112184329-90c810757fe6.zip": "dcef948c71b6b6f6e83c41a8c6b9f6bc3df953216534ac4bc7a817d54bcd3515",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.3.zip": "7778b1e4485e4f17f35e5e592d87eb99c29e173ac9507801d000ad76dd0c261e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/sentry-go/com_github_cockroachdb_sentry_go-v0.6.1-cockroachdb.2.zip": "fbb2207d02aecfdd411b1357efe1192dbb827959e36b7cab7491731ac55935c9",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ require (
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
github.com/cockroachdb/gostdlib v1.19.0
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f
github.com/cockroachdb/pebble v0.0.0-20230110150502-a80169845786
github.com/cockroachdb/pebble v0.0.0-20230112184329-90c810757fe6
github.com/cockroachdb/redact v1.1.3
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ github.com/cockroachdb/gostdlib v1.19.0/go.mod h1:+dqqpARXbE/gRDEhCak6dm0l14AaTy
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f h1:6jduT9Hfc0njg5jJ1DdKCFPdMBrp/mdZfCpa5h+WM74=
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/pebble v0.0.0-20230110150502-a80169845786 h1:avnVz2lzx0gNPoStePsmGgK4mJLu/UTmaXJD1W2tTDs=
github.com/cockroachdb/pebble v0.0.0-20230110150502-a80169845786/go.mod h1:rWEpkT1ud5qGG2m1HqTBRWbLgi+oodC4+BWC46uVPjw=
github.com/cockroachdb/pebble v0.0.0-20230112184329-90c810757fe6 h1:g4/xNt1/chUSHly60rbkoMxUrzL4DhzJvL9UktSq9Fs=
github.com/cockroachdb/pebble v0.0.0-20230112184329-90c810757fe6/go.mod h1:rWEpkT1ud5qGG2m1HqTBRWbLgi+oodC4+BWC46uVPjw=
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd h1:KFOt5I9nEKZgCnOSmy8r4Oykh8BYQO8bFOTgHDS8YZA=
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ SELECT * FROM crdb_internal.cluster_contention_events WHERE table_id < 0
----
table_id index_id num_contention_events cumulative_contention_time key txn_id count

query TTTT colnames
query TTTTT colnames
SELECT * FROM crdb_internal.builtin_functions WHERE function = ''
----
function signature category details
function signature category details schema

query ITTITTTTTTTBBBB colnames
SELECT * FROM crdb_internal.create_statements WHERE database_name = ''
Expand Down
17 changes: 16 additions & 1 deletion pkg/cli/clisqlshell/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,22 @@ func (c *cliState) doHandleCliCmd(loopState, nextState cliStateEnum) cliStateEnu

case `\hf`:
if len(cmd) == 1 {
c.concatLines = `SELECT DISTINCT proname AS function FROM pg_proc ORDER BY 1`
// The following query lists all functions. It prefixes
// functions with their schema but only if the schema is not in
// the search path. This ensures that "common" functions
// are not prefixed by "pg_catalog", but crdb_internal functions
// get prefixed with "crdb_internal."
//
// TODO(knz): Replace this by the \df logic when that is implemented;
// see: https://github.com/cockroachdb/cockroach/pull/88061
c.concatLines = `
SELECT DISTINCT
IF(n.nspname = ANY current_schemas(TRUE), '',
pg_catalog.quote_ident(n.nspname) || '.') ||
pg_catalog.quote_ident(p.proname) AS function
FROM pg_catalog.pg_proc p
JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
ORDER BY 1`
return cliRunStatement
}
return c.handleFunctionHelp(cmd[1:], loopState, errState)
Expand Down
52 changes: 52 additions & 0 deletions pkg/cli/clisqlshell/testdata/complete/composite_names
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,55 @@ msg: ""
completions:
- "functions":
"crdb_internal.force_error(" (This function is used only by CockroachDB's developers for testing purposes.) -> "crdb_internal.force_error(" (0, 25)

sql
create schema my_schema
----
ok

sql
CREATE FUNCTION my_func(i INT) RETURNS INT LANGUAGE SQL AS 'SELECT i'
----
ok

sql
CREATE FUNCTION my_schema.my_other_func(i INT) RETURNS INT LANGUAGE SQL AS 'SELECT i'
----
ok

complete
select my@
----
complete 0 9
msg: ""
completions:
- "functions":
"my_func(" () -> "my_func(" (0, 2)
- "schema":
"my_schema" () -> "my_schema" (0, 2)

complete
select my_schema.@
----
complete 0 17
msg: ""
completions:
- "functions":
"my_schema.my_other_func(" () -> "my_schema.my_other_func(" (0, 10)

complete
select pg_catalog.array_l@
----
complete 0 25
msg: ""
completions:
- "functions":
"pg_catalog.array_length(" (Calculates the length of `input` on the provided `array_dimension`. However, bec) -> "pg_catalog.array_length(" (0, 18)
"pg_catalog.array_lower(" (Calculates the minimum value of `input` on the provided `array_dimension`. Howev) -> "pg_catalog.array_lower(" (0, 18)

complete
select "PG_CATALOG".@
----
complete 0 20
msg: ""
(no completions generated)
10 changes: 10 additions & 0 deletions pkg/cli/clisqlshell/testdata/complete/sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ msg: ""
completions:
- "relation":
"mytable" () -> "mytable" (0, 0)

complete
select array_l@
----
complete 0 14
msg: ""
completions:
- "functions":
"array_length(" (Calculates the length of `input` on the provided `array_dimension`. However, bec) -> "array_length(" (0, 7)
"array_lower(" (Calculates the minimum value of `input` on the provided `array_dimension`. Howev) -> "array_lower(" (0, 7)
54 changes: 24 additions & 30 deletions pkg/sql/comprules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func GetCompMethods() []compengine.Method {
return []compengine.Method{
method("keywords", completeKeyword),
method("builtins", completeBuiltin),
method("functions", completeFunction),
method("objects", completeObjectInCurrentDatabase),
method("schemas", completeSchemaInCurrentDatabase),
method("dbs", completeDatabase),
Expand Down Expand Up @@ -96,41 +96,27 @@ var compNotQualProcRe = regexp.MustCompile(`[^.](i'|_)`)
// A qualified possible builtin name.
var compMaybeQualProcRe = regexp.MustCompile(`i\.['_]|i\.i'`)

var compVSchemaRe = regexp.MustCompile(`pg_catalog|crdb_internal|information_schema`)

func completeBuiltin(ctx context.Context, c compengine.Context) (compengine.Rows, error) {
// Complete builtin names:
func completeFunction(ctx context.Context, c compengine.Context) (compengine.Rows, error) {
// Complete function names:
//
// - at whitespace after keywords.
// - after a period, if the identifier before the period is a vschema.
// - after a period.
//
var prefix string
var start, end int
var extraPrefix string
var schemaName string
atWord := c.AtWord()
sketch := c.Sketch()
switch {
case compMaybeQualProcRe.MatchString(sketch) &&
((!atWord && compVSchemaRe.MatchString(c.RelToken(-1).Str)) ||
(atWord && compVSchemaRe.MatchString(c.RelToken(-2).Str))):
case compMaybeQualProcRe.MatchString(sketch):
start = int(c.RelToken(-1).Start)
prefix = c.RelToken(-1).Str + "."
schemaName = c.RelToken(-1).Str
if atWord {
start = int(c.RelToken(-2).Start)
prefix = c.RelToken(-2).Str + "."
}
// crdb has this weird thing where every unqualified built-in "X"
// also exists as "pg_catalog.X". So when we search for
// completions after "pg_catalog.", we can strip that prefix from
// the search. However, we must be careful to add it back in the
// completion results, so that the prefix does not get stripped
// when the completion occurs.
if prefix == "pg_catalog." {
prefix = ""
extraPrefix = "pg_catalog."
schemaName = c.RelToken(-2).Str
}
if atWord {
prefix += c.RelToken(0).Str
prefix = c.RelToken(0).Str
}
end = int(c.RelToken(0).End)

Expand All @@ -152,23 +138,31 @@ func completeBuiltin(ctx context.Context, c compengine.Context) (compengine.Rows
return nil, nil
}

c.Trace("completing for %q (%d,%d)", prefix, start, end)
c.Trace("completing for %q (%d,%d) with schema %q", prefix, start, end, schemaName)
// TODO(knz): use the comment extraction functions from pg_catalog
// instead of crdb_internal. This requires exposing comments for
// built-in functions through pg_catalog.
const query = `
WITH p AS (SELECT DISTINCT proname FROM pg_catalog.pg_proc)
SELECT $4:::STRING || proname || '(' AS completion,
WITH p AS (
SELECT DISTINCT
proname, nspname
FROM pg_catalog.pg_proc
JOIN pg_catalog.pg_namespace n ON n.oid = pronamespace)
SELECT IF(length($4) > 0, pg_catalog.quote_ident($4:::STRING) || '.', '') ||
pg_catalog.quote_ident(proname) || '(' AS completion,
'functions' AS category,
substr(COALESCE((SELECT details
substr(COALESCE((
SELECT details
FROM "".crdb_internal.builtin_functions f2
WHERE f2.function = p.proname
WHERE f2.function = p.proname AND f2.schema = p.nspname
LIMIT 1), ''), e'[^\n]{0,80}') AS description,
$2:::INT AS start,
$3:::INT AS end
FROM p
WHERE left(proname, length($1:::STRING)) = $1:::STRING`
iter, err := c.Query(ctx, query, prefix, start, end, extraPrefix)
WHERE left(proname, length($1:::STRING)) = $1:::STRING
AND ((length($4) > 0 AND $4 = nspname)
OR (length($4) = 0 AND nspname = ANY current_schemas(true)))`
iter, err := c.Query(ctx, query, prefix, start, end, schemaName)
return iter, err
}

Expand Down
Loading

0 comments on commit 6f5d89e

Please sign in to comment.