Skip to content

sql: implemented placement restricted syntax for domiciling#68433

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
pawalt:domiciling_stiching
Aug 15, 2021
Merged

sql: implemented placement restricted syntax for domiciling#68433
craig[bot] merged 1 commit intocockroachdb:masterfrom
pawalt:domiciling_stiching

Conversation

@pawalt
Copy link
Copy Markdown
Contributor

@pawalt pawalt commented Aug 4, 2021

This PR combines the existing restricted placement zone config logic
with the stubbed syntax to create an end-to-end PLACEMENT RESTRICTED
implementation.

Release note: None

Note that the cluster setting for domiciling and telemetry will be added in a later PR.

@pawalt pawalt requested review from ajstorm, arulajmani and otan August 4, 2021 17:47
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@pawalt pawalt marked this pull request as ready for review August 4, 2021 17:48
@pawalt pawalt requested a review from a team as a code owner August 4, 2021 17:48
@pawalt pawalt force-pushed the domiciling_stiching branch 2 times, most recently from beae38e to 204929d Compare August 5, 2021 16:16
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.

Reviewed 2 of 16 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @otan, and @pawalt)


pkg/ccl/logictestccl/testdata/logic_test/domiciling, line 2 at r2 (raw file):

# LogicTest: multiregion-9node-3region-3azs multiregion-9node-3region-3azs-vec-off

nit: rename this file to placement


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_domiciling, line 1 at r2 (raw file):

# LogicTest: multiregion-9node-3region-3azs multiregion-9node-3region-3azs-vec-off

nit: rename this file regional_by_row_placement_restricted


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_domiciling, line 43 at r2 (raw file):

# Alter to RESTRICTED and see that we have no non-voter constraints.
statement ok
ALTER DATABASE testdb SET PLACEMENT RESTRICTED

Add tests to add/drop regions and change survival goal to ensure these operations work correctly with PLACEMENT RESTRICTED.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_domiciling, line 1 at r2 (raw file):

# LogicTest: multiregion-9node-3region-3azs multiregion-9node-3region-3azs-vec-off

Same as above, let's rename this file regional_by_table_placement_restricted

Separately, should we have some tests for global_tables with placement_restricted as well?


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_domiciling, line 45 at r2 (raw file):

# Change primary region to ensure zone config is rebuilt on table changes.
statement ok
ALTER DATABASE testdb SET PRIMARY REGION "ap-southeast-2"

Let's add tests that ensure ADD/DROP region continue to work correctly with PLACEMENT RESTRICTED as well?


pkg/sql/alter_database.go, line 1108 at r2 (raw file):

	}

	// TODO(pawalt): add a check for placement enabled cluster setting

Mind opening an issue for this to keep track?


pkg/sql/alter_database.go, line 1157 at r2 (raw file):

		return err
	}
	n.desc.RegionConfig.Placement = newPlacement

Instead of directly updating the proto like such, let's add a setter method on dbdesc.Mutable instead. In general, we try to avoid raw proto accesses/setters -- they should instead be mediated through the specific descriptor interface or Mutable type respectively.


pkg/sql/alter_database.go, line 1172 at r2 (raw file):

	}

	if err := multiregion.ValidateRegionConfig(regionConfig); err != nil {

SynthesizeRegionConfig gives you a validated RegionConfig, so I think you can get rid of this.


pkg/sql/alter_database.go, line 1194 at r2 (raw file):

	}

	// TODO(pawalt): add telemetry/logging for PLACEMENT events.

Can we open issues for both of these things?


pkg/sql/crdb_internal.go, line 253 at r2 (raw file):

	regions STRING[],
	survival_goal STRING,
	data_placement STRING,

nit: s/data_placement/placement_policy/?

Copy link
Copy Markdown
Collaborator

@ajstorm ajstorm left a comment

Choose a reason for hiding this comment

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

Nicely done!

Reviewed 10 of 16 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan and @pawalt)


