Skip to content

Commit

Permalink
tenantsettings: delete overrides when removing tenant
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
RaduBerinde committed Feb 17, 2022
1 parent 3317ca8 commit e81c2e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/tenant_settings
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,21 @@ query T retry
SHOW CLUSTER SETTING kv.protectedts.reconciliation.interval
----
00:00:45

user host-cluster-root

# Verify that destroying a tenant cleans up any tenant-specific overrides.
statement ok
SELECT crdb_internal.create_tenant(1234)

# TODO(radu): replace with ALTER TENANT when it's available.
statement ok
INSERT INTO system.tenant_settings (tenant_id, name, value, value_type) VALUES (1234, 'sql.notices.enabled', 'true', 'b')

statement ok
SELECT crdb_internal.destroy_tenant(1234, true)

query I
SELECT count(*) FROM system.tenant_settings WHERE tenant_id = 1234
----
0
9 changes: 9 additions & 0 deletions pkg/sql/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ func GCTenantSync(ctx context.Context, execCfg *ExecutorConfig, info *descpb.Ten
return errors.Wrapf(err, "deleting tenant %d usage", info.ID)
}

if execCfg.Settings.Version.IsActive(ctx, clusterversion.TenantSettingsTable) {
if _, err := execCfg.InternalExecutor.ExecEx(
ctx, "delete-tenant-settings", txn, sessiondata.NodeUserSessionDataOverride,
`DELETE FROM system.tenant_settings WHERE tenant_id = $1`, info.ID,
); err != nil {
return errors.Wrapf(err, "deleting tenant %d settings", info.ID)
}
}

if !execCfg.Settings.Version.IsActive(ctx, clusterversion.PreSeedTenantSpanConfigs) {
return nil
}
Expand Down

0 comments on commit e81c2e7

Please sign in to comment.