Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
106121: sql: session var `disable_drop_virtual_cluster` r=yuzefovich a=knz

Informs cockroachdb#106068.
Epic: CRDB-29380

This replaces `disable_drop_tenant`, together with the cluster setting `sql.drop_virtual_cluster.enabled` (replaces
`sql.drop_tenant.enabled`).

We are OK with this breaking change since the feature was not yet exposed to end-users.

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed Jul 6, 2023
2 parents 818aec8 + ab28123 commit 06fde61
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pkg/configprofiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ var virtClusterInitTasks = []autoconfigpb.Task{
// to range coalescing have not been solved yet).
"SET CLUSTER SETTING spanconfig.storage_coalesce_adjacent.enabled = false",
"SET CLUSTER SETTING spanconfig.tenant_coalesce_adjacent.enabled = false",
// Make the operator double-check tenant deletions.
"SET CLUSTER SETTING sql.drop_tenant.enabled = false",
// Make the operator double-check virtual cluster deletions.
"SET CLUSTER SETTING sql.drop_virtual_cluster.enabled = false",
},
nil, /* txnSQL */
),
Expand Down
4 changes: 2 additions & 2 deletions pkg/configprofiles/testdata/virtual-app
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WHERE variable IN (
'sql.multi_region.allow_abstractions_for_secondary_tenants.enabled',
'spanconfig.storage_coalesce_adjacent.enabled',
'spanconfig.tenant_coalesce_adjacent.enabled',
'sql.drop_tenant.enabled',
'sql.drop_virtual_cluster.enabled',
'sql.create_tenant.default_template',
'server.controller.default_tenant',
'kv.rangefeed.enabled',
Expand All @@ -33,7 +33,7 @@ server.secondary_tenants.redact_trace.enabled false
spanconfig.storage_coalesce_adjacent.enabled false
spanconfig.tenant_coalesce_adjacent.enabled false
sql.create_tenant.default_template template
sql.drop_tenant.enabled false
sql.drop_virtual_cluster.enabled false
sql.multi_region.allow_abstractions_for_secondary_tenants.enabled true
sql.zone_configs.allow_for_secondary_tenant.enabled true

Expand Down
4 changes: 2 additions & 2 deletions pkg/configprofiles/testdata/virtual-app-repl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WHERE variable IN (
'sql.multi_region.allow_abstractions_for_secondary_tenants.enabled',
'spanconfig.storage_coalesce_adjacent.enabled',
'spanconfig.tenant_coalesce_adjacent.enabled',
'sql.drop_tenant.enabled',
'sql.drop_virtual_cluster.enabled',
'sql.create_tenant.default_template',
'server.controller.default_tenant',
'kv.rangefeed.enabled',
Expand All @@ -33,7 +33,7 @@ server.secondary_tenants.redact_trace.enabled false
spanconfig.storage_coalesce_adjacent.enabled false
spanconfig.tenant_coalesce_adjacent.enabled false
sql.create_tenant.default_template template
sql.drop_tenant.enabled false
sql.drop_virtual_cluster.enabled false
sql.multi_region.allow_abstractions_for_secondary_tenants.enabled true
sql.zone_configs.allow_for_secondary_tenant.enabled true

Expand Down
4 changes: 2 additions & 2 deletions pkg/configprofiles/testdata/virtual-noapp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WHERE variable IN (
'sql.multi_region.allow_abstractions_for_secondary_tenants.enabled',
'spanconfig.storage_coalesce_adjacent.enabled',
'spanconfig.tenant_coalesce_adjacent.enabled',
'sql.drop_tenant.enabled',
'sql.drop_virtual_cluster.enabled',
'sql.create_tenant.default_template',
'server.controller.default_tenant',
'kv.rangefeed.enabled',
Expand All @@ -28,7 +28,7 @@ server.secondary_tenants.redact_trace.enabled false
spanconfig.storage_coalesce_adjacent.enabled false
spanconfig.tenant_coalesce_adjacent.enabled false
sql.create_tenant.default_template template
sql.drop_tenant.enabled false
sql.drop_virtual_cluster.enabled false
sql.multi_region.allow_abstractions_for_secondary_tenants.enabled true
sql.zone_configs.allow_for_secondary_tenant.enabled true

Expand Down
4 changes: 2 additions & 2 deletions pkg/configprofiles/testdata/virtual-noapp-repl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WHERE variable IN (
'sql.multi_region.allow_abstractions_for_secondary_tenants.enabled',
'spanconfig.storage_coalesce_adjacent.enabled',
'spanconfig.tenant_coalesce_adjacent.enabled',
'sql.drop_tenant.enabled',
'sql.drop_virtual_cluster.enabled',
'sql.create_tenant.default_template',
'server.controller.default_tenant',
'kv.rangefeed.enabled',
Expand All @@ -28,7 +28,7 @@ server.secondary_tenants.redact_trace.enabled false
spanconfig.storage_coalesce_adjacent.enabled false
spanconfig.tenant_coalesce_adjacent.enabled false
sql.create_tenant.default_template template
sql.drop_tenant.enabled false
sql.drop_virtual_cluster.enabled false
sql.multi_region.allow_abstractions_for_secondary_tenants.enabled true
sql.zone_configs.allow_for_secondary_tenant.enabled true

Expand Down
1 change: 1 addition & 0 deletions pkg/settings/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var retiredSettings = map[string]struct{}{
// renamed.
"spanconfig.host_coalesce_adjacent.enabled": {},
"sql.defaults.experimental_stream_replication.enabled": {},
"sql.drop_tenant.enabled": {},

// removed as of 23.2.
"sql.log.unstructured_entries.enabled": {},
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,8 @@ var errTransactionInProgress = errors.New("there is already a transaction in pro
const sqlTxnName string = "sql txn"
const metricsSampleInterval = 10 * time.Second

// enableDropTenant (or rather, its inverted boolean value) defines
// the default value for the session var "disable_drop_tenant".
// enableDropVirtualCluster (or rather, its inverted boolean value) defines
// the default value for the session var "disable_drop_virtual_cluster".
//
// Note:
// - We use a cluster setting here instead of a default role option
Expand All @@ -756,10 +756,10 @@ const metricsSampleInterval = 10 * time.Second
// - The session var is named "disable_" because we want the Go
// default value (false) to mean that tenant deletion is enabled.
// This is needed for backward-compatibility with Cockroach Cloud.
var enableDropTenant = settings.RegisterBoolSetting(
var enableDropVirtualCluster = settings.RegisterBoolSetting(
settings.SystemOnly,
"sql.drop_tenant.enabled",
"default value (inverted) for the disable_drop_tenant session setting",
"sql.drop_virtual_cluster.enabled",
"default value (inverted) for the disable_virtual_cluster session setting",
true,
)

Expand Down Expand Up @@ -3226,8 +3226,8 @@ func (m *sessionDataMutator) SetSafeUpdates(val bool) {
m.data.SafeUpdates = val
}

func (m *sessionDataMutator) SetDisableDropTenant(val bool) {
m.data.DisableDropTenant = val
func (m *sessionDataMutator) SetDisableDropVirtualCluster(val bool) {
m.data.DisableDropVirtualCluster = val
}

func (m *sessionDataMutator) SetCheckFunctionBodies(val bool) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -5275,7 +5275,7 @@ default_transaction_read_only off
default_transaction_use_follower_reads off
default_with_oids off
descriptor_validation on
disable_drop_tenant off
disable_drop_virtual_cluster off
disable_hoist_projection_in_join_limitation off
disable_partially_distributed_plans off
disable_plan_gists off
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/tenant
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ DROP TENANT tmpl
statement ok
RESET CLUSTER SETTING sql.create_tenant.default_template

subtest block_drop_tenant
subtest block_drop_virtual_cluster

statement ok
SET disable_drop_tenant = 'true'
SET disable_drop_virtual_cluster = 'true'

statement ok
CREATE TENANT nodelete
Expand All @@ -499,7 +499,7 @@ statement error rejected.*irreversible data loss
DROP TENANT nodelete

statement ok
RESET disable_drop_tenant
RESET disable_drop_virtual_cluster

statement ok
DROP TENANT nodelete
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/sessiondatapb/local_only_session_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ message LocalOnlySessionData {
int64 prepared_statements_cache_size = 97;
// StreamerEnabled controls whether the Streamer API can be used.
bool streamer_enabled = 98;
// DisableDropTenant causes errors when the client
// attempts to drop tenants or tenant records.
bool disable_drop_tenant = 99;
// DisableDropVirtualCluster causes errors when the client
// attempts to drop virtual clusters or tenant records.
bool disable_drop_virtual_cluster = 99;
// MultipleActivePortalEnabled determines if the pgwire portal execution
// for certain queries can be paused. If true, portals with read-only SELECT
// query without sub/post queries can be executed in interleaving manner, but
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/tenant_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
func (p *planner) DropTenantByID(
ctx context.Context, tenID uint64, synchronousImmediateDrop, ignoreServiceMode bool,
) error {
if p.SessionData().DisableDropTenant || p.SessionData().SafeUpdates {
if p.SessionData().DisableDropVirtualCluster || p.SessionData().SafeUpdates {
err := errors.Newf("DROP VIRTUAL CLUSTER causes irreversible data loss")
err = errors.WithMessage(err, "rejected (via sql_safe_updates or disable_drop_tenant)")
err = errors.WithMessage(err, "rejected (via sql_safe_updates or disable_drop_virtual_cluster)")
err = pgerror.WithCandidateCode(err, pgcode.Warning)
return err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -1566,17 +1566,17 @@ var varGen = map[string]sessionVar{
},

// CockroachDB extension.
`disable_drop_tenant`: {
`disable_drop_virtual_cluster`: {
Hidden: true,
Get: func(evalCtx *extendedEvalContext, _ *kv.Txn) (string, error) {
return formatBoolAsPostgresSetting(evalCtx.SessionData().DisableDropTenant), nil
return formatBoolAsPostgresSetting(evalCtx.SessionData().DisableDropVirtualCluster), nil
},
Set: func(_ context.Context, m sessionDataMutator, s string) error {
b, err := paramparse.ParseBoolVar("disable_drop_tenant", s)
b, err := paramparse.ParseBoolVar("disable_drop_virtual_cluster", s)
if err != nil {
return err
}
m.SetDisableDropTenant(b)
m.SetDisableDropVirtualCluster(b)
return nil
},
GlobalDefault: func(sv *settings.Values) string {
Expand All @@ -1589,7 +1589,7 @@ var varGen = map[string]sessionVar{
// - The session var is named "disable_" because we want the Go
// default value (false) to mean that tenant deletion is enabled.
// This is needed for backward-compatibility with Cockroach Cloud.
return formatBoolAsPostgresSetting(!enableDropTenant.Get(sv))
return formatBoolAsPostgresSetting(!enableDropVirtualCluster.Get(sv))
},
},

Expand Down

0 comments on commit 06fde61

Please sign in to comment.