Skip to content

spanconfig: add Record constructor and validation#77349

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
adityamaru:add-record-validation
Mar 12, 2022
Merged

spanconfig: add Record constructor and validation#77349
craig[bot] merged 1 commit intocockroachdb:masterfrom
adityamaru:add-record-validation

Conversation

@adityamaru
Copy link
Copy Markdown
Contributor

@adityamaru adityamaru commented Mar 3, 2022

This change adds a constructor method that returns
a new spanconfig.Record and conditionally performs
some validation if the target is a SystemTarget.

Informs: #73727

Release note: None

Release justification: low-risk updates to new functionality

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@adityamaru adityamaru force-pushed the add-record-validation branch from ecdfbea to f5177fa Compare March 3, 2022 22:30
@adityamaru adityamaru changed the title [WIP,DNM] spanconfig: add Record constructor and validation spanconfig: add Record constructor and validation Mar 3, 2022
@adityamaru adityamaru force-pushed the add-record-validation branch from f5177fa to e182666 Compare March 3, 2022 22:37
@adityamaru adityamaru marked this pull request as ready for review March 3, 2022 22:38
@adityamaru adityamaru requested a review from a team as a code owner March 3, 2022 22:38
@adityamaru adityamaru requested review from a team and arulajmani and removed request for a team March 3, 2022 22:38
@adityamaru
Copy link
Copy Markdown
Contributor Author

Will rebase once #77338 is in.

@adityamaru adityamaru force-pushed the add-record-validation branch from e182666 to adbe7ba Compare March 5, 2022 02:17
Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! Looks good modulo couple minor comments/suggestions.

Reviewed 14 of 14 files at r1, all commit messages.
Reviewable status: :shipit: 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

@adityamaru adityamaru force-pushed the add-record-validation branch from adbe7ba to 99c7feb Compare March 6, 2022 21:35
Copy link
Copy Markdown
Contributor Author

@adityamaru adityamaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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 ExcludeFromBackup here 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 Target and Config private 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 MakeTargetFromSpan and a few other places in target.go where 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.

@adityamaru adityamaru force-pushed the add-record-validation branch from 99c7feb to e54bfd2 Compare March 6, 2022 21:39
@adityamaru
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: 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: :shipit: 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.

@adityamaru adityamaru force-pushed the add-record-validation branch from 5d6c270 to 4077ffc Compare March 10, 2022 16:46
Copy link
Copy Markdown
Contributor Author

@adityamaru adityamaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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 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.

agreed, switched to bubble up the error.

@adityamaru adityamaru force-pushed the add-record-validation branch from 4077ffc to 63bcc8d Compare March 10, 2022 17:29
Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Reviewed 9 of 10 files at r5, 2 of 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru)

@adityamaru
Copy link
Copy Markdown
Contributor Author

Looks like a bazel flake.

TFTR!

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 10, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 10, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 10, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

Build failed:

@adityamaru adityamaru force-pushed the add-record-validation branch from 63bcc8d to ae7c2d3 Compare March 11, 2022 05:45
@adityamaru adityamaru requested a review from a team as a code owner March 11, 2022 05:45
@adityamaru adityamaru removed the request for review from a team March 11, 2022 05:45
@adityamaru
Copy link
Copy Markdown
Contributor Author

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

🕐 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.

@adityamaru
Copy link
Copy Markdown
Contributor Author

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

🕐 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.

@adityamaru
Copy link
Copy Markdown
Contributor Author

🤷 unsure whatsup, will try to bors in a bit.

@adityamaru
Copy link
Copy Markdown
Contributor Author

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

🕐 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.

@adityamaru
Copy link
Copy Markdown
Contributor Author

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

🕐 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.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

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.

@adityamaru
Copy link
Copy Markdown
Contributor Author

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

🕐 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.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 11, 2022

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
@adityamaru adityamaru force-pushed the add-record-validation branch from ae7c2d3 to 99c9691 Compare March 11, 2022 17:47
@adityamaru
Copy link
Copy Markdown
Contributor Author

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 12, 2022

Build succeeded:

@craig craig bot merged commit af747e7 into cockroachdb:master Mar 12, 2022
@adityamaru adityamaru deleted the add-record-validation branch March 12, 2022 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants