-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Linear] Ensure a resource is only serialized/hashed at most once in linear cache #20
Conversation
cca7965
to
4100f52
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.
looks reasonable to me, for what it's worth.
@@ -179,13 +177,13 @@ type RawResponse struct { | |||
Version string | |||
|
|||
// Resources to be included in the response. | |||
Resources []types.ResourceWithTTL | |||
resources []cachedResource |
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.
Don't forget to fix the godoc comments (here and everywhere).
pkg/cache/v3/linear.go
Outdated
cacheVersion: cacheVersion, | ||
} | ||
} | ||
|
||
// getMarshaledResource lazily marshals the resource and return the bytes. |
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.
// getMarshaledResource lazily marshals the resource and return the bytes. | |
// getMarshaledResource lazily marshals the resource and returns the bytes. |
pkg/cache/v3/linear.go
Outdated
return c.marshaledResource, nil | ||
} | ||
|
||
// getStableVersion lazily hashes the resource and return the stable hash used to track version changes. |
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.
// getStableVersion lazily hashes the resource and return the stable hash used to track version changes. | |
// getStableVersion lazily hashes the resource and returns the stable hash used to track version changes. |
Name: GetResourceName(resource.Resource), | ||
Ttl: durationpb.New(*resource.TTL), | ||
func (r *RawResponse) marshalTTLResource(resource cachedResource) (*anypb.Any, error) { | ||
if resource.ttl == nil { |
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.
How are TTLs for resources decided out of curiosity?
Currently the go-control-plane caches (both linear and snapshots) will serialize the resource as many time as there are clients receiving it.
This is an issue with control-planes watched by a lot of clients, especially with large resources (e.g. endpoints)
This PR ensures that the serialization occurs at most once per resource:
WithSotwStableVersions
is set