Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
136683: crosscluster/logical: type check dest tenant spec in planHookFn r=dt a=msbutler

Fixes cockroachdb#136339

Release note: none

Co-authored-by: Michael Butler <[email protected]>
  • Loading branch information
craig[bot] and msbutler committed Dec 4, 2024
2 parents 78e363f + 3578514 commit 757b9ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/crosscluster/physical/alter_replication_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func alterReplicationJobHook(
}
}

// Ensure the TenantSpec is type checked, even if we don't use the result.
_, _, _, err = exprEval.TenantSpec(ctx, alterTenantStmt.TenantSpec)
if err != nil {
return nil, nil, nil, false, err
}

retentionTTLSeconds := defaultRetentionTTLSeconds
if ret, ok := options.GetRetention(); ok {
retentionTTLSeconds = ret
Expand Down
19 changes: 19 additions & 0 deletions pkg/crosscluster/physical/alter_replication_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,22 @@ func TestAlterTenantStartReplicationAfterRestore(t *testing.T) {
srcTime := srv.Clock().Now()
replicationtestutils.WaitUntilReplicatedTime(t, srcTime, db, catpb.JobID(ingestionJobID))
}

func TestAlterReplicationJobErrors(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()

srv, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{
DefaultTestTenant: base.TestControlsTenantsExplicitly})
defer srv.Stopper().Stop(ctx)

db := sqlutils.MakeSQLRunner(sqlDB)

t.Run("alter tenant subqueries", func(t *testing.T) {
// Regression test for #136339
db.ExpectErr(t, "subqueries are not allowed", "ALTER TENANT (select 't2') START REPLICATION OF t1 ON 'foo'")
})

}

0 comments on commit 757b9ab

Please sign in to comment.