Skip to content

Commit

Permalink
builtins: remove crdb_internal.gc_tenant
Browse files Browse the repository at this point in the history
This is an internal function that was deprecated a while ago. It's no
longer used since DestroyTenant is used instead.

Release note: None
  • Loading branch information
rafiss committed Dec 7, 2023
1 parent 43b0dd3 commit 25acf63
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 77 deletions.
5 changes: 0 additions & 5 deletions pkg/sql/faketreeeval/evalctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,6 @@ func (c *DummyTenantOperator) DropTenantByID(
return errors.WithStack(errEvalTenant)
}

// GCTenant is part of the tree.TenantOperator interface.
func (c *DummyTenantOperator) GCTenant(_ context.Context, _ uint64) error {
return errors.WithStack(errEvalTenant)
}

// UpdateTenantResourceLimits is part of the tree.TenantOperator interface.
func (c *DummyTenantOperator) UpdateTenantResourceLimits(
_ context.Context,
Expand Down
8 changes: 0 additions & 8 deletions pkg/sql/logictest/testdata/logic_test/tenant_builtins
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ id active name
10 true tenant-number-ten
11 true tenant-number-eleven

# Garbage collect a non-drop tenant fails.

query error tenant 5 is not in data state DROP
SELECT crdb_internal.gc_tenant(5)

# Note this just marks the tenant as dropped but does not call GC.

statement ok
Expand Down Expand Up @@ -273,9 +268,6 @@ SELECT crdb_internal.create_tenant('not-allowed')
statement error user testuser does not have MANAGEVIRTUALCLUSTER system privilege
DROP TENANT [1]

statement error crdb_internal.gc_tenant\(\): user testuser does not have REPAIRCLUSTERMETADATA system privilege
SELECT crdb_internal.gc_tenant(314)

user root

subtest avoid_tenant_id_reuse
Expand Down
27 changes: 0 additions & 27 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -6798,33 +6798,6 @@ Parameters:` + randgencfg.ConfigDoc,
},
),

"crdb_internal.gc_tenant": makeBuiltin(
// TODO(jeffswenson): Delete crdb_internal.gc_tenant after the DestroyTenant
// changes are deployed to all Cockroach Cloud serverless hosts.
tree.FunctionProperties{
Category: builtinconstants.CategoryMultiTenancy,
Undocumented: true,
},
tree.Overload{
Types: tree.ParamTypes{
{Name: "id", Typ: types.Int},
},
ReturnType: tree.FixedReturnType(types.Int),
Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) {
sTenID, err := mustBeDIntInTenantRange(args[0])
if err != nil {
return nil, err
}
if err := evalCtx.Tenant.GCTenant(ctx, uint64(sTenID)); err != nil {
return nil, err
}
return args[0], nil
},
Info: "Garbage collects a tenant with the provided ID. Must be run by the System tenant.",
Volatility: volatility.Volatile,
},
),

// Used to configure the tenant token bucket. See UpdateTenantResourceLimits.
"crdb_internal.update_tenant_resource_limits": makeBuiltin(
tree.FunctionProperties{
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/sem/builtins/fixed_oids.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,6 @@ var builtinOidsArray = []string{
1351: `crdb_internal.unsafe_delete_namespace_entry(parent_id: int, parent_schema_id: int, name: string, desc_id: int) -> bool`,
1352: `crdb_internal.unsafe_delete_namespace_entry(parent_id: int, parent_schema_id: int, name: string, desc_id: int, force: bool) -> bool`,
1353: `crdb_internal.sql_liveness_is_alive(session_id: bytes) -> bool`,
1354: `crdb_internal.gc_tenant(id: int) -> int`,
1355: `crdb_internal.update_tenant_resource_limits(tenant_id: int, available_request_units: float, refill_rate: float, max_burst_request_units: float, as_of: timestamp, as_of_consumed_request_units: float) -> int`,
1356: `crdb_internal.compact_engine_span(node_id: int, store_id: int, start_key: bytes, end_key: bytes) -> bool`,
1357: `crdb_internal.increment_feature_counter(feature: string) -> bool`,
Expand Down
5 changes: 0 additions & 5 deletions pkg/sql/sem/eval/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,6 @@ type TenantOperator interface {
// the gc job will not wait for a GC ttl.
DropTenantByID(ctx context.Context, tenantID uint64, synchronous, ignoreServiceMode bool) error

// GCTenant attempts to garbage collect a DROP tenant from the system. Upon
// success it also removes the tenant record.
// It returns an error if the tenant does not exist.
GCTenant(ctx context.Context, tenantID uint64) error

// LookupTenantID returns the ID for the given tenant name.o
LookupTenantID(ctx context.Context, tenantName roachpb.TenantName) (roachpb.TenantID, error)

Expand Down
31 changes: 0 additions & 31 deletions pkg/sql/tenant_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/spanconfig"
"github.com/cockroachdb/cockroach/pkg/sql/isql"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
"github.com/cockroachdb/cockroach/pkg/sql/syntheticprivilege"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -124,32 +122,3 @@ func clearTenant(ctx context.Context, execCfg *ExecutorConfig, info *mtinfopb.Te

return errors.Wrapf(execCfg.DB.Run(ctx, b), "clearing tenant %d data", info.ID)
}

// GCTenant implements the tree.TenantOperator interface.
// This is the function used by the crdb_internal.gc_tenant built-in function.
// It garbage-collects a tenant already in the DROP state.
//
// TODO(jeffswenson): Delete crdb_internal.gc_tenant after the DestroyTenant
// changes are deployed to all Cockroach Cloud serverless hosts.
func (p *planner) GCTenant(ctx context.Context, tenID uint64) error {
if !p.extendedEvalCtx.TxnIsSingleStmt {
return errors.Errorf("gc_tenant cannot be used inside a multi-statement transaction")
}
if err := p.CheckPrivilege(ctx, syntheticprivilege.GlobalPrivilegeObject, privilege.REPAIRCLUSTERMETADATA); err != nil {
return err
}
info, err := GetTenantRecordByID(ctx, p.InternalSQLTxn(), roachpb.MustMakeTenantID(tenID), p.ExecCfg().Settings)
if err != nil {
return errors.Wrapf(err, "retrieving tenant %d", tenID)
}

// Confirm tenant is ready to be cleared.
if info.DataState != mtinfopb.DataStateDrop {
return errors.Errorf("tenant %d is not in data state DROP", info.ID)
}

_, err = createGCTenantJob(
ctx, p.ExecCfg().JobRegistry, p.InternalSQLTxn(), p.User(), tenID, false, /* synchronous */
)
return err
}

0 comments on commit 25acf63

Please sign in to comment.