Skip to content

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

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
nvb:nvanbenschoten/tenantKey4
May 5, 2020
Merged

sql: push tenant-bound SQL codec into descriptor key generation#48376
craig[bot] merged 2 commits intocockroachdb:masterfrom
nvb:nvanbenschoten/tenantKey4

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented May 4, 2020

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.

@nvb nvb added the A-multitenancy Related to multi-tenancy label May 4, 2020
@nvb nvb requested review from asubiotto and tbg May 4, 2020 21:23
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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
Copy Markdown
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)

nvb added 2 commits May 5, 2020 12:36
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.
@nvb nvb force-pushed the nvanbenschoten/tenantKey4 branch from cf00e3c to f618c80 Compare May 5, 2020 16:40
@nvb
Copy link
Copy Markdown
Contributor Author

nvb commented May 5, 2020

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

bors r+

@craig
Copy link
Copy Markdown
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>
@nvb nvb 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