-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
settings: Add syntax for cluster settings
Before this commit, there was no syntax to SET or SHOW cluster settings which exist for a given tenant. This commit adds the following syntax: * ALTER TENANT <id> SET CLUSTER SETTING <setting> = <value> * ALTER TENANT ALL SET CLUSTER SETTING <setting> = <value> * ALTER TENANT <id> RESET CLUSTER SETTING <setting> * ALTER TENANT ALL RESET CLUSTER SETTING <setting> * SHOW CLUSTER SETTING <setting> FOR TENANT <id> * SHOW [ALL] CLUSTER SETTINGS FOR TENANT <id> Note that the syntax is added but the underlying commands are currently unimplemented. The implementation of these commands will come with a subsequent commit. Release note (sql change): Added syntax for modifying cluster settings at the tenant level.
- Loading branch information
Showing
23 changed files
with
596 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
alter_stmt ::= | ||
alter_ddl_stmt | ||
| alter_role_stmt | ||
| alter_tenant_csetting_stmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
alter_tenant_csetting_stmt ::= | ||
'ALTER' 'TENANT' iconst64 'SET' 'CLUSTER' 'SETTING' var_name to_or_eq var_value | ||
| 'ALTER' 'TENANT' 'ALL' 'SET' 'CLUSTER' 'SETTING' var_name to_or_eq var_value | ||
| 'ALTER' 'TENANT' iconst64 'RESET' 'CLUSTER' 'SETTING' var_name | ||
| 'ALTER' 'TENANT' 'ALL' 'RESET' 'CLUSTER' 'SETTING' var_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sql | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/settings" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// alterTenantSetClusterSettingNode represents an | ||
// ALTER TENANT ... SET CLUSTER SETTING statement. | ||
type alterTenantSetClusterSettingNode struct { | ||
name string | ||
tenantID roachpb.TenantID | ||
tenantAll bool | ||
st *cluster.Settings | ||
setting settings.NonMaskedSetting | ||
// If value is nil, the setting should be reset. | ||
value tree.TypedExpr | ||
} | ||
|
||
// AlterTenantSetClusterSetting sets tenant level session variables. | ||
// Privileges: super user. | ||
func (p *planner) AlterTenantSetClusterSetting( | ||
ctx context.Context, n *tree.AlterTenantSetClusterSetting, | ||
) (planNode, error) { | ||
name := strings.ToLower(n.Name) | ||
st := p.EvalContext().Settings | ||
v, ok := settings.Lookup(name, settings.LookupForLocalAccess, p.ExecCfg().Codec.ForSystemTenant()) | ||
if !ok { | ||
return nil, errors.Errorf("unknown cluster setting '%s'", name) | ||
} | ||
|
||
if err := checkPrivilegesForSetting(ctx, p, name, "set"); err != nil { | ||
return nil, err | ||
} | ||
|
||
setting, ok := v.(settings.NonMaskedSetting) | ||
if !ok { | ||
return nil, errors.AssertionFailedf("expected writable setting, got %T", v) | ||
} | ||
|
||
if setting.Class() == settings.SystemOnly && !p.execCfg.Codec.ForSystemTenant() { | ||
return nil, pgerror.Newf(pgcode.InsufficientPrivilege, | ||
"setting %s is only settable in the system tenant", name) | ||
} | ||
|
||
value, err := p.getAndValidateTypedClusterSetting(ctx, name, n.Value, setting) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
node := alterTenantSetClusterSettingNode{ | ||
name: name, tenantID: n.TenantID, tenantAll: n.TenantAll, st: st, | ||
setting: setting, value: value, | ||
} | ||
return &node, nil | ||
} | ||
|
||
func (n *alterTenantSetClusterSettingNode) startExec(params runParams) error { | ||
return unimplemented.NewWithIssue(73857, | ||
`unimplemented: tenant-level cluster settings not supported`) | ||
} | ||
|
||
func (n *alterTenantSetClusterSettingNode) Next(_ runParams) (bool, error) { return false, nil } | ||
func (n *alterTenantSetClusterSettingNode) Values() tree.Datums { return nil } | ||
func (n *alterTenantSetClusterSettingNode) Close(_ context.Context) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.