Skip to content
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

Closed

Conversation

valerian-roche
Copy link
Collaborator

@valerian-roche valerian-roche commented Dec 17, 2024

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:

  • in delta mode
  • in sotw mode if WithSotwStableVersions is set

Copy link

@atollena atollena left a 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

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).

cacheVersion: cacheVersion,
}
}

// getMarshaledResource lazily marshals the resource and return the bytes.

Choose a reason for hiding this comment

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

Suggested change
// getMarshaledResource lazily marshals the resource and return the bytes.
// getMarshaledResource lazily marshals the resource and returns the bytes.

return c.marshaledResource, nil
}

// getStableVersion lazily hashes the resource and return the stable hash used to track version changes.

Choose a reason for hiding this comment

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

Suggested change
// 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 {

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants