Skip to content

kv: mask system config gossip info in tenant GossipSubscription stream#52598

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/systemDBStrip
Aug 17, 2020
Merged

kv: mask system config gossip info in tenant GossipSubscription stream#52598
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/systemDBStrip

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Aug 10, 2020

Fixes #52361.

This commit creates a new GossipSubscriptionSystemConfigMask object that the
KV server uses to filter out most system config keys within the "system-db"
gossip key. The keys remaining after the filter are only those that a tenant
SQL process needs access to, namely just enough of the zone hierarchy to
understand which zone configurations apply to their keyspace.

@nvb nvb requested a review from tbg August 10, 2020 21:18
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@tbg tbg added the A-multitenancy Related to multi-tenancy label Aug 11, 2020
// SystemConfigMask is a mask that can be applied to a set of system config
// entries to filter out unwanted entries.
type SystemConfigMask struct {
keys []roachpb.Key
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: name this allowed so that it's clear this is an allowlist?

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.

func (m SystemConfigMask) Apply(entries SystemConfigEntries) SystemConfigEntries {
var res SystemConfigEntries
for _, key := range m.keys {
i := sort.Search(len(entries.Values), func(i int) bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if entries.Values is also sorted (as it is?), shouldn't it be possible to "merge search" here by discarding entries.Values[:i+1] after each hit? Probably not worth it though, given m.keys is small in practice.

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.

Yes, this seems possible, but it's probably not worth the complexity. I actually thought of doing so while writing this, and then remembered that at some point during the TLA+ training, you convinced me with some fancy math that doing this was still O(m*log(n)).

Fixes cockroachdb#52361.

This commit creates a new GossipSubscriptionSystemConfigMask object that the
KV server uses to filter out most system config keys within the "system-db"
gossip key. The keys remaining after the filter are only those that a tenant
SQL process needs access to, namely just enough of the zone hierarchy to
understand which zone configurations apply to their keyspace.
@nvb nvb force-pushed the nvanbenschoten/systemDBStrip branch from f81cd1b to b5f85a7 Compare August 17, 2020 17:15
@nvb
Copy link
Copy Markdown
Contributor Author

nvb commented Aug 17, 2020

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 17, 2020

Build succeeded:

@craig craig bot merged commit 9b3ef9d into cockroachdb:master Aug 17, 2020
@nvb nvb deleted the nvanbenschoten/systemDBStrip branch August 17, 2020 21:54
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.

kv: filter "system-db" keys for GossipSubscription requests from tenants

3 participants