Skip to content

sql: add closest-instance physical planning#98468

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
dt:dsp
Mar 13, 2023
Merged

sql: add closest-instance physical planning#98468
craig[bot] merged 2 commits intocockroachdb:masterfrom
dt:dsp

Conversation

@dt
Copy link
Copy Markdown
Contributor

@dt dt commented Mar 13, 2023

This changes physical planning, specifically how the SQL instance for a
given KV node ID is resolved, to be more generalized w.r.t. different
locality tier taxonomies.

Previously this function had a special case that checked for, and only
for, a specific locality tier with the key "region" and if it was
found, picked a random instance from the subset of instances where their
value for that matched the value for the KV node.

Matching on and only on the "region" tier is both too specific and not
specific enough: it is "too specific" in that it requires a tier with
the key "region" to be used and to match, and is "not specific enough"
in that it simultaneously ignores more specific locality tiers that
would indicate closer matches (e.g. subregion, AZ, data-center or rack).

Instead, this change generalizes this function to identify the subset of
instances that have the "closest match" in localities to the KV node and
pick one of them, where closest match is defined as the longest matching
prefix of locality tiers. In a simple, single-tier locality taxonomy
using the key "region" this should yield the same behavior as the
previous implementation, as all instances with a matching "region" will
have the same longest matching prefix (at length 1), however this more
general approach should better handle other locality taxonomies that use
more tiers and/or tiers with names other than "region".

Currently this change only applies to physical planning for secondary
tenants until physical planning is unified for system and secondary
tenants.

Release note: none.
Epic: CRDB-16910

@dt dt requested review from rharding6373 and yuzefovich March 13, 2023 02:04
@dt dt requested review from a team as code owners March 13, 2023 02:04
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

i like it 💯 - but let's see what our sql queries folk think of it.

Reviewed 2 of 2 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rharding6373 and @yuzefovich)

Copy link
Copy Markdown
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

:lgtm: Very elegant. Thank you for this!

Reviewed 2 of 2 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

I agree, nice work! :lgtm:

Reviewed 2 of 2 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @dt)


pkg/roachpb/metadata.go line 615 at r1 (raw file):

}

// SharedPrefix returns the number of this locality's tiers which match those

nit: something sounds off in "those the passed locality", like a preposition "of" is missing or something.


pkg/sql/distsql_physical_planner.go line 1381 at r2 (raw file):

	}

	// If we were able to determine the region information for at least some

nit: this comment needs a minor adjustment now, probably just s/region/locality/g.

dt added 2 commits March 13, 2023 18:46
Release note: none.
Epic: none.
This changes physical planning, specifically how the SQL instance for a
given KV node ID is resolved, to be more generalized w.r.t. different
locality tier taxonomies.

Previously this function had a special case that checked for, and only
for, a specific locality tier with the key "region" and if it was
found, picked a random instance from the subset of instances where their
value for that matched the value for the KV node.

Matching on and only on the "region" tier is both too specific and not
specific enough: it is "too specific" in that it requires a tier with
the key "region" to be used and to match, and is "not specific enough"
in that it simultaneously ignores more specific locality tiers that
would indicate closer matches (e.g. subregion, AZ, data-center or rack).

Instead, this change generalizes this function to identify the subset of
instances that have the "closest match" in localities to the KV node and
pick one of them, where closest match is defined as the longest matching
prefix of locality tiers. In a simple, single-tier locality taxonomy
using the key "region" this should yield the same behavior as the
previous implementation, as all instances with a matching "region" will
have the same longest matching prefix (at length 1), however this more
general approach should better handle other locality taxonomies that use
more tiers and/or tiers with names other than "region".

Currently this change only applies to physical planning for secondary
tenants until physical planning is unified for system and secondary
tenants.

Release note: none.
Epic: none.
Copy link
Copy Markdown
Contributor Author

@dt dt left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @knz, @rharding6373, and @yuzefovich)


pkg/roachpb/metadata.go line 615 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: something sounds off in "those the passed locality", like a preposition "of" is missing or something.

Done.

Yep, indeed was supposed to say "of the passed..."


pkg/sql/distsql_physical_planner.go line 1381 at r2 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: this comment needs a minor adjustment now, probably just s/region/locality/g.

Done

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 13, 2023

Build failed (retrying...):

Copy link
Copy Markdown
Contributor

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

💯

Reviewed 1 of 2 files at r1, 4 of 4 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @dt)

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 13, 2023

Build succeeded:

@craig craig bot merged commit c31c1ac into cockroachdb:master Mar 13, 2023
@dt dt deleted the dsp branch March 21, 2023 01:31
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