spanconfig: add Record constructor and validation#77349
spanconfig: add Record constructor and validation#77349craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
ecdfbea to
f5177fa
Compare
f5177fa to
e182666
Compare
|
Will rebase once #77338 is in. |
e182666 to
adbe7ba
Compare
arulajmani
left a comment
There was a problem hiding this comment.
Thanks for doing this! Looks good modulo couple minor comments/suggestions.
Reviewed 14 of 14 files at r1, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @adityamaru)
pkg/roachpb/span_config.go, line 89 at r1 (raw file):
return errors.AssertionFailedf("LeasePreferences set on system span config") } if s.RangefeedEnabled == true {
The linter is complaining about simplifying this to just if s.RangefeedEnabled {
pkg/roachpb/span_config.go, line 91 at r1 (raw file):
if s.RangefeedEnabled == true { return errors.AssertionFailedf("RangefeedEnabled set on system span config") }
Do we want to check ExcludeFromBackup here as well?
pkg/roachpb/span_config.proto, line 189 at r1 (raw file):
// Next ID: 12 // // When adding a field, also add a check a to `ValidateSystemTargetSpanConfig`
nit: you could add a test that codifies this, something similar in essence to what we do in TestValidateCoversAllDescriptorFields.
pkg/spanconfig/spanconfig.go, line 277 at r1 (raw file):
// Record ties a target to its corresponding config. // // Use `MakeRecord` to construct a new Record instead of directly reaching for
Instead of this comment, how about enforcing this in code by making Target and Config private fields and adding getters?
pkg/spanconfig/spanconfig.go, line 279 at r1 (raw file):
// Use `MakeRecord` to construct a new Record instead of directly reaching for // this struct to ensure proper validation. type Record struct {
super nit: should we pull this struct, its getters, and constructors into its own file?
pkg/spanconfig/spanconfig.go, line 289 at r1 (raw file):
// MakeRecord returns a Record with the specified Target and SpanConfig. If the // Record targets a SystemTarget, we also validate the SpanConfig. func MakeRecord(target Target, cfg roachpb.SpanConfig) (Record, error) {
Let's add a basic test that ensures we return validation errors correctly?
pkg/spanconfig/spanconfig.go, line 293 at r1 (raw file):
if err := cfg.ValidateSystemTargetSpanConfig(); err != nil { return Record{}, errors.AssertionFailedf("failed to validate SystemTarget SpanConfig: %+v", err.Error())
nit: we could panic here, like we do in MakeTargetFromSpan and a few other places in target.go where we know for sure it is a programming mistake if this ever happens.
pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 180 at r1 (raw file):
} } clusterSystemRecord, err := spanconfig.MakeRecord(
nit: missing error check
adbe7ba to
99c7feb
Compare
adityamaru
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @adityamaru and @arulajmani)
pkg/roachpb/span_config.go, line 89 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
The linter is complaining about simplifying this to just
if s.RangefeedEnabled {
Done.
pkg/roachpb/span_config.go, line 91 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
Do we want to check
ExcludeFromBackuphere as well?
Done.
pkg/spanconfig/spanconfig.go, line 277 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
Instead of this comment, how about enforcing this in code by making
TargetandConfigprivate fields and adding getters?
Done.
pkg/spanconfig/spanconfig.go, line 279 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
super nit: should we pull this struct, its getters, and constructors into its own file?
Done.
pkg/spanconfig/spanconfig.go, line 293 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
nit: we could panic here, like we do in
MakeTargetFromSpanand a few other places intarget.gowhere we know for sure it is a programming mistake if this ever happens.
meh I'm generally panic averse. Most of the places already had proper error handling so it wasn't too painful. In light of issues like #76734 and having being bitten by panics in bulk code I prefer to return an error.
pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 180 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
nit: missing error check
oops, done.
99c7feb to
e54bfd2
Compare
|
I want CI to shake out any tests I might have forgotten to update so I'd hold off reviewing for a bit. I also need to add a simple validation test still but addressed other comments. |
e54bfd2 to
5d6c270
Compare
arulajmani
left a comment
There was a problem hiding this comment.
modulo a couple minor comments.
Reviewed 18 of 20 files at r2, 1 of 1 files at r3, 5 of 5 files at r4, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @adityamaru)
pkg/spanconfig/spanconfig.go, line 289 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
Let's add a basic test that ensures we return validation errors correctly?
The line this comment was referencing has moved, but were hoping to do this?
pkg/spanconfig/spanconfig.go, line 293 at r1 (raw file):
Previously, adityamaru (Aditya Maru) wrote…
meh I'm generally panic averse. Most of the places already had proper error handling so it wasn't too painful. In light of issues like #76734 and having being bitten by panics in bulk code I prefer to return an error.
Okay, no strong preference.
pkg/spanconfig/spanconfig.go, line 369 at r4 (raw file):
record, err := MakeRecord(target, roachpb.SpanConfig{}) // delete if err != nil { log.Fatalf(context.Background(), "%+v", err)
I don't think context.Background() is correct here is it? We should either thread in the context or panic here, it's pretty much the same effect. Alternatively, you could bubble up the error.
We should be a consistent in how we handle these MakeRecord errors though -- if we're okay crashing the node here, then let's just do it in the constructor to MakeRecord as well. If we're not, then let's bubble up the error here as well.
5d6c270 to
4077ffc
Compare
adityamaru
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru and @arulajmani)
pkg/spanconfig/spanconfig.go, line 289 at r1 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
The line this comment was referencing has moved, but were hoping to do this?
Done.
pkg/spanconfig/spanconfig.go, line 369 at r4 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
I don't think
context.Background()is correct here is it? We should either thread in the context or panic here, it's pretty much the same effect. Alternatively, you could bubble up the error.We should be a consistent in how we handle these
MakeRecorderrors though -- if we're okay crashing the node here, then let's just do it in the constructor toMakeRecordas well. If we're not, then let's bubble up the error here as well.
agreed, switched to bubble up the error.
4077ffc to
63bcc8d
Compare
arulajmani
left a comment
There was a problem hiding this comment.
![]()
Reviewed 9 of 10 files at r5, 2 of 2 files at r6, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru)
|
Looks like a bazel flake. TFTR! bors r=arulajmani |
|
Build failed (retrying...): |
|
Build failed (retrying...): |
|
Build failed (retrying...): |
|
Build failed: |
63bcc8d to
ae7c2d3
Compare
|
bors r=arulajmani |
|
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
|
bors r=arulajmani |
|
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
|
🤷 unsure whatsup, will try to bors in a bit. |
|
bors r=arulajmani |
|
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
|
bors r+ |
|
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
|
GitHub status checks took too long to complete, so bors is giving up. You can adjust bors configuration to have it wait longer if you like. |
|
bors r=arulajmani |
|
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
|
GitHub status checks took too long to complete, so bors is giving up. You can adjust bors configuration to have it wait longer if you like. |
This change adds a constructor method that returns a new `spanconfig.Record` and conditionally performs some validation if the target is a SystemTarget. Informs: cockroachdb#73727 Release note: None Release justification: low-risk updates to new functionality
ae7c2d3 to
99c9691
Compare
|
bors r+ |
|
Build succeeded: |
This change adds a constructor method that returns
a new
spanconfig.Recordand conditionally performssome validation if the target is a SystemTarget.
Informs: #73727
Release note: None
Release justification: low-risk updates to new functionality