Skip to content

lease,systemschema: hook up the lease table to regional-by-row partitioning#92588

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/lease-partitioning
Dec 9, 2022
Merged

lease,systemschema: hook up the lease table to regional-by-row partitioning#92588
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/lease-partitioning

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner commented Nov 28, 2022

This PR extends the system.lease table with REGIONAL BY ROW partitioning for use with #92395. The PR is itself freestanding.

Epic: CRDB-18596

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner ajwerner force-pushed the ajwerner/lease-partitioning branch 4 times, most recently from 1ee3bcf to b9327f6 Compare November 30, 2022 15:15
@ajwerner ajwerner changed the title [DNM] lease,systemschema: hook up the lease table to regional-by-row partit… lease,systemschema: hook up the lease table to regional-by-row partitioning Nov 30, 2022
@ajwerner ajwerner marked this pull request as ready for review November 30, 2022 19:30
@ajwerner ajwerner requested review from a team as code owners November 30, 2022 19:30
@ajwerner ajwerner requested review from a team and benbardin and removed request for a team November 30, 2022 19:30
@ajwerner ajwerner force-pushed the ajwerner/lease-partitioning branch 2 times, most recently from 72c3cfd to f95068f Compare November 30, 2022 21:52
@ajwerner ajwerner requested a review from jeffswenson November 30, 2022 22:49
// it and returns it.
func (t *descriptorState) upsertLeaseLocked(
ctx context.Context, desc catalog.Descriptor, expiration hlc.Timestamp,
ctx context.Context, desc catalog.Descriptor, expiration hlc.Timestamp, prefix []byte,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you add some comment on prefix? or just make it regionPrefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

sem: quotapool.NewIntPool("lease manager", leaseConcurrencyLimit),
}
lm.storage.regionPrefix = &atomic.Value{}
lm.storage.regionPrefix.Store(enum.One)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can it be something else like an empty slice, or this is just something conventional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We prevent it from being the empty slice. We want it to always be a value. Enums always have this value unless it has been removed.


// SetRegionPrefix sets the prefix this Manager uses to write leases. If val
// is empty, this call is a no-op. Note that the default value is enum.One.
// This means that leases acquired before initial startup may write their
Copy link
Copy Markdown
Contributor

@chengxiong-ruan chengxiong-ruan Dec 1, 2022

Choose a reason for hiding this comment

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

What does this mean for a non-multiregion cluster? (I think my question is should we disallow calls to this method if it's not a multiregion cluster?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In an non-MR cluster this doesn't do anything.

return err
}

s.leaseMgr.SetRegionPrefix(regionPhysicalRep)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

regionPhysicalRep may be []byte{} and if it is, we should use enum.One instead. We discussed pushing this into GetLocalityRegionEnumPhysicalRepresentation, but I think that would be surprising behavior for the API. Instead, we could put the branch in server_sql. Alternatively we could defer initializing the leasing subsystem until a sql session is created and the lease could use the region from the session.

If we don't use enum.One, then we run into problems using sql to query leases that were created before the system database is configured as multi-region:

jeff@multiregion-8.6s4p.crdb.io:26257/defaultdb> select * from system.lease;
ERROR: internal error: unexpected error from the vectorized engine: could not find [] in enum "system.public.crdb_internal_region" representation PhysicalReps: [[64] [96] [128]]; LogicalReps: [gcp-asia-southeast1 gcp-europe-west1 gcp-us-central1] goroutine 12874 [running]:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is handled inside that call. It has the below logic. The value is initialized to enum.One.

if len(val) > 0 {
		m.storage.regionPrefix.Store(val)
}

},
descpb.IndexDescriptor{
Name: "primary",
ID: 1,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The multi-region index should use ID 2 if we want to support migrating from the old schema to the new schema using a protocol resembling a standard schema change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ajwerner ajwerner force-pushed the ajwerner/lease-partitioning branch from f95068f to 411c8c2 Compare December 8, 2022 19:35
@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Dec 8, 2022

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 8, 2022

Build failed:

@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Dec 9, 2022

bors r+

flake was #93287

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 9, 2022

Build succeeded:

@craig craig bot merged commit 2485499 into cockroachdb:master Dec 9, 2022
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Dec 9, 2022
This is an oversight from cockroachdb#92588. Testing will come in cockroachdb#92826.

Epic: CRDB-18596

Release note: None
craig bot pushed a commit that referenced this pull request Dec 10, 2022
93294: dev: do not log noisy bep flag r=rickystewart a=healthy-pod

Release note: None
Epic: none

93342: sql: partition lease table when optimizing system database for MR r=ajwerner a=ajwerner

This is an oversight from #92588. Testing will come in #92826.

Epic: CRDB-18596

Release note: None

Co-authored-by: healthy-pod <ahmad@cockroachlabs.com>
Co-authored-by: Ahmad Abedalqader <ahmad@cockroachlabs.com>
Co-authored-by: Andrew Werner <awerner32@gmail.com>
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.

4 participants