-- commits, line 8 at r2 ([raw file](https://github.com/cockroachdb/cockroach/blob/204929de4c4b49a7057f7d9dcf87cb3f2beb74d9/-- commits#L8)):
I know that we don't want to make this public now, but in the case we need to expose this on short notice, does it make sense to write some basic documentation now? @rmloveland thoughts?


pkg/ccl/logictestccl/testdata/logic_test/domiciling, line 10 at r2 (raw file):


statement ok
CREATE DATABASE zone_survivable_strict PRIMARY REGION "ca-central-1" REGIONS "ap-southeast-2", "us-east-1" PLACEMENT RESTRICTED

Can we both show the zone configurations here, and validate them using the builtin? I want to ensure that validate holds up even with PLACEMENT RESTRICTED set.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_domiciling, line 43 at r2 (raw file):

# Alter to RESTRICTED and see that we have no non-voter constraints.
statement ok
ALTER DATABASE testdb SET PLACEMENT RESTRICTED

Can we validate with the builtin here too?


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_domiciling, line 27 at r2 (raw file):

# Alter to RESTRICTED and see that we have no non-voter constraints.
statement ok
ALTER DATABASE testdb SET PLACEMENT RESTRICTED

Validate here too?


pkg/sql/alter_database.go, line 755 at r2 (raw file):

	// must be explicitly rebuilt so as to move their primary region.
	if updatedRegionConfig.IsPlacementRestricted() {
		if err := params.p.updateZoneConfigsForAllTables(params.ctx, n.desc); err != nil {

Does it make sense to be more precise here? What I'm worried about is cases where we have 100s or 1000s of tables and only a handful of GLOBAL tables. This will end up rewriting all of their zone configs. Should we instead create a updateZoneConfigsForAllGlobalTables which filters out the other table types?


pkg/sql/alter_database.go, line 1128 at r2 (raw file):

		return errors.WithHintf(
			pgerror.New(pgcode.InvalidName,
				"database must have associated regions before a survival goal can be set",

Copy pasta? Shouldn't this read that the database must have associated regions before the placement goal can be set? Comment above too.

Also, can we test this case?


pkg/sql/crdb_internal.go, line 294 at r2 (raw file):

						// unless we know the user wants to use PLACEMENT. Therefore, we
						// only add a PLACEMENT clause if we're in restricted mode.
						createNode.Placement = tree.DataPlacementUnspecified

I'm probably missing something, but is there a reason why we want to differentiate between DEFAULT and UNSPECIFIED? Shouldn't they be the same in practice?

Copy link
Copy Markdown
Collaborator

@rmloveland rmloveland 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 @awoods187, @otan, and @pawalt)


-- commits, line 8 at r2 ([raw file](https://github.com/cockroachdb/cockroach/blob/204929de4c4b49a7057f7d9dcf87cb3f2beb74d9/-- commits#L8)):

we need to expose this on short notice

tl;dr: I'd rather just ignore this for now

long version:

if someone really really needs this info ASAP I bet someone could email them instructions how to use it while we get a docs PR ready (est. 1-2 days to write/review/merge)

meta: this convo is part of why I'm knee-jerk anti "put it in the product but don't document it", because then we have to spend time thinking about non-standard workflows like this and maybe end up doing rushed work anyway (cc @awoods187 with my sudden but inevitable complaint :-D )

@ajstorm ajstorm requested a review from awoods187 August 9, 2021 15:02
Copy link
Copy Markdown
Collaborator

@ajstorm ajstorm 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 @awoods187, @otan, and @pawalt)


-- commits, line 8 at r2 ([raw file](https://github.com/cockroachdb/cockroach/blob/204929de4c4b49a7057f7d9dcf87cb3f2beb74d9/-- commits#L8)):

Previously, rmloveland (Rich Loveland) wrote…

we need to expose this on short notice

tl;dr: I'd rather just ignore this for now

long version:

if someone really really needs this info ASAP I bet someone could email them instructions how to use it while we get a docs PR ready (est. 1-2 days to write/review/merge)

meta: this convo is part of why I'm knee-jerk anti "put it in the product but don't document it", because then we have to spend time thinking about non-standard workflows like this and maybe end up doing rushed work anyway (cc @awoods187 with my sudden but inevitable complaint :-D )

It's a fair (and somewhat expected) complaint. The reason we voted to have this go into 21.2 is because we're worried that the knee-jerk code-level backfit would be riskier than a knee-jerk doc change, but I'm open to have my mind changed on that. I confess that I don't have a good sense for the risk involved in these types of doc changes.

Copy link
Copy Markdown
Collaborator

@rmloveland rmloveland 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 @awoods187, @otan, and @pawalt)


-- commits, line 8 at r2 ([raw file](https://github.com/cockroachdb/cockroach/blob/204929de4c4b49a7057f7d9dcf87cb3f2beb74d9/-- commits#L8)):

the risk involved in these types of doc changes.

tbh almost no risk from a purely docs POV, it's easy to add when we need it. I agree with the assessment that changing the code is way riskier/harder

I'm just, like, duty bound to complain about it - because historically CRL doesn't do much of this. But I have worked at other places where this becomes "the norm", esp. when dealing with big customers. Work becomes a lot less fun (and harder to do at good quality levels) in those environments. So I'm worried about the slippery slope. Because from any customer's (or revenue team member's) POV it's always "Important (tm)"

Copy link
Copy Markdown
Collaborator

@ajstorm ajstorm 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 @awoods187, @otan, and @pawalt)


-- commits, line 8 at r2 ([raw file](https://github.com/cockroachdb/cockroach/blob/204929de4c4b49a7057f7d9dcf87cb3f2beb74d9/-- commits#L8)):

Previously, rmloveland (Rich Loveland) wrote…

the risk involved in these types of doc changes.

tbh almost no risk from a purely docs POV, it's easy to add when we need it. I agree with the assessment that changing the code is way riskier/harder

I'm just, like, duty bound to complain about it - because historically CRL doesn't do much of this. But I have worked at other places where this becomes "the norm", esp. when dealing with big customers. Work becomes a lot less fun (and harder to do at good quality levels) in those environments. So I'm worried about the slippery slope. Because from any customer's (or revenue team member's) POV it's always "Important (tm)"

I agree. This is one of the reasons I was wondering if we wanted a draft PR (or Google Doc) at the ready should such a need arise? I was thinking that this could make the fire drill less hot if/when it eventually arrives.

Copy link
Copy Markdown
Contributor Author

@pawalt pawalt 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 @ajstorm, @arulajmani, @awoods187, and @otan)


pkg/ccl/logictestccl/testdata/logic_test/domiciling, line 10 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Can we both show the zone configurations here, and validate them using the builtin? I want to ensure that validate holds up even with PLACEMENT RESTRICTED set.

Yup I'll do it at the database level here and at the table level in each table test.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_domiciling, line 43 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Add tests to add/drop regions and change survival goal to ensure these operations work correctly with PLACEMENT RESTRICTED.

Done.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_domiciling, line 43 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Can we validate with the builtin here too?

Done.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_domiciling, line 1 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Same as above, let's rename this file regional_by_table_placement_restricted

Separately, should we have some tests for global_tables with placement_restricted as well?

Yep I'll add tests that ensure global tables get the new non-inherited zone config.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_domiciling, line 27 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Validate here too?

Done.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_domiciling, line 45 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Let's add tests that ensure ADD/DROP region continue to work correctly with PLACEMENT RESTRICTED as well?

Done.


pkg/sql/alter_database.go, line 755 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Does it make sense to be more precise here? What I'm worried about is cases where we have 100s or 1000s of tables and only a handful of GLOBAL tables. This will end up rewriting all of their zone configs. Should we instead create a updateZoneConfigsForAllGlobalTables which filters out the other table types?

I think that makes sense. I figure we'll want to do this with RBR/RBT tables as well, so I've added a method that allows you to pass in a filter to only apply changes to table descriptors that match the filter.


pkg/sql/alter_database.go, line 1108 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Mind opening an issue for this to keep track?

Done.


pkg/sql/alter_database.go, line 1128 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

Copy pasta? Shouldn't this read that the database must have associated regions before the placement goal can be set? Comment above too.

Also, can we test this case?

Added testing for creating without a primary region and altering without a primary region.


pkg/sql/alter_database.go, line 1157 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Instead of directly updating the proto like such, let's add a setter method on dbdesc.Mutable instead. In general, we try to avoid raw proto accesses/setters -- they should instead be mediated through the specific descriptor interface or Mutable type respectively.

Done.


pkg/sql/alter_database.go, line 1172 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

SynthesizeRegionConfig gives you a validated RegionConfig, so I think you can get rid of this.

Done.


pkg/sql/alter_database.go, line 1194 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Can we open issues for both of these things?

#68597
#68598


pkg/sql/crdb_internal.go, line 294 at r2 (raw file):

Previously, ajstorm (Adam Storm) wrote…

I'm probably missing something, but is there a reason why we want to differentiate between DEFAULT and UNSPECIFIED? Shouldn't they be the same in practice?

They are the same in practice, but the formatter doesn't print for UNSPECIFIED but it does for DEFAULT. In this case, we want to always format as UNSPECIFIED so that a user on the DEFAULT behavior doesn't get PLACEMENT leaked to them.

@pawalt pawalt force-pushed the domiciling_stiching branch from d5aecb7 to 83ef652 Compare August 9, 2021 22:23
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.

Reviewed 3 of 10 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @arulajmani, @awoods187, @otan, and @pawalt)


pkg/ccl/logictestccl/testdata/logic_test/global_placement_restricted, line 100 at r3 (raw file):

            lease_preferences = '[[+region=ap-southeast-2]]'

# Alter to DEFAULT and see that our voter constraints are back.

Were they gone before?


pkg/sql/alter_database.go, line 265 at r3 (raw file):

	// RESTRICTED mode, GLOBAL tables will not inherit the database zone config
	// and will have to be explicitly rebuilt.
	if n.desc.RegionConfig.Placement == descpb.DataPlacement_RESTRICTED {

Same comment as below.


pkg/sql/alter_database.go, line 652 at r3 (raw file):

	// Update all GLOBAL tables' zone configurations. This is required as in
	// RESTRICTED mode, GLOBAL tables will not inherit the database zone config
	// and will have to be explicitly rebuilt.

I see you're doing something similar in the DatabaseRegionChangeFinalizer. I may be missing something, but do you need both?


pkg/sql/alter_database.go, line 1220 at r3 (raw file):

	}

	// Update all GLOBAL tables' zone configurations. This is required as in

I think there's more to this. I'd reword this as:

Update all GLOBAL tables' zone configurations. This is required because GLOBAL table's can inherit the database's zone configuration under the DEFAULT placement policy. However, under the RESTRICTED placement policy, non-voters are removed from the database. But global tables need non-voters to behave properly, and as such, need a bespoke zone configuration. Regardless of the transition direction (DEFAULT -> RESTRICTED, RESTRICTED -> DEFAULT), we need to refresh the zone configuration of all GLOBAL table's inside the database to either carry a bespoke configuration or go back to inheriting it from the database.

pkg/sql/crdb_internal.go, line 294 at r2 (raw file):

Previously, pawalt (Peyton Walters) wrote…

They are the same in practice, but the formatter doesn't print for UNSPECIFIED but it does for DEFAULT. In this case, we want to always format as UNSPECIFIED so that a user on the DEFAULT behavior doesn't get PLACEMENT leaked to them.

nit: s/if we're in restricted mode/if the database was configured with restricted placement/g


pkg/sql/create_database.go, line 98 at r3 (raw file):

	if n.Placement != tree.DataPlacementUnspecified {
		// TODO(pawalt): add cluster setting checking for placement

nit: full stop
nit: link the issue here (and above) as well maybe?


pkg/sql/database_region_change_finalizer.go, line 39 at r3 (raw file):

	cleanupFunc         func()
	regionalByRowTables []*tabledesc.Mutable
	globalTables        []*tabledesc.Mutable

Does this need to be a field on this struct? Put another way, is there a reason to pre-fetch all global tables?


pkg/sql/database_region_change_finalizer.go, line 173 at r3 (raw file):

	if err != nil {
		return err
	}

Should we add a check to only do this if the database is configured in PLACEMENT RESTRICTED?


pkg/sql/database_region_change_finalizer.go, line 175 at r3 (raw file):

	}

	for _, tableDesc := range r.globalTables {

Do you need to save all global tables on this struct or can you just fetch them here?


pkg/sql/descriptor.go, line 250 at r3 (raw file):

		return descpb.DataPlacement_RESTRICTED, nil
	default:
		return 0, errors.Newf("unknown data placement: %d", g)

Should this be an assertion failed error?


pkg/sql/region_util.go, line 150 at r3 (raw file):

		// placement. Voter placement will be set at the table/partition level to
		// the table/partition region.
		constraints = nil

Why did this change?


pkg/sql/region_util.go, line 816 at r3 (raw file):

}

func filterIsLocalityGlobal(t *tabledesc.Mutable) bool {

Consider making this an option. Have updateZoneConfigsForTables take in an optional list of options. By default, the filter function will be a passthrough. Then, you can make a WithOnlyGlobalTables option that applies this filter.

Here's a link in the style guide which talks a bit more about this pattern (if you're unfamiliar): https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/181371303/Go+Golang+coding+guidelines#Functional-Options


pkg/sql/catalog/dbdesc/database_desc.go, line 408 at r3 (raw file):

}

// SetPlacement sets the placement of the region config for a database

s/of the region config/on the region config/g


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_placement_restricted, line 134 at r3 (raw file):

lease_preferences = '[[+region=us-east-1]]'

# Alter to DEFAULT and see that our voter constraints are back.

Do you mean constraints?


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_placement_restricted, line 10 at r3 (raw file):


statement ok
CREATE TABLE test () LOCALITY REGIONAL BY TABLE IN PRIMARY REGION

Let's add the same set of tests for a REGIONAL BY TABLE in an explicit region as well? Say ap-southeast-2, as it isn't the primary region and you're not dropping it anywhere?


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_placement_restricted, line 97 at r3 (raw file):

                 lease_preferences = '[[+region=ap-southeast-2]]'

# Alter to DEFAULT and see that our voter constraints are back.

Do you mean constraints?

@awoods187
Copy link
Copy Markdown

I'm supportive of documenting this in a Google doc that we can publish in the future. We have plenty of historical evidence of not documenting changes, particularly ones gated behind feature flags.

@ajstorm ajstorm requested review from ajstorm and arulajmani August 10, 2021 21:14
Copy link
Copy Markdown
Collaborator

@ajstorm ajstorm 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 @ajstorm, @arulajmani, @awoods187, @otan, and @pawalt)


pkg/sql/alter_database.go, line 755 at r2 (raw file):

Previously, pawalt (Peyton Walters) wrote…

I think that makes sense. I figure we'll want to do this with RBR/RBT tables as well, so I've added a method that allows you to pass in a filter to only apply changes to table descriptors that match the filter.

Cool!


pkg/sql/crdb_internal.go, line 294 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: s/if we're in restricted mode/if the database was configured with restricted placement/g

Gotcha. I think I saw this in your Gru presentation.

@pawalt pawalt force-pushed the domiciling_stiching branch from 83ef652 to c82d343 Compare August 11, 2021 04:00
Copy link
Copy Markdown
Contributor Author

@pawalt pawalt 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 @ajstorm, @arulajmani, @awoods187, and @otan)


pkg/ccl/logictestccl/testdata/logic_test/global_placement_restricted, line 100 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Were they gone before?

Nope ... not sure what I was trying to say here. Fixed.


pkg/sql/alter_database.go, line 265 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Same comment as below.

Done.


pkg/sql/alter_database.go, line 652 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I see you're doing something similar in the DatabaseRegionChangeFinalizer. I may be missing something, but do you need both?

Ah I didn't think of that. Removed.


pkg/sql/alter_database.go, line 1220 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I think there's more to this. I'd reword this as:

Update all GLOBAL tables' zone configurations. This is required because GLOBAL table's can inherit the database's zone configuration under the DEFAULT placement policy. However, under the RESTRICTED placement policy, non-voters are removed from the database. But global tables need non-voters to behave properly, and as such, need a bespoke zone configuration. Regardless of the transition direction (DEFAULT -> RESTRICTED, RESTRICTED -> DEFAULT), we need to refresh the zone configuration of all GLOBAL table's inside the database to either carry a bespoke configuration or go back to inheriting it from the database.

Done.


pkg/sql/database_region_change_finalizer.go, line 39 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Does this need to be a field on this struct? Put another way, is there a reason to pre-fetch all global tables?

Nope I think fetching them later is fine. Changed.


pkg/sql/database_region_change_finalizer.go, line 173 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Should we add a check to only do this if the database is configured in PLACEMENT RESTRICTED?

Done.


pkg/sql/database_region_change_finalizer.go, line 175 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Do you need to save all global tables on this struct or can you just fetch them here?

Done.


pkg/sql/descriptor.go, line 250 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Should this be an assertion failed error?

Yep


pkg/sql/region_util.go, line 150 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Why did this change?

I found out that empty constraints get deserialized as nil even if they're created with [], so I changed this so that the generated zone config is the same as the one stored in the database. You get errors otherwise since the multi-region checks think the zone config has been modified by the user.


pkg/sql/region_util.go, line 816 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Consider making this an option. Have updateZoneConfigsForTables take in an optional list of options. By default, the filter function will be a passthrough. Then, you can make a WithOnlyGlobalTables option that applies this filter.

Here's a link in the style guide which talks a bit more about this pattern (if you're unfamiliar): https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/181371303/Go+Golang+coding+guidelines#Functional-Options

Gave this a shot. Let me know if it looks ok


pkg/sql/catalog/dbdesc/database_desc.go, line 408 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

s/of the region config/on the region config/g

Done.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_placement_restricted, line 134 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Do you mean constraints?

Yep


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_placement_restricted, line 10 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Let's add the same set of tests for a REGIONAL BY TABLE in an explicit region as well? Say ap-southeast-2, as it isn't the primary region and you're not dropping it anywhere?

Done.


pkg/ccl/logictestccl/testdata/logic_test/regional_by_table_placement_restricted, line 97 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Do you mean constraints?

Yep thanks

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 making the changes! This is quite close, mostly minor comments left.

Let's open an issue for the ADD/DROP REGION failure case that we talked about offline as well?

Reviewed 1 of 10 files at r3, 1 of 10 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @arulajmani, @awoods187, @otan, and @pawalt)


pkg/sql/database_region_change_finalizer.go, line 81 at r4 (raw file):

			dbDesc,
			func(ctx context.Context, scName string, tableDesc *tabledesc.Mutable) error {
				if tableDesc.Dropped() {

Revert this change?


pkg/sql/database_region_change_finalizer.go, line 160 at r4 (raw file):

// updateGlobalTablesZoneConfig recalculates all global tables' zone configs so
// that their zone configs are recalculated after a newly-added region goes
// out of being a transitioning region.

Could you add a nod here that this is only required when the database has the PLACEMENT RESTRICTED policy and why?

Also can we s/recalculate/refresh/g in the comment for consistency, as that's the word we use in other places?


pkg/sql/database_region_change_finalizer.go, line 181 at r4 (raw file):

		return err
	}
	mutableDesc := dbDesc.(*dbdesc.Mutable)

I don't think this is safe -- you shouldn't be getting an immutable database descriptor and then casting it to mutable descriptor. You should instead ask the descsCol for a mutable database descriptor.


pkg/sql/region_util.go, line 150 at r3 (raw file):

Previously, pawalt (Peyton Walters) wrote…

I found out that empty constraints get deserialized as nil even if they're created with [], so I changed this so that the generated zone config is the same as the one stored in the database. You get errors otherwise since the multi-region checks think the zone config has been modified by the user.

I see, thanks for the explanation. Let's put this in a // NB: here as well for posterity?


pkg/sql/region_util.go, line 816 at r3 (raw file):

Previously, pawalt (Peyton Walters) wrote…

Gave this a shot. Let me know if it looks ok

Looks great, thanks for making the change! Is this filter function unused now? Should we get rid of it?


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_placement_restricted, line 134 at r4 (raw file):

lease_preferences = '[[+region=us-east-1]]'

# Alter to DEFAULT and see that our non-voter constraints are back.

Let's just drop non-voter altogether? It's slightly confusing, the way this looks, but the constraints field actually applies to both voters and non-voters.

@pawalt pawalt requested a review from arulajmani August 12, 2021 16:42
Copy link
Copy Markdown
Contributor Author

@pawalt pawalt 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 @ajstorm, @arulajmani, @awoods187, and @otan)


pkg/sql/database_region_change_finalizer.go, line 81 at r4 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Revert this change?

Done.


pkg/sql/database_region_change_finalizer.go, line 160 at r4 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Could you add a nod here that this is only required when the database has the PLACEMENT RESTRICTED policy and why?

Also can we s/recalculate/refresh/g in the comment for consistency, as that's the word we use in other places?

Done.


pkg/sql/database_region_change_finalizer.go, line 181 at r4 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I don't think this is safe -- you shouldn't be getting an immutable database descriptor and then casting it to mutable descriptor. You should instead ask the descsCol for a mutable database descriptor.

I did this initially because I didn't want to have to get the database name and then the mutable descriptor (since we only have a GetMutableDatabaseByName function). I've added a GetMutableDatabaseByID function; let me know if the approach is safe. I think it is because I'm requiring the descriptor to be mutable, but not 100%.


pkg/sql/region_util.go, line 150 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I see, thanks for the explanation. Let's put this in a // NB: here as well for posterity?

Done.


pkg/sql/region_util.go, line 816 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Looks great, thanks for making the change! Is this filter function unused now? Should we get rid of it?

Yep removed


pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_placement_restricted, line 134 at r4 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Let's just drop non-voter altogether? It's slightly confusing, the way this looks, but the constraints field actually applies to both voters and non-voters.

Done.

@pawalt pawalt force-pushed the domiciling_stiching branch from 2c130cb to 7d009fb Compare August 12, 2021 18:24
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.

One last thing before this is good to go! My bad on not realizing about updateZoneConfigsForAllTables earlier.

Reviewed 1 of 10 files at r4, 1 of 4 files at r5.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @arulajmani, @awoods187, @otan, and @pawalt)


pkg/sql/database_region_change_finalizer.go, line 181 at r4 (raw file):

Previously, pawalt (Peyton Walters) wrote…

I did this initially because I didn't want to have to get the database name and then the mutable descriptor (since we only have a GetMutableDatabaseByName function). I've added a GetMutableDatabaseByID function; let me know if the approach is safe. I think it is because I'm requiring the descriptor to be mutable, but not 100%.

I think what you have makes sense, but I'm not sure we need to/should expose this API considering:

  1. this is the only usage
  2. The reason you need it here is slightly dubious (not because of something you did)

Let me say a bit more about what I mean by point 2 here -- I'm looking at this udpateZoneConfigsForTables method again and looks like it only needs the database descriptor to synthesize the region config. I don't think it needs a mutable descriptor to begin with considering all its using it for is to synthesize the region config. SynthesizeRegionConfig only takes an ID and does so because it wants to read the descriptor from the store so that it gets an up-to-date view of things (as opposed to the leased version). This is all to say that maybe the right thing to do here is to change updateZoneConfigsForTables to take in a catalog.DatabaseDescriptor instead of a mutable database descriptor.


pkg/sql/region_util.go, line 155 at r5 (raw file):

		// always deserialized as nil. Therefore, if constraints are set as [] here,
		// the database will have a difference in its expected constraints vs the
		// actual constraints.

nit: vs the actual constraints when comparing using multi-region validation builitins?

@pawalt pawalt force-pushed the domiciling_stiching branch from 7d009fb to 1149b4e Compare August 12, 2021 19:12
@pawalt pawalt requested a review from arulajmani August 12, 2021 19:13
Copy link
Copy Markdown
Contributor Author

@pawalt pawalt 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 @ajstorm, @arulajmani, @awoods187, and @otan)


pkg/sql/database_region_change_finalizer.go, line 181 at r4 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I think what you have makes sense, but I'm not sure we need to/should expose this API considering:

  1. this is the only usage
  2. The reason you need it here is slightly dubious (not because of something you did)

Let me say a bit more about what I mean by point 2 here -- I'm looking at this udpateZoneConfigsForTables method again and looks like it only needs the database descriptor to synthesize the region config. I don't think it needs a mutable descriptor to begin with considering all its using it for is to synthesize the region config. SynthesizeRegionConfig only takes an ID and does so because it wants to read the descriptor from the store so that it gets an up-to-date view of things (as opposed to the leased version). This is all to say that maybe the right thing to do here is to change updateZoneConfigsForTables to take in a catalog.DatabaseDescriptor instead of a mutable database descriptor.

Agreed. Changed to catalog.DatabaseDescriptor and removed GetMutableDatabaseByID

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_strong:

Reviewed 3 of 3 files at r7.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajstorm, @arulajmani, @awoods187, and @otan)

@pawalt pawalt force-pushed the domiciling_stiching branch from 1149b4e to 0c5a5dc Compare August 13, 2021 15:08
@pawalt
Copy link
Copy Markdown
Contributor Author

pawalt commented Aug 13, 2021

bros r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 13, 2021

👊

@pawalt
Copy link
Copy Markdown
Contributor Author

pawalt commented Aug 13, 2021

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 13, 2021

This PR was included in a batch that was canceled, it will be automatically retried

craig bot pushed a commit that referenced this pull request Aug 14, 2021
66889: jobs: retry jobs with exponential backoff r=ajwerner a=sajjadrizvi

This commit adds a mechanism to retry jobs with exponentially increasing
delays. This is achieved through two new columns in system.jobs table,
last_run and num_runs. In addition, this commit adds cluster settings
to control exponential-backoff parameters, initial delay and max delay,
with corresponding settings `jobs.registry.retry.initial_delay` and
`jobs.registry.retry.max_delay`. Finally, this commit adds a new
partial-index in the jobs table that improves the performance of periodic 
queries run by registry in each node.

Release note (general change): The behavior for retrying jobs, which fail
due to a retriable error or due to job coordinator failure, is now delayed
using exponential backoff. Before this change, jobs which failed in a
retryable manner, would be resumed immediately on a different coordinator.
This change reduces the impact of recurrently failing jobs on the cluster.
This change adds two new cluster settings that control this behavior:
"jobs.registry.retry.initial_delay" and "jobs.registry.retry.max_delay",
which respectively control initial delay and maximum delay between 
resumptions.

Fixes #44594
Fixes #65080

68212: colexec: add optimized versions of aggregate window functions r=DrewKimball a=DrewKimball

**colexecwindow: add sliding window functionality to window framer**

This commit adds a method `slidingWindowIntervals` to `windowFramer`
operators that returns a set of `toAdd` intervals and a set of
`toRemove` intervals, which indicate the rows that should be added
to the current aggregation and those that should be removed, respectively.
This will be used to implement the sliding window optimization for
aggregate window functions such as `sum`.

**colexecwindow: implement sliding window aggregator**

This commit supplies a new operator, `slidingWindowAggregator`, which
is used for any window aggregate functions that implement the
`slidingWindowAggregateFunc` interface. Rather than aggregating over
the entire window frame for each row, the `slidingWindowAggregator`
operator aggregates over the rows that are in the current window
frame but were not in the previous, and removes from the aggregation
the rows that were in the previous window frame but not the current.
This allows window aggregate functions to be evaluated in linear rather
than quadratic time.

**colexec: implement sliding window optimization for sum window function**

This commit modifies the `sum` aggregate window function to implement
the `slidingWindowAggregateFunc`, which allows it to be used in a
sliding window context. This yields linear rather than quadratic scaling
in the worst case, and allows the vectorized engine to meet or exceed
parity with the row engine for `sum` window functions.

**colexec: implement sliding window optimization for count window function**

This commit modifies the count aggregate operator to implement the
`slidingWindowAggregateFunc` interface so that it can be used with
the sliding window optimization.

**colexec: implement sliding window optimization for average window function**

This commit modifies the `average` aggregate operator to implement the
`slidingWindowAggregateFunc` interface so that it can be used with the
sliding window optimization.

**colexec: optimize count_rows window function**

This commit implements an optimized version of `count_rows` that
calculates the size of the window frame as soon as the window frame
is calculated. This means that most of the overhead for `count_rows`
now comes from calculating the window frame, which is worst-case
linear time (previously, the step to retrieve the size of the frame
was quadratic, though with a small constant).

**colexec: optimize min and max window functions with default exclusion**

This commit modifies the 'min' and 'max' aggregate window functions
to implement the `slidingWindowAggregateFunc` interface, which allows
them to be used in a sliding window context. However, this is only
usable when the window frame never shrinks - e.g. it always contains
all rows from the previous frame.

This commit also provides implementations of `min` and `max` for use
when the window frame can shrink. The indices of the 'next best'
minimum or maximum values are stored in a priority queue that is
updated for each row. Using the priority queue allows the `min` and
`max` operators to avoid fully aggregating over the window frame
even when the previous best value goes out of scope. Note that this
implementation currently does not handle the case of non-default
exclusion clause, in which case we must fall back to the quadratic
approach.

Fixes: #37039

Release note (performance improvement): The vectorized engine can now
use the sliding-window approach to execute common aggregate functions 
as window functions. This allows aggregate window functions to be evaluated
in linear rather than quadratic time. Currently, sum, count, average, min, and 
max are executed using this approach.

68433: sql: implemented placement restricted syntax for domiciling r=pawalt a=pawalt

This PR combines the existing restricted placement zone config logic
with the stubbed syntax to create an end-to-end PLACEMENT RESTRICTED
implementation.

Release note: None

Note that the cluster setting for domiciling and telemetry will be added in a later PR.

68818: changefeedccl: mark avro format as no longer experimental r=[miretskiy,spiffyeng] a=HonoreDB

The avro format for changefeeds now supports all column types
and has been in production use for several releases.
We'll now allow format=avro rather than format=experimental_avro
The old string will remain supported because job payloads can
persist across upgrades and downgrades.

Release note (enterprise change): changefeed avro format no longer marked experimental

Co-authored-by: Sajjad Rizvi <sajjad@cockroachlabs.com>
Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
Co-authored-by: Peyton Walters <peyton.walters@cockroachlabs.com>
Co-authored-by: Aaron Zinger <zinger@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 14, 2021

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 14, 2021

Build failed (retrying...):

craig bot pushed a commit that referenced this pull request Aug 14, 2021
68433: sql: implemented placement restricted syntax for domiciling r=pawalt a=pawalt

This PR combines the existing restricted placement zone config logic
with the stubbed syntax to create an end-to-end PLACEMENT RESTRICTED
implementation.

Release note: None

Note that the cluster setting for domiciling and telemetry will be added in a later PR.

Co-authored-by: Peyton Walters <peyton.walters@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 14, 2021

Build failed:

@pawalt pawalt force-pushed the domiciling_stiching branch from 0c5a5dc to f1a1c6e Compare August 15, 2021 12:13
@pawalt pawalt requested a review from a team August 15, 2021 12:13
@pawalt pawalt requested a review from a team as a code owner August 15, 2021 12:13
This PR combines the existing restricted placement zone config logic
with the stubbed syntax to create an end-to-end PLACEMENT RESTRICTED
implementation.

Release note: None
@pawalt pawalt force-pushed the domiciling_stiching branch from f1a1c6e to 9849400 Compare August 15, 2021 20:55
@pawalt
Copy link
Copy Markdown
Contributor Author

pawalt commented Aug 15, 2021

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 15, 2021

Build succeeded:

@craig craig bot merged commit 04a41e7 into cockroachdb:master Aug 15, 2021
@pawalt pawalt deleted the domiciling_stiching branch August 16, 2021 13:50
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.

6 participants