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

sql: push tenant-bound SQL codec into descriptor key generation #48376

Merged
merged 2 commits into from
May 5, 2020

Conversation

nvanbenschoten
Copy link
Member

Informs #48123.

This commit continues with the plumbing that began an #48190. It pushes a tenant-bound SQL codec into the other main source of key generation in the SQL layer - descriptor manipulation and metadata handling. This allows SQL tenants to properly handle metadata descriptors for its database and tables.

This ended up being a larger undertaking than I had originally expected. However, now that it's complete, we're in a pretty good spot:

  1. sqlbase.MetadataSchema is ready to be used for sql: tenant deletion #47904.
  2. we can now run SQL migrations for a non-system tenant.
  3. there is only one remaining use of keys.TODOSQLCodec in pkg/sql. See sql/kv: how does multi-tenancy interact with zone configurations? #48375.

@nvanbenschoten nvanbenschoten added the A-multitenancy Related to multi-tenancy label May 4, 2020
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

That wasn't fun to review, I bet it was even worse to write. :lgtm: though and exciting that we're getting close to wrapping up the plumbing! Hope this goes in before it rots.

Reviewed 6 of 6 files at r1, 136 of 136 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @asubiotto and @nvanbenschoten)


pkg/sql/zone_config.go, line 41 at r2 (raw file):

// to make sure to look at the correct Zones according to the tenant prefix of
// its key range? See #48375.
var zoneConfigCodec = keys.TODOSQLCodec

I would have expected us to use SystemCodec here as I don't anticipate any plan to allow tenants to store their own zone configs separately from the system tenants. Fine to merge with this TODO in place.


pkg/sql/tests/hash_sharded_test.go, line 139 at r2 (raw file):

		}

		tableDesc := sqlbase.GetTableDescriptor(kvDB, keys.SystemSQLCodec, `d`, `kv_secondary`)

Maybe something we can look into is to replace these calls in tests with RandomCodec() where possible, to improve testing coverage.

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @asubiotto and @nvanbenschoten)

These were all pretty easy because there was a ExecutorConfig nearby.
Informs cockroachdb#48123.

This commit continues with the plumbing that began an cockroachdb#48190. It pushes
a tenant-bound SQL codec into the other main source of key generation in
the SQL layer - descriptor manipulation and metadata handling. This
allows SQL tenants to properly handle metadata descriptors for its
database and tables.

This ended up being a larger undertaking than I had originally expected.
However, now that it's complete, we're in a pretty good spot:
1. `sqlbase.MetadataSchema` is ready to be used for cockroachdb#47904.
2. we can now run SQL migrations for a non-system tenant
3. there is only one remaining use of TODOSQLCodec in pkg/sql. See cockroachdb#48375.
@nvanbenschoten
Copy link
Member Author

TFTR! I can't imagine that was an enjoyable experience. Merging to avoid any more skew.

bors r+

@craig
Copy link
Contributor

craig bot commented May 5, 2020

Build succeeded

@craig craig bot merged commit 3ea985a into cockroachdb:master May 5, 2020
Anzoteh96 pushed a commit to Anzoteh96/cockroach that referenced this pull request May 5, 2020
48376: sql: push tenant-bound SQL codec into descriptor key generation r=nvanbenschoten a=nvanbenschoten

Informs cockroachdb#48123.

This commit continues with the plumbing that began an cockroachdb#48190. It pushes a tenant-bound SQL codec into the other main source of key generation in the SQL layer - descriptor manipulation and metadata handling. This allows SQL tenants to properly handle metadata descriptors for its database and tables.

This ended up being a larger undertaking than I had originally expected. However, now that it's complete, we're in a pretty good spot:
1. `sqlbase.MetadataSchema` is ready to be used for cockroachdb#47904.
2. we can now run SQL migrations for a non-system tenant.
3. there is only one remaining use of `keys.TODOSQLCodec` in pkg/sql. See cockroachdb#48375.

Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>

Release note (<category, see below>): <what> <show> <why>
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/tenantKey4 branch May 6, 2020 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-multitenancy Related to multi-tenancy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants