-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
118575: schemachanger: Prep work for ALTER DATABASE ... CONFIGURE ZONE r=Xiang-Gu a=Xiang-Gu This PR contains three preparation commits for supporting zone configs in DSC. They should be rather uncontroversial and easy to review. See commit message for details. Informs: #117574 Epic: CRDB-31473 118679: sql: minor improvements around estimated row count r=yuzefovich a=yuzefovich This commit makes it so that we use the ceiling of the estimated row count in scans and aggregation. It also fixes recently-introduced bug that could cause integer overflow in the agg alloc code. Fixes: #118724. Epic: None Release note: None 118680: ui: change start and end values on stmt details charts r=maryliag a=maryliag Previously, we were using the data values to define the start and end date of charts, which could cause confusion, since users might think that is a bug of now showing data, when instead there is no data to show. This commit forces the start and end of the chart to be the selected period, this way we always show the correct period even if we don't have data to show. Fixes #102214 https://www.loom.com/share/3f463d82407b4ab186a5b0c1e1ab2369 Release note (ui change): On Statement Details page always show the entire selected period, instead of just the period that had data. 118769: logictest: skip `distsql_tenant_locality` under duress r=yuzefovich,michae2 a=rickystewart Flaky test: see #118627 Epic: None Release note: None Co-authored-by: Xiang Gu <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]> Co-authored-by: maryliag <[email protected]> Co-authored-by: Ricky Stewart <[email protected]>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// Copyright 2024 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 zone | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/config" | ||
"github.com/cockroachdb/cockroach/pkg/config/zonepb" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
"github.com/cockroachdb/errors" | ||
"github.com/gogo/protobuf/proto" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
type OptionValue struct { | ||
InheritValue bool | ||
ExplicitValue tree.TypedExpr | ||
} | ||
|
||
// ZoneConfigOption describes a Field one can set on a ZoneConfig. | ||
type ZoneConfigOption struct { | ||
Field config.Field | ||
RequiredType *types.T | ||
Setter func(*zonepb.ZoneConfig, tree.Datum) | ||
CheckAllowed func(context.Context, *cluster.Settings, tree.Datum) error | ||
} | ||
|
||
func loadYAML(dst interface{}, yamlString string) { | ||
if err := yaml.UnmarshalStrict([]byte(yamlString), dst); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// SupportedZoneConfigOptions indicates how to translate SQL variable | ||
// assignments in ALTER CONFIGURE ZONE to assignments to the member | ||
// fields of zonepb.ZoneConfig. | ||
var SupportedZoneConfigOptions map[tree.Name]ZoneConfigOption | ||
|
||
// ZoneOptionKeys contains the keys from suportedZoneConfigOptions in | ||
// deterministic order. Needed to make the event log output | ||
// deterministic. | ||
var ZoneOptionKeys []string | ||
|
||
func init() { | ||
opts := []ZoneConfigOption{ | ||
{ | ||
Field: config.RangeMinBytes, | ||
RequiredType: types.Int, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { c.RangeMinBytes = proto.Int64(int64(tree.MustBeDInt(d))) }, | ||
}, | ||
{ | ||
Field: config.RangeMaxBytes, | ||
RequiredType: types.Int, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { c.RangeMaxBytes = proto.Int64(int64(tree.MustBeDInt(d))) }, | ||
}, | ||
{ | ||
Field: config.GlobalReads, | ||
RequiredType: types.Bool, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { c.GlobalReads = proto.Bool(bool(tree.MustBeDBool(d))) }, | ||
CheckAllowed: func(ctx context.Context, settings *cluster.Settings, d tree.Datum) error { | ||
if !tree.MustBeDBool(d) { | ||
// Always allow the value to be unset. | ||
return nil | ||
} | ||
return base.CheckEnterpriseEnabled( | ||
settings, | ||
"global_reads", | ||
) | ||
}, | ||
}, | ||
{ | ||
Field: config.NumReplicas, | ||
RequiredType: types.Int, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { c.NumReplicas = proto.Int32(int32(tree.MustBeDInt(d))) }, | ||
}, | ||
{ | ||
Field: config.NumVoters, | ||
RequiredType: types.Int, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { c.NumVoters = proto.Int32(int32(tree.MustBeDInt(d))) }, | ||
}, | ||
{ | ||
Field: config.GCTTL, | ||
RequiredType: types.Int, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { | ||
c.GC = &zonepb.GCPolicy{TTLSeconds: int32(tree.MustBeDInt(d))} | ||
}, | ||
}, | ||
{ | ||
Field: config.Constraints, | ||
RequiredType: types.String, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { | ||
constraintsList := zonepb.ConstraintsList{ | ||
Constraints: c.Constraints, | ||
Inherited: c.InheritedConstraints, | ||
} | ||
loadYAML(&constraintsList, string(tree.MustBeDString(d))) | ||
c.Constraints = constraintsList.Constraints | ||
c.InheritedConstraints = false | ||
}, | ||
}, | ||
{ | ||
Field: config.VoterConstraints, | ||
RequiredType: types.String, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { | ||
voterConstraintsList := zonepb.ConstraintsList{ | ||
Constraints: c.VoterConstraints, | ||
Inherited: c.InheritedVoterConstraints(), | ||
} | ||
loadYAML(&voterConstraintsList, string(tree.MustBeDString(d))) | ||
c.VoterConstraints = voterConstraintsList.Constraints | ||
c.NullVoterConstraintsIsEmpty = true | ||
}, | ||
}, | ||
{ | ||
Field: config.LeasePreferences, | ||
RequiredType: types.String, | ||
Setter: func(c *zonepb.ZoneConfig, d tree.Datum) { | ||
loadYAML(&c.LeasePreferences, string(tree.MustBeDString(d))) | ||
c.InheritedLeasePreferences = false | ||
}, | ||
}, | ||
} | ||
SupportedZoneConfigOptions = make(map[tree.Name]ZoneConfigOption, len(opts)) | ||
ZoneOptionKeys = make([]string, len(opts)) | ||
for i, opt := range opts { | ||
name := opt.Field.String() | ||
key := tree.Name(name) | ||
if _, exists := SupportedZoneConfigOptions[key]; exists { | ||
panic(errors.AssertionFailedf("duplicate entry for key %s", name)) | ||
} | ||
SupportedZoneConfigOptions[key] = opt | ||
ZoneOptionKeys[i] = name | ||
} | ||
sort.Strings(ZoneOptionKeys) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.