-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
sql: add validation to cascading zone configs #32861
Conversation
1ffde96
to
3bd4344
Compare
97a7de3
to
25d3f0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM. Well done. A few comments below.
Reviewed 10 of 10 files at r1, 6 of 6 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/cmd/roachtest/split.go, line 143 at r2 (raw file):
setRangeMaxBytes := func(maxBytes int) { stmtZone := fmt.Sprintf( "ALTER RANGE default CONFIGURE ZONE USING range_max_bytes = %d, range_min_bytes = COPY FROM PARENT",
please check with the powers that be that this test code is only used with 2.2/master; if it is also used with 2.1 you'll need to backport the syntax change to 2.1 before you can merge the test update.
pkg/sql/set_zone_config.go, line 472 at r2 (raw file):
// Per-replica constraints cannot be set unless num_replicas is explicitly set if err := zoneToWrite.ValidateTandemFields(); err != nil { return pgerror.NewErrorf(pgerror.CodeInternalError,
This is not an internal error. Internal errors are bugs in CockroachDB; also internal errors get uploaded to our telemetry data.
Here you are simply reporting an error to the client/user. You can use one of the other error codes instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/parser/sql.y, line 1416 at r1 (raw file):
var_set_list: var_name '=' COPY FROM PARENT
Also add the missing tests to parse_test.go
.
25d3f0e
to
6f8e49d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/cmd/roachtest/split.go, line 143 at r2 (raw file):
Previously, knz (kena) wrote…
please check with the powers that be that this test code is only used with 2.2/master; if it is also used with 2.1 you'll need to backport the syntax change to 2.1 before you can merge the test update.
This test uses 2.2 but good note, changes the other one to use the min bytes explicitly.
pkg/sql/set_zone_config.go, line 472 at r2 (raw file):
Previously, knz (kena) wrote…
This is not an internal error. Internal errors are bugs in CockroachDB; also internal errors get uploaded to our telemetry data.
Here you are simply reporting an error to the client/user. You can use one of the other error codes instead.
Done.
pkg/sql/parser/sql.y, line 1416 at r1 (raw file):
Previously, knz (kena) wrote…
Also add the missing tests to
parse_test.go
.
Done.
Approach looks fantastic to me! If @knz is happy, I'm happy. |
6f8e49d
to
3389c8c
Compare
pkg/sql/sem/tree/zone.go
Outdated
ctx.FormatNode(&node.Options) | ||
kvOptions := node.Options | ||
for i, kv := range kvOptions { | ||
if i > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma := ""
for ... {
WriteString(comma)
...
comma = ", "
}
pkg/sql/set_zone_config.go
Outdated
if optionStr.Len() > 0 { | ||
optionStr.WriteString(", ") | ||
} | ||
fmt.Fprintf(&optionStr, "%s = COPY FROM PARENT", string(*name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait what no you should not convert the name to a string!!
it's fmt("%s = ...", name)
244999a
to
a13ac50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 7 files at r3, 5 of 5 files at r4, 1 of 3 files at r5, 2 of 2 files at r6.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/set_zone_config.go, line 473 at r3 (raw file):
if err := zoneToWrite.ValidateTandemFields(); err != nil { return pgerror.NewErrorf(pgerror.CodeInvalidParameterValueError, fmt.Sprintf("could not validate zone config: %s", err)).SetHintf(
-
we use
%v
for errors not%s
-
NewErrorf
means you can use formatting -- so it'spgerror.NewErrorf(code, "foo %v", err)
notNewErrorf(code, fmt.Sprintf(...))
pkg/sql/set_zone_config.go, line 134 at r6 (raw file):
for _, opt := range n.Options { if _, alreadyExists := options[opt.Key]; alreadyExists { return nil, fmt.Errorf("duplicate zone config parameter: %q", tree.ErrString(&opt.Key))
while you're at it please convert the errors around here to pgerrors
pkg/sql/set_zone_config.go, line 216 at r6 (raw file):
optionStr.WriteString(", ") } fmt.Fprintf(&optionStr, "%s = COPY FROM PARENT", *name)
pass name
not *name
, they are not the same.
pkg/sql/set_zone_config.go, line 224 at r6 (raw file):
} if datum == tree.DNull { return fmt.Errorf("unsupported NULL value for %q", tree.ErrString(name))
ditto pgerror
pkg/sql/set_zone_config.go, line 231 at r6 (raw file):
optionStr.WriteString(", ") } fmt.Fprintf(&optionStr, "%s = %s", *name, datum)
ditto name
vs *name
Adds a `COPY FROM PARENT` command to zone configs to solidify a field. Solidifying a field means, the field will now be explicitly set to the value that applied to it. Any change to a parent zone on the field will no longer affect it. This change will allow people to do the following: `ALTER .... CONFIGURE ZONE USING range_min_bytes = ..., range_max_bytes = COPY FROM PARENT` instead of figuring out what the `RangeMaxBytes`should be and populating it manually. This change will allow us to add a validation constraint that tandem fields are set together (for more details see the cascading zone config RFC). Release note (sql change): New SQL command added. `ALTER ... CONFIGURE ZONE USING field_name = COPY FROM PARENT` now solidifies/explicitly sets the field.
As described in the cascading zone RFC, a few additional constraints are required on zone config usage so no zone is ever in an invalid state if their parent zone changes a value. Release note: None
The formatter is updated to now recognise the COPY FROM PARENT command when the value in the KVOption is nil. Release note: None
a13ac50
to
733cfb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR!
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/set_zone_config.go, line 473 at r3 (raw file):
Previously, knz (kena) wrote…
we use
%v
for errors not%s
NewErrorf
means you can use formatting -- so it'spgerror.NewErrorf(code, "foo %v", err)
notNewErrorf(code, fmt.Sprintf(...))
Done.
pkg/sql/set_zone_config.go, line 134 at r6 (raw file):
Previously, knz (kena) wrote…
while you're at it please convert the errors around here to pgerrors
Done.
pkg/sql/set_zone_config.go, line 216 at r6 (raw file):
Previously, knz (kena) wrote…
pass
name
not*name
, they are not the same.
Done.
pkg/sql/set_zone_config.go, line 224 at r6 (raw file):
Previously, knz (kena) wrote…
ditto pgerror
Done.
pkg/sql/set_zone_config.go, line 231 at r6 (raw file):
Previously, knz (kena) wrote…
ditto
name
vs*name
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 6 of 9 files at r7, 4 of 5 files at r8, 3 of 3 files at r9.
Reviewable status: complete! 1 of 0 LGTMs obtained
bors r+ |
32861: sql: add validation to cascading zone configs r=ridwanmsharif a=ridwanmsharif I found a few hours free and so took a second stab at #32059. Thought it'd be fun and new to try adding something to SQL for this, so @knz please feel free to tell me if what I've done here makes no sense. There are to be two changes to be made: 1) Allow for the `COPY FROM PARENT` command so users can do something like: ` ALTER ... CONFIGURE ZONE USING range_min_bytes = ..., range_max_bytes = COPY FROM PARENT` 2) Add validation to the zone configs so certain fields are written in tandem. The fields are: - `NumReplicas` and `Constraints` (Only when per-replica constraints are in use) - `RangeMinBytes` and `RangeMaxBytes` - `LeasePreferences` and `Constraints` Each of the changes are contained in their own commits. Co-authored-by: Ridwan Sharif <ridwan@cockroachlabs.com>
Build succeeded |
I found a few hours free and so took a second stab at #32059. Thought it'd be fun and new to try adding something to SQL for this, so @knz please feel free to tell me if what I've done here makes no sense.
There are to be two changes to be made:
Allow for the
COPY FROM PARENT
command so users can do something like:ALTER ... CONFIGURE ZONE USING range_min_bytes = ..., range_max_bytes = COPY FROM PARENT
Add validation to the zone configs so certain fields are written in tandem. The fields are:
NumReplicas
andConstraints
(Only when per-replica constraints are in use)RangeMinBytes
andRangeMaxBytes
LeasePreferences
andConstraints
Each of the changes are contained in their own commits.