Skip to content

Commit

Permalink
Merge #116790
Browse files Browse the repository at this point in the history
116790: workload/schemachange: fix `CREATE SCHEMA` for the DSC r=rafiss a=chrisseto

### This PR is stacked on top of others!

Please consider reviewing those PRs first. This message will be removed once prerequisite PRs are merged and this one is rebased.

* 6e1ea5d is from #115357
* 230b588 is from #115358
* 4cc9b45 is from #115359
* be063ef is from #115360
* 4e89e34 is from #116788
* 95ffcf4 is from #116789

---

#### 89e761126789d2828e141339c34e739203da2310 workload/schemachange: fix `CREATE SCHEMA` for the DSC

Previously, `CREATE SCHEMA` would break if executed with the declarative
schema changer due to the inclusion of `AUTHORIZATION`.

This commit removes the `AUTHORIZATION` clause from `CREATE SCHEMA`
operations until it's support within the DSC.

Epic: none
Release note: None

Co-authored-by: Chris Seto <[email protected]>
  • Loading branch information
craig[bot] and chrisseto committed Dec 26, 2023
2 parents 53e4efd + 6bf526e commit 4f31fba
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
gosql "database/sql"
"fmt"
"net/url"
"os"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -63,23 +64,38 @@ func TestWorkload(t *testing.T) {
tdb.Exec(t, "GRANT admin TO testuser")
tdb.Exec(t, "SET CLUSTER SETTING sql.log.all_statements.enabled = true")

// Grab a backup and also print the namespace and descriptor tables upon
// failure.
// It's not clear how helpful this actually is but it doesn't hurt.
printRows := func(rows *gosql.Rows) {
dumpRows := func(name string, rows *gosql.Rows) {
t.Helper()
mat, err := sqlutils.RowsToStrMatrix(rows)
require.NoError(t, err)
fmt.Printf("rows:\n%s", sqlutils.MatrixToStr(mat))
require.NoError(t, os.WriteFile(fmt.Sprintf("%s/%s.rows", dir, name), []byte(sqlutils.MatrixToStr(mat)), 0666))
}

// Grab a backup, dump the namespace and descriptor tables upon failure.
defer func() {
if !t.Failed() {
return
}
printRows(tdb.Query(t, "SELECT id, encode(descriptor, 'hex') FROM system.descriptor"))
printRows(tdb.Query(t, "SELECT * FROM system.namespace"))
// Dump namespace and descriptor in their raw format. This is useful for
// processing results with some degree of scripting.
dumpRows("namespace", tdb.Query(t, `SELECT * FROM system.namespace`))
dumpRows("descriptor", tdb.Query(t, "SELECT id, encode(descriptor, 'hex') FROM system.descriptor"))
// Dump out a more human readable version of the above as well to allow for
// easy debugging by hand.
// NB: A LEFT JOIN is used here because not all descriptors (looking at you
// functions) have namespace entries.
dumpRows("ns-desc-json", tdb.Query(t, `
SELECT
"parentID",
"parentSchemaID",
descriptor.id,
name,
crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)
FROM system.descriptor
LEFT JOIN system.namespace ON namespace.id = descriptor.id
`))
tdb.Exec(t, "BACKUP DATABASE schemachange TO 'nodelocal://1/backup'")
t.Logf("backup and tracing data in %s", dir)
t.Logf("backup, tracing data, and system table dumps in %s", dir)
}()

pgURL, cleanup := sqlutils.PGUrl(t, tc.Server(0).AdvSQLAddr(), t.Name(), url.User("testuser"))
Expand Down
1 change: 0 additions & 1 deletion pkg/workload/schemachange/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ go_library(
deps = [
"//pkg/clusterversion",
"//pkg/roachpb",
"//pkg/security/username",
"//pkg/sql/catalog/catpb",
"//pkg/sql/catalog/colinfo",
"//pkg/sql/parser",
Expand Down
Loading

0 comments on commit 4f31fba

Please sign in to comment.