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

multitenant: move tenantcapabilities.IDs to tenantcapabilitiespb #141774

Merged
merged 2 commits into from
Mar 6, 2025

Conversation

shubhamdhama
Copy link
Contributor

@shubhamdhama shubhamdhama commented Feb 20, 2025

multitenant: relocate `tenantcapabilitiespb` directory

This commit relocates the tenantcapabilitiespb directory to the same
level as tenantcapabilities. This change improves consistency with other
similar directories (e.g., mtinfopb) and shortens the long package path
(pkg/multitenant/tenantcapabilities).

multitenant: move `tenantcapabilities.IDs` to `tenantcapabilitiespb`

This commit moves tenantcapabilities.IDs from
pkg/multitenant/tenantcapabilities to tenantcapabilitiespb to resolve a
cyclic dependency. pkg/base needs to use capability constants/enums, but
a direct dependency on pkg/multitenant/tenantcapabilities would create a
cycle. tenantcapabilitiespb has fewer dependencies, making it a more
suitable location for these IDs. It also makes sense to keep high-level
contracts like these in the tenantcapabilitiespb package.

Informs: #138912
Epic: CRDB-38970
Release note: None

@shubhamdhama shubhamdhama requested review from a team as code owners February 20, 2025 10:13
@shubhamdhama shubhamdhama requested review from kev-cao, andyyang890, golgeek, DarrylWong, angles-n-daemons and yuzefovich and removed request for a team February 20, 2025 10:13
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rafiss rafiss 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 @andyyang890, @angles-n-daemons, @DarrylWong, @golgeek, @kev-cao, and @yuzefovich)


pkg/multitenant/tenantcapabilities/capability.go line 95 at r3 (raw file):

// EnableAll enables maximum access to services.
func EnableAll(t *tenantcapabilitiespb.TenantCapabilities) {

is this function for tests only? if so, let's name it TestingEnableAll to make that clear.

we use that convention a lot, for example:

// TestingSetDefaultMinCheckpointFrequency changes DefaultMinCheckpointFrequency for tests.
// Returns function to restore flush frequency to its original value.
func TestingSetDefaultMinCheckpointFrequency(f time.Duration) func() {
old := DefaultMinCheckpointFrequency
DefaultMinCheckpointFrequency = f
return func() { DefaultMinCheckpointFrequency = old }
}

(i haven't reviewd the PR closely yet, but the same naming convention should be used for any other testing functions that were introduced here)

Copy link
Collaborator

@rafiss rafiss 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 @andyyang890, @angles-n-daemons, @DarrylWong, @golgeek, @kev-cao, @shubhamdhama, and @yuzefovich)


pkg/multitenant/tenantcapabilities/capability.go line 95 at r3 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

is this function for tests only? if so, let's name it TestingEnableAll to make that clear.

we use that convention a lot, for example:

// TestingSetDefaultMinCheckpointFrequency changes DefaultMinCheckpointFrequency for tests.
// Returns function to restore flush frequency to its original value.
func TestingSetDefaultMinCheckpointFrequency(f time.Duration) func() {
old := DefaultMinCheckpointFrequency
DefaultMinCheckpointFrequency = f
return func() { DefaultMinCheckpointFrequency = old }
}

(i haven't reviewd the PR closely yet, but the same naming convention should be used for any other testing functions that were introduced here)

and also, similar to that example, it's prudent to have these testing functions return a cleanup function that resets everything back to the previous state, so that cleanup can be called by a defer statement.

@shubhamdhama
Copy link
Contributor Author

pkg/multitenant/tenantcapabilities/capability.go line 95 at r3 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

and also, similar to that example, it's prudent to have these testing functions return a cleanup function that resets everything back to the previous state, so that cleanup can be called by a defer statement.

This is just a code relocation: some existing code from capabilities.go has been moved to capability.go. No new functionality has been added.

@shubhamdhama shubhamdhama force-pushed the refactor-tenant-capabilities branch from 5373bc4 to 9c5d352 Compare February 21, 2025 12:53
Copy link

🟢 Sysbench [SQL, 3node, oltp_read_write]
Metric Old Commit New Commit Delta Note Threshold
🟢 sec/op 10.99m ±1% 10.93m ±0% -0.52% p=0.035 n=10 3.0%
errs/op 0.000 ±0% 0.000 ±0% ~ p=1.000 n=10 0.0%
allocs/op 10.15k ±1% 10.17k ±0% ~ p=0.469 n=10 2.0%
B/op 2.204Mi ±0% 2.205Mi ±0% ~ p=0.853 n=10 2.0%
Reproduce

benchdiff binaries:

mkdir -p benchdiff/9c5d352/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/9c5d35278925ab275bc3030de676cbd8dc0ee56d/bin/pkg_sql_tests benchdiff/9c5d352/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/9c5d352/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/fbcabe0/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/fbcabe029eb2e1701710d08cebbca6d15089f911/bin/pkg_sql_tests benchdiff/fbcabe0/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/fbcabe0/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/SQL/3node/oltp_read_write$ --old=fbcabe0 --new=9c5d352 ./pkg/sql/tests
🟢 Sysbench [KV, 1node, local, oltp_read_only]
Metric Old Commit New Commit Delta Note Threshold
🟢 sec/op 666.7µ ±1% 658.4µ ±1% -1.26% p=0.015 n=10 2.0%
errs/op 0.000 ±0% 0.000 ±0% ~ p=1.000 n=10 0.0%
allocs/op 439.0 ±0% 439.0 ±0% ~ p=1.000 n=10 1.5%
🟢 B/op 254.2Ki ±0% 254.1Ki ±0% -0.02% p=0.006 n=10 1.5%
Reproduce

benchdiff binaries:

mkdir -p benchdiff/9c5d352/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/9c5d35278925ab275bc3030de676cbd8dc0ee56d/bin/pkg_sql_tests benchdiff/9c5d352/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/9c5d352/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/fbcabe0/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/fbcabe029eb2e1701710d08cebbca6d15089f911/bin/pkg_sql_tests benchdiff/fbcabe0/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/fbcabe0/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/1node_local/oltp_read_only$ --old=fbcabe0 --new=9c5d352 ./pkg/sql/tests
⚪ Sysbench [KV, 1node, local, oltp_write_only]
Metric Old Commit New Commit Delta Note Threshold
sec/op 1.303m ±2% 1.301m ±3% ~ p=0.280 n=10 2.5%
errs/op 0.000 ±0% 0.000 ±0% ~ p=1.000 n=10 0.0%
allocs/op 1.391k ±0% 1.390k ±0% ~ p=0.548 n=10 1.8%
B/op 288.7Ki ±0% 288.7Ki ±1% ~ p=0.684 n=10 1.8%
Reproduce

benchdiff binaries:

mkdir -p benchdiff/9c5d352/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/9c5d35278925ab275bc3030de676cbd8dc0ee56d/bin/pkg_sql_tests benchdiff/9c5d352/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/9c5d352/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/fbcabe0/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/fbcabe029eb2e1701710d08cebbca6d15089f911/bin/pkg_sql_tests benchdiff/fbcabe0/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/fbcabe0/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/1node_local/oltp_write_only$ --old=fbcabe0 --new=9c5d352 ./pkg/sql/tests
Artifacts

download:

mkdir -p new
gcloud storage cp gs://cockroach-microbench-ci/artifacts/9c5d35278925ab275bc3030de676cbd8dc0ee56d/13457216717-1/\* new/
mkdir -p old
gcloud storage cp gs://cockroach-microbench-ci/artifacts/fbcabe029eb2e1701710d08cebbca6d15089f911/13457216717-1/\* old/
Legend
  • Neutral: No significant performance change.
  • 🟡 Warning: Slight degradation, likely due to variance, but still within thresholds.
  • 🔴 Regression: Likely performance regression, requiring investigation.
  • 🟢 Improvement: Possible performance gain.

No regressions detected!

built with commit: 9c5d35278925ab275bc3030de676cbd8dc0ee56d

@shubhamdhama shubhamdhama force-pushed the refactor-tenant-capabilities branch 3 times, most recently from 5b91044 to 226b6e6 Compare March 4, 2025 08:23
This commit relocates the `tenantcapabilitiespb` directory to the same
level as `tenantcapabilities`.  This change improves consistency with other
similar directories (e.g., `mtinfopb`) and shortens the long package path
(`pkg/multitenant/tenantcapabilities`).
This commit moves `tenantcapabilities.IDs` from
`pkg/multitenant/tenantcapabilities` to `tenantcapabilitiespb` to resolve a
cyclic dependency.  `pkg/base` needs to use capability constants/enums, but
a direct dependency on `pkg/multitenant/tenantcapabilities` would create a
cycle. `tenantcapabilitiespb` has fewer dependencies, making it a more
suitable location for these IDs. It also makes sense to keep high-level
contracts like these in the `tenantcapabilitiespb` package.

Informs: cockroachdb#138912
Epic: CRDB-38970
Release note: None
@shubhamdhama shubhamdhama force-pushed the refactor-tenant-capabilities branch from 226b6e6 to ecca7f5 Compare March 6, 2025 06:13
Copy link
Contributor

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

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

Thank you. LGTM!

@shubhamdhama
Copy link
Contributor Author

Thanks for the reviews!

bors r=stevendanna,cthumuluru-crdb

@shubhamdhama
Copy link
Contributor Author

shubhamdhama commented Mar 6, 2025

pkg/multitenant/tenantcapabilities/capability.go line 95 at r3 (raw file):

Previously, shubhamdhama (Shubham Dhama) wrote…

This is just a code relocation: some existing code from capabilities.go has been moved to capability.go. No new functionality has been added.

@rafiss, it's actually used for non-test code, so I think we are good here:

if tid.IsSystem() {
tenantcapabilities.EnableAll(&info.ProtoInfo.Capabilities)
}

@craig
Copy link
Contributor

craig bot commented Mar 6, 2025

@craig craig bot merged commit f54cc8e into cockroachdb:master Mar 6, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants