tenantsettingswatcher: implement watcher and integrate into server#76445
tenantsettingswatcher: implement watcher and integrate into server#76445craig[bot] merged 5 commits intocockroachdb:masterfrom
Conversation
1d5f1af to
a4c22c5
Compare
|
@ajwerner I added a commit that adds |
9e86e0c to
050c62d
Compare
|
I am looking at It doesn't work with this PR because the tenant requests the settings regardless of its version, and the host can't satisfy that request until it is upgraded. I wonder what the right thing to do is here. Threading the tenant cluster version through to the |
050c62d to
0d2d1ca
Compare
I did that, I think that makes the most sense. The overrides will automatically start getting updated once the version is upgraded. |
0d2d1ca to
c8aac71
Compare
ba2ff40 to
16e7d5c
Compare
This commit introduces the overrides store, the in-memory data structure that will hold all tenant overrides. The data structure is designed for efficient read access and to allow multiple goroutines to get notified of changes (via a channel close). Release note: None
c1e2148 to
348cdc7
Compare
| ) (descpb.ID, error) { | ||
| var id descpb.ID | ||
| err := r.collectionFactory.Txn(ctx, r.ie, r.db, func(ctx context.Context, txn *kv.Txn, descriptors *Collection) error { | ||
| _, desc, err := descriptors.GetImmutableTableByName( |
There was a problem hiding this comment.
Now that you're here, you can use the lower-level call to get what you need. This will also avoid the lookup against kv.
var id descpb.ID
if err := r.collectionFactory.Txn(ctx, r.ie, r.db, func(
ctx context.Context, txn *kv.Txn, descriptors *Collection,
) (err error) {
id, err = descriptors.kv.lookupName(
ctx, txn, nil /* maybeDatabase */, keys.SystemDatabaseID, keys.PublicSchemaID, tableName,
)
return err
}); err != nil {
return 0, err
}
return id, nil| // | ||
| // The caller can listen for closing of changeCh, which is guaranteed to happen | ||
| // if the tenant's overrides change. | ||
| func (s *overridesStore) GetTenantOverrides(tenantID roachpb.TenantID) *tenantOverrides { |
| // | ||
| // This method is called once we complete a full initial scan of the | ||
| // tenant_setting table. | ||
| func (s *overridesStore) SetAll(allOverrides map[roachpb.TenantID][]roachpb.TenantSetting) { |
| } | ||
| } | ||
|
|
||
| func (s *overridesStore) Init() { |
| // SetTenantOverride changes an override for the given tenant. If the setting | ||
| // has an empty value, the existing override is removed; otherwise a new | ||
| // override is added. | ||
| func (s *overridesStore) SetTenantOverride( |
|
|
||
| // GetTenantOverrides returns the current overrides for the given tenant, and a | ||
| // channel that will be closed when the overrides for this tenant change. | ||
| func (w *Watcher) GetTenantOverrides( |
There was a problem hiding this comment.
Note that the returned slice is shared and must not be modified
| // GetAllTenantOverrides returns the current overrides for all tenants. | ||
| // Each of these overrides apply to any tenant, as long as that tenant doesn't | ||
| // have an override for the same setting. | ||
| func (w *Watcher) GetAllTenantOverrides() ( |
There was a problem hiding this comment.
Note that the returned slice is shared and must not be modified
This commit implements the tenantsettingswatcher, which monitors the tenant_settings table and allows callers to access the current overrides and listen for changes. For now, we hardcode the tenant_settings system table ID to 50 (which will be the case in fresh clusters). We will fix this in a follow-up change. Release note: None
This commit integrates the tenant settings watcher into the server and implements the TenantSettings API. Release note: None
This commit adds functionality to logic tests to allow running SQL against the host cluster in a tenant configuration. This allows us to manipulate the tenant_settings table and observe the settings changing on the tenant. We add a tenant_settings test that verifies basic overrides behavior. This test can become more comprehensive once we implement the new ALTER TENANT settings. Release note: None
This commit adds the SystemTableIDResolver interface and its implementation, and modifies tenantsettingswatcher to use it for the `tenant_settings` table. Release note: None
348cdc7 to
f6dbccc
Compare
RaduBerinde
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @ajwerner, and @dt)
pkg/server/tenantsettingswatcher/overrides_store.go, line 63 at r10 (raw file):
Previously, ajwerner wrote…
why export this?
It's not really, since the type itself is not exported. It's just meant to differentiate the "API" of the datastructure from the internals.
pkg/server/tenantsettingswatcher/watcher.go, line 271 at r10 (raw file):
Previously, ajwerner wrote…
Note that the returned slice is shared and must not be modified
Done.
pkg/server/tenantsettingswatcher/watcher.go, line 281 at r10 (raw file):
Previously, ajwerner wrote…
Note that the returned slice is shared and must not be modified
Done.
pkg/sql/catalog/descs/system_table.go, line 49 at r10 (raw file):
Previously, ajwerner wrote…
Now that you're here, you can use the lower-level call to get what you need. This will also avoid the lookup against kv.
var id descpb.ID if err := r.collectionFactory.Txn(ctx, r.ie, r.db, func( ctx context.Context, txn *kv.Txn, descriptors *Collection, ) (err error) { id, err = descriptors.kv.lookupName( ctx, txn, nil /* maybeDatabase */, keys.SystemDatabaseID, keys.PublicSchemaID, tableName, ) return err }); err != nil { return 0, err } return id, nil
Done.
RaduBerinde
left a comment
There was a problem hiding this comment.
TFTR!
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @ajwerner, and @dt)
|
bors r+ |
|
Build succeeded: |
For now, we hardcode 50 as the system table ID. I plan to work on that and add a commit to this PR. Adding do-not-merge label until then.tenantsettingswatcher: in-memory data structure
This commit introduces the overrides store, the in-memory data
structure that will hold all tenant overrides.
The data structure is designed for efficient read access and to allow
multiple goroutines to get notified of changes (via a channel close).
Release note: None
tenantsettingswatcher: implement watcher
This commit implements the tenantsettingswatcher, which monitors the
tenant_settings table and allows callers to access the current
overrides and listen for changes.
For now, we hardcode the tenant_settings system table ID to 50 (which
will be the case in fresh clusters). We will fix this in a follow-up
change.
Release note: None
tenantsettingswatcher: integrate into server
This commit integrates the tenant settings watcher into the server and
implements the TenantSettings API.
Release note: None
logictestccl: add tenant_settings test
This commit adds functionality to logic tests to allow running SQL
against the host cluster in a tenant configuration. This allows us to
manipulate the tenant_settings table and observe the settings changing
on the tenant.
We add a tenant_settings test that verifies basic overrides behavior.
This test can become more comprehensive once we implement the new
ALTER TENANT settings.
Release note: None
catalog: add SystemTableIDResolver
This commit adds the SystemTableIDResolver interface and its
implementation, and modifies tenantsettingswatcher to use it for the
tenant_settingstable.Release note: None