Skip to content
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

spanconfigsqltranslator: emit all SystemTarget span configs when required #76606

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

adityamaru
Copy link
Contributor

This change teaches the SQLTranslator to emit SpanConfigurations
corresponding to spanconfig.SystemTargets. Today, these SpanConfigurations
only contain ProtectionPolicies, corresponding to protected timestamp
records that may be written by the host tenant to protect its cluster,
a secondary tenant to protect its cluster, or the host tenant to protect
a secondary tenant.

The SystemTarget span configurations will be applied to a SystemSpanConfig
store that will be introduced in a follow up PR.

Informs: #73727

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@adityamaru
Copy link
Contributor Author

First two commits from #76414, will rebase once it merges.

Copy link
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.

I mostly have nitty comments! Good stuff 💯

Reviewed 8 of 9 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru and @irfansharif)


pkg/roachpb/span_config.go, line 113 at r1 (raw file):

// TestingSystemTargetDefaultSpanConfig exports the default span config that
// applies to spanconfig.SystemTargets for testing purposes.
func TestingSystemTargetDefaultSpanConfig() SpanConfig {

Should we call this TestingDefaultSystemSpanConfiguration?


pkg/spanconfig/spanconfig.go, line 116 at r1 (raw file):

	// configuration. Translate also accounts for and negotiates subzone spans.
	Translate(ctx context.Context, ids descpb.IDs,
		shouldGenerateSystemTargetRecords bool) ([]Record, hlc.Timestamp, error)

Similar to my comment above, should we call this generateSystemSpanConfigurations?


pkg/spanconfig/spanconfigreconciler/reconciler.go, line 382 at r1 (raw file):

					allIDs = append(allIDs, update.GetDescriptorUpdate().ID)
				} else if update.IsProtectedTimestampUpdate() {
					shouldGenerateSystemTargetRecords = true

Should we revert this until we teach + test system span configurations to the reconciler? Wiring this up right now, without the KV changes, might cause issues.


pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 157 at r1 (raw file):

// generateSystemTargetRecords is responsible for generating all the SpanConfigs
// that apply to spanconfig.SystemTargets.
func (s *SQLTranslator) generateSystemTargetRecords(

s/generateSystemTargetRecords/generateSystemSpanConfigRecords/?


pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 187 at r1 (raw file):

	// Aggregate tenant target protections.
	tenantProtections := ptsStateReader.getProtectionPoliciesForTenants()

Centralizing the discussion we've had in a couple of places, do you prefer this approach over returning ptpb.Target's from the ptsStateReader and writing conversions from a ptpb.Target to a spanconfig.Target (and vice versa)?


pkg/spanconfig/spanconfigtestutils/utils.go, line 277 at r1 (raw file):

// diffs the given config against the default config that applies to
// spanconfig.SystemTargets, and returns a string for the mismatched fields.
func PrintSystemTargetSpanConfigDiffedAgainstDefault(conf roachpb.SpanConfig) string {

s/PrintSystemTargetSpanConfigDiffedAgainstDefault/PrintSystemSpanConfigDiffedAgainstDefault/g


pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/datadriven_test.go, line 174 at r1 (raw file):

						output.WriteString(fmt.Sprintf("%-42s %s\n", record.Target.GetSpan(),
							spanconfigtestutils.PrintSpanConfigDiffedAgainstDefaults(record.Config)))
					} else {

nit: might be worth using a switch statement which explicitly checks for IsSpanTarget and IsSystemTarget and panics in the default case.

@adityamaru
Copy link
Contributor Author

Going to wait for #76721 before I rebase this PR.

Copy link
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 @arulajmani and @irfansharif)


pkg/roachpb/span_config.go, line 113 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Should we call this TestingDefaultSystemSpanConfiguration?

Done.


pkg/spanconfig/spanconfig.go, line 116 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Similar to my comment above, should we call this generateSystemSpanConfigurations?

Done.


pkg/spanconfig/spanconfigreconciler/reconciler.go, line 382 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Should we revert this until we teach + test system span configurations to the reconciler? Wiring this up right now, without the KV changes, might cause issues.

Sounds good, added a todo.


pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 157 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

s/generateSystemTargetRecords/generateSystemSpanConfigRecords/?

Done.


pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 187 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Centralizing the discussion we've had in a couple of places, do you prefer this approach over returning ptpb.Target's from the ptsStateReader and writing conversions from a ptpb.Target to a spanconfig.Target (and vice versa)?

After the discussions/refactor of the methods in your other PRs, I'm happy with where this is right now. If we think there's some cleanup to be done in the future we can revisit.


pkg/spanconfig/spanconfigtestutils/utils.go, line 277 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

s/PrintSystemTargetSpanConfigDiffedAgainstDefault/PrintSystemSpanConfigDiffedAgainstDefault/g

Done.


pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/datadriven_test.go, line 174 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: might be worth using a switch statement which explicitly checks for IsSpanTarget and IsSystemTarget and panics in the default case.

Done.

@adityamaru
Copy link
Contributor Author

@arulajmani rebased, and addressed all your comments. Should be RFAL

Copy link
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: once we introduce a new directive to translate system span configurations

Reviewed 9 of 9 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @adityamaru, @arulajmani, and @irfansharif)


pkg/spanconfig/spanconfigtestutils/utils.go, line 280 at r2 (raw file):

// PrintSystemSpanConfigDiffedAgainstDefault is a helper function that
// diffs the given config against the default config that applies to

nit: "the default system span config"


pkg/spanconfig/spanconfigtestutils/utils.go, line 284 at r2 (raw file):

func PrintSystemSpanConfigDiffedAgainstDefault(conf roachpb.SpanConfig) string {
	if conf.Equal(roachpb.TestingDefaultSystemSpanConfiguration()) {
		return "system target default"

nit: "default system span config"


pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/datadriven_test.go, line 163 at r2 (raw file):

				sqlTranslator := tenant.SpanConfigSQLTranslator().(spanconfig.SQLTranslator)
				records, _, err := sqlTranslator.Translate(ctx, descpb.IDs{objID},
					true /* generateSystemSpanConfigurations */)

Should we create a new directive to just generate system span configurations? As is, it's slightly confusing that these things are getting generated when translating a table or a database.

@adityamaru adityamaru force-pushed the teach-translator branch 2 times, most recently from 258861b to da743ee Compare February 22, 2022 16:45
@adityamaru
Copy link
Contributor Author

Addressed all your comments, TFTR!

@adityamaru
Copy link
Contributor Author

bors r=arulajmani

…ired

This change teaches the SQLTranslator to emit SpanConfigurations
corresponding to `spanconfig.SystemTargets`. Today, these SpanConfigurations
only contain ProtectionPolicies, corresponding to protected timestamp
records that may be written by the host tenant to protect its cluster,
a secondary tenant to protect its cluster, or the host tenant to protect
a secondary tenant.

The SystemTarget span configurations will be applied to a SystemSpanConfig
store that will be introduced in a follow up PR.

Informs: cockroachdb#73727

Release note: None
@adityamaru
Copy link
Contributor Author

Merge conflict, rebasing and trying again.

@adityamaru
Copy link
Contributor Author

bors r=arulajmani

@craig
Copy link
Contributor

craig bot commented Feb 22, 2022

Build failed (retrying...):

@adityamaru
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 22, 2022

Already running a review

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build failed:

@adityamaru
Copy link
Contributor Author

Unrelated flake, lets try this again.

bors r=arulajmani

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build succeeded:

@craig craig bot merged commit 715520b into cockroachdb:master Feb 23, 2022
@adityamaru adityamaru deleted the teach-translator branch February 23, 2022 23:37
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.

None yet

3 participants