Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tenantsettings: delete overrides when removing tenant #76716

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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