Skip to content

Commit 3b69c58

Browse files
craig[bot]kev-caoangles-n-daemonsjeffswenson
committed
155780: roachtest: more logging on deleted sst in OR recovery r=msbutler a=kev-cao This commit adds more logging on the SST that is deleted in the OR recovery roachtest to determine exactly what backed up span and data was deleted. Epic: None Release note: None 155821: optbuilder, sql: fix stable sql api edge cases r=angles-n-daemons a=angles-n-daemons The logictests have flushed out a handful of situations in which the stable sql api gates block unexpectedly. Examples of this include unsafe access in safe builtin execution, nested delegates, and other similar use cases. What was required to fix them was to update the way we unguard the unsafe internals during query planning. Fixes: #154675 Epic: CRDB-55267 Release note: None 156483: logical: do not allow the REFCURSOR type r=jeffswenson a=jeffswenson This removes LDR support for the REFCURSOR type. The crud writer does not support it because REFCURSOR does not support the equality SQL operator. This removal is unlikely to impact any users. The REFCURSOR is a weird type that should not show up in a durable table. If the user really needs this type for some reason, they could store they type as a STRING and convert it back to a REFCURSOR when reading from the table. Epic: CRDB-48647 Release note: none Co-authored-by: Kevin Cao <[email protected]> Co-authored-by: Brian Dillmann <[email protected]> Co-authored-by: Jeff Swenson <[email protected]>
4 parents e484d80 + 6fc84e2 + 71f7cab + 5ab8258 commit 3b69c58

File tree

8 files changed

+64
-9
lines changed

8 files changed

+64
-9
lines changed

pkg/cmd/roachtest/tests/mixed_version_backup.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,9 +2383,11 @@ func (d *BackupRestoreTestDriver) deleteUserTableSST(
23832383
ctx context.Context, l *logger.Logger, db *gosql.DB, collection *backupCollection,
23842384
) error {
23852385
var sstPath string
2386+
var startPretty, endPretty string
2387+
var sizeBytes, numRows int
23862388
if err := db.QueryRowContext(
23872389
ctx,
2388-
`SELECT path FROM
2390+
`SELECT path, start_pretty, end_pretty, size_bytes, rows FROM
23892391
(
23902392
SELECT row_number() OVER (), * FROM
23912393
[SHOW BACKUP FILES FROM LATEST IN $1]
@@ -2394,14 +2396,17 @@ func (d *BackupRestoreTestDriver) deleteUserTableSST(
23942396
ORDER BY row_number DESC
23952397
LIMIT 1`,
23962398
collection.uri(),
2397-
).Scan(&sstPath); err != nil {
2399+
).Scan(&sstPath, &startPretty, &endPretty, &sizeBytes, &numRows); err != nil {
23982400
return errors.Wrapf(err, "failed to get SST path from %s", collection.uri())
23992401
}
24002402
uri, err := url.Parse(collection.uri())
24012403
if err != nil {
24022404
return errors.Wrapf(err, "failed to parse backup collection URI %q", collection.uri())
24032405
}
2404-
l.Printf("deleting sst %s at %s", sstPath, uri)
2406+
l.Printf(
2407+
"deleting sst %s at %s: covering %d bytes and %d rows in [%s, %s)",
2408+
sstPath, uri, sizeBytes, numRows, startPretty, endPretty,
2409+
)
24052410
storage, err := cloud.ExternalStorageFromURI(
24062411
ctx,
24072412
collection.uri(),

pkg/crosscluster/logical/logical_replication_job_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,11 @@ func TestLogicalReplicationCreationChecks(t *testing.T) {
28332833
jobutils.WaitForJobToCancel(t, dbA, jobAID)
28342834
replicationtestutils.WaitForAllProducerJobsToFail(t, dbB)
28352835

2836+
// Check that REFCURSOR columns are not allowed.
2837+
dbA.Exec(t, "CREATE TABLE tab_with_refcursor (pk INT PRIMARY KEY, curs REFCURSOR)")
2838+
dbB.Exec(t, "CREATE TABLE b.tab_with_refcursor (pk INT PRIMARY KEY, curs REFCURSOR)")
2839+
expectErr(t, "tab_with_refcursor", "cannot create logical replication stream: column curs is a RefCursor")
2840+
28362841
// Add different default values to to the source and dest, verify the stream
28372842
// can be created, and that the default value is sent over the wire.
28382843
dbA.Exec(t, "CREATE TABLE tab2 (pk INT PRIMARY KEY, payload STRING DEFAULT 'cat')")

pkg/sql/catalog/tabledesc/logical_replication_helpers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ func CheckLogicalReplicationCompatibility(
5858
return pgerror.Wrapf(err, pgcode.InvalidTableDefinition, cannotLDRMsg)
5959
}
6060

61+
if err := checkForbiddenTypes(dst); err != nil {
62+
return pgerror.Wrapf(err, pgcode.InvalidTableDefinition, cannotLDRMsg)
63+
}
64+
65+
return nil
66+
}
67+
68+
func checkForbiddenTypes(dst *descpb.TableDescriptor) error {
69+
for _, col := range dst.Columns {
70+
// RefCursor is not supported by LDR because it has no definition of
71+
// equality. It's a weird type that should never exist in a durable table
72+
// since a cursor is a session scoped entity.
73+
if col.Type.Family() == types.RefCursorFamily {
74+
return errors.Newf("column %s is a RefCursor", col.Name)
75+
}
76+
}
6177
return nil
6278
}
6379

pkg/sql/opt/optbuilder/builder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,11 @@ func (b *Builder) maybeTrackUserDefinedTypeDepsForViews(texpr tree.TypedExpr) {
593593
// DisableUnsafeInternalCheck is used to disable the check that the
594594
// prevents external users from accessing unsafe internals.
595595
func (b *Builder) DisableUnsafeInternalCheck() func() {
596+
// Already in the middle of a disabled section.
597+
if b.skipUnsafeInternalsCheck {
598+
return func() {}
599+
}
600+
596601
b.skipUnsafeInternalsCheck = true
597602
var cleanup func()
598603
if b.catalog != nil {

pkg/sql/opt/optbuilder/routine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func (b *Builder) buildUDF(
5151
))
5252
}
5353

54+
// builtins should have access to unsafe internals
55+
if o.Type == tree.BuiltinRoutine {
56+
defer b.DisableUnsafeInternalCheck()()
57+
}
58+
5459
// Check for execution privileges for user-defined overloads. Built-in
5560
// overloads do not need to be checked.
5661
if o.Type == tree.UDFRoutine {

pkg/sql/opt_catalog.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,9 @@ func (oc *optCatalog) codec() keys.SQLCodec {
744744
return oc.planner.ExecCfg().Codec
745745
}
746746

747-
// DisableUnsafeInternalCheck sets the planners skipUnsafeInternalsCheck
748-
// to true, and returns a function which reverses it to false.
747+
// DisableUnsafeInternalCheck forwards the call to the planner.
749748
func (oc *optCatalog) DisableUnsafeInternalCheck() func() {
750-
oc.planner.skipUnsafeInternalsCheck = true
751-
return func() {
752-
oc.planner.skipUnsafeInternalsCheck = false
753-
}
749+
return oc.planner.DisableUnsafeInternalsCheck()
754750
}
755751

756752
// optView is a wrapper around catalog.TableDescriptor that implements

pkg/sql/planner.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,19 @@ func (p *planner) InternalSQLTxn() descs.Txn {
676676
return &p.internalSQLTxn
677677
}
678678

679+
// DisableUnsafeInternalCheck sets the skipUnsafeInternalsCheck property
680+
// to true, and returns a function which reverses it to false.
681+
func (p *planner) DisableUnsafeInternalsCheck() func() {
682+
if p.skipUnsafeInternalsCheck {
683+
return func() {}
684+
}
685+
686+
p.skipUnsafeInternalsCheck = true
687+
return func() {
688+
p.skipUnsafeInternalsCheck = false
689+
}
690+
}
691+
679692
func (p *planner) regionsProvider() *regions.Provider {
680693
if txn := p.InternalSQLTxn(); txn != nil {
681694
_ = txn.Regions() // force initialization

pkg/sql/unsafesql/unsafesql_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ func TestAccessCheckServer(t *testing.T) {
231231
Passes: false,
232232
LogsDenied: true,
233233
},
234+
{
235+
// test nested delegates
236+
Query: "SHOW JOBS WHEN COMPLETE SELECT job_id FROM [SHOW JOBS]",
237+
Passes: true,
238+
},
239+
{
240+
// unexpected unsafe builtin access
241+
Query: "SELECT col_description(0, 0)",
242+
Passes: true,
243+
},
234244
} {
235245
t.Run(fmt.Sprintf("query=%s,internal=%t,allowUnsafe=%t", test.Query, test.Internal, test.AllowUnsafeInternals), func(t *testing.T) {
236246
accessedSpy.Reset()

0 commit comments

Comments
 (0)