-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
systemspanconfig: introduce Target and encoding/decoding methods #75641
systemspanconfig: introduce Target and encoding/decoding methods #75641
Conversation
@irfansharif and I have been talking a bit more about how we can change some of the types/protos in the span config package to reduce the number of types exposed outside the package while still maintaining explicit internal types for I plan on doing this in a separate patch, but if we go this route, We also agreed that it would make sense to review the business logic of the KVAccessor and Target encoding/decoding separate to the type change. The hope is it'll make review iterations faster + targeted (for both me and the reviewers); however it's worth keeping in mind that some of this stuff might shift in the near term. |
5012f9b
to
4947d17
Compare
4947d17
to
f987775
Compare
type Target struct { | ||
// TargeterTenantID is the ID of the tenant that specified the system span | ||
// configuration. | ||
TargeterTenantID roachpb.TenantID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had discussed considering SourceTenantID and TargetTenantID to be more intuitive names for these fields. I'm okay leaving things as they are since the comments are explanatory but wanted to check if you had considered that?
targeteeTenantID = targeterTenantID | ||
} | ||
|
||
t := Target{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to just call return MakeTarget
at this point?
@@ -218,7 +222,7 @@ func (s *SQLTranslator) generateSpanConfigurationsForNamedZone( | |||
}) | |||
spans = append(spans, roachpb.Span{ | |||
Key: keys.TimeseriesSpan.EndKey, | |||
EndKey: keys.SystemMax, | |||
EndKey: keys.SystemSpanConfigSpan.Key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed briefly, but does it make sense to include keys.SystemConfigSpan.EndKey
to keys.SystemMax
just incase we ever have any keys in that hole?
Key: keys.EverythingSpan.Key, | ||
EndKey: keys.SystemSpanConfigSpan.Key, | ||
}) | ||
spans = append(spans, roachpb.Span{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here that we intentionally elide the SystemSpanConfigSpan. My hunch is that this will change once we build out the SystemSpanConfigStore etc?
This patch introduces a new `systemspanconfig.Target` type which is intended as in interemediate representation for system span config targets throughout the `spanconfig` package. It ties together a targeter tenant ID with a targetee tenant ID (along with validation to ensure secondary tenants don't target other tenants). We also reserve a `SystemSpanConfigSpan` at the end of the System range. This allows us to assign special meaning to key-prefixes carved out of this range (when stored in `system.span_configurations`). By ensuring this span is carved at the end of the system range, we can ensure that the host tenant does not install span configurations to this span directly. We define special key prefixes for system span configurations in this range and establish a mapping between a Target <-> span using `Encode` and `Decode` methods. This is useful when we store sysytem span configurations in `system.span_configurations` given its schema. Ditto for reading from the table. We'll make use of the `Target` in upcoming PRs, specifically in the `KVAccessor`, `KVSubscriber`, and (the upcoming) `SystemSpanConfigStore`. The `KVAccessor` will construct `Targets` using tenant information from the context as the targeter tenant. It'll use the `roachpb.SystemSpanConfigTargets` supplied to it by RPCs (See cockroachdb#75615). The encoding/decoding methods will be used when writing to/reading from `system.span_configurations`. While the existing `roachpb.SystemSpanConfigTarget` is sufficient for our use in the `KVAccessor` (which runs on SQL pods), the richer structure is motivated by the desire to also use this type in the `KVSubscriber` (when receiving system span config events) and `SystemSpanConfigStore` (which is an in-memory representation of the system span config state). Down in KV we want to distinguish between a tenant installed system span config on its entire keyspace vs. a host tenant installed system span config over a tenants keyspace. Release note: None
f987775
to
63b4f2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @ajwerner, @irfansharif, and @nvanbenschoten)
pkg/spanconfig/spanconfigreconciler/reconciler.go, line 285 at r1 (raw file):
Previously, adityamaru (Aditya Maru) wrote…
Maybe add a comment here that we intentionally elide the SystemSpanConfigSpan. My hunch is that this will change once we build out the SystemSpanConfigStore etc?
I don't think this will change even when we build out the SystemSpanConfigStore
because we never want to install/ get configs at these keyspans directly; KV stores things here by translating SystemSpanConfigTargets
, but at the layer of the reconciler, we shouldn't be doing that translation.
I'll add a comment to this effect though.
pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go, line 225 at r1 (raw file):
Previously, adityamaru (Aditya Maru) wrote…
discussed briefly, but does it make sense to include
keys.SystemConfigSpan.EndKey
tokeys.SystemMax
just incase we ever have any keys in that hole?
Talked offline, but considering the SystemSpanConfigSpan
is at the end of the System
keyrange, and anything that comes between SystemSpanConfigSpan.EndKey
and `SystemMax' will still be prefixed by this span, I think it's fair to say we'll never have any keys in that hole.
pkg/spanconfig/systemspanconfig/target.go, line 24 at r1 (raw file):
Previously, adityamaru (Aditya Maru) wrote…
We had discussed considering SourceTenantID and TargetTenantID to be more intuitive names for these fields. I'm okay leaving things as they are since the comments are explanatory but wanted to check if you had considered that?
Switched!
pkg/spanconfig/systemspanconfig/target.go, line 56 at r1 (raw file):
Previously, adityamaru (Aditya Maru) wrote…
does it make sense to just call
return MakeTarget
at this point?
Done.
Thanks for capturing the discussion on future typing changes we're looking to explore. That only came up after having looked at this PR and it's relation to the protos we recently introduced in #74765, the motivation being that we're 2x-ing the number of symbols for a lot of interfaces in the package -- one to deal with the SystemConfigSpan{,Target,Entry} types and one for just the SpanConfig{,Entry} type. We ought to consider this more fully I think, and now's a great time to do it. The affected interfaces/impls IIUC are:
Given we're open to unifying the typing story, I would encourage you to work through the implications discussed here first: #75641 (comment). I suspect it:
That said, if the end-state is clearer to others, and therefore feel more comfortable with this PR's incremental step, I won't hold up the merge train. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sans the typing discussions above this looks good to me. I'll leave it up to you on how these PRs should be ordered.
Closing this in favour of #76219 |
This patch introduces a new
systemspanconfig.Target
type which isintended as in interemediate representation for system span config
targets throughout the
spanconfig
package. It ties together atargeter tenant ID with a targetee tenant ID (along with validation
to ensure secondary tenants don't target other tenants).
We also reserve a
SystemSpanConfigSpan
at the end of the Systemrange. This allows us to assign special meaning to key-prefixes carved
out of this range (when stored in
system.span_configurations
).By ensuring this span is carved at the end of the system range, we can
ensure that the host tenant does not install span configurations to this
span directly.
We define special key prefixes for system span configurations in this
range and establish a mapping between a Target <-> span using
Encode
and
Decode
methods. This is useful when we store sysytem spanconfigurations in
system.span_configurations
given its schema. Dittofor reading from the table.
We'll make use of the
Target
in upcoming PRs, specifically in theKVAccessor
,KVSubscriber
, and (the upcoming)SystemSpanConfigStore
.The
KVAccessor
will constructTargets
using tenant information fromthe context as the targeter tenant. It'll use the
roachpb.SystemSpanConfigTargets
supplied to it by RPCs (See #75615).The encoding/decoding methods will be used when writing to/reading from
system.span_configurations
.While the existing
roachpb.SystemSpanConfigTarget
is sufficientfor our use in the
KVAccessor
(which runs on SQL pods), the richerstructure is motivated by the desire to also use this type in the
KVSubscriber
(when receiving system span config events) andSystemSpanConfigStore
(which is an in-memory representation of thesystem span config state). Down in KV we want to distinguish between a
tenant installed system span config on its entire keyspace vs. a host
tenant installed system span config over a tenants keyspace.
Release note: None