Skip to content

Commit

Permalink
[Linear cache] rework watches and storage in the cache to make code m…
Browse files Browse the repository at this point in the history
…ore common between delta and sotw (#11)

Following previous PRs on linear cache fixes in sotw, the implementation of linear cache has become more common between sotw and delta watches. This PR makes it clearer and reorganize the setup:
 - reorganize resource cache and watch tracking per resource, instead of per mode. This will enable changes like sotw using resource versions
 - avoid multiple marshaling of the resource when the version is already computed through marshaling (not in this PR, as potentially impactful on memory)
 - sotw and delta watches use a common model for their handling, with common code to compute subscription impact vs. cache. Only the generation of the response is different

Signed-off-by: Valerian Roche <[email protected]>
  • Loading branch information
valerian-roche committed Feb 16, 2024
1 parent 03121e4 commit 99822ee
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 338 deletions.
6 changes: 0 additions & 6 deletions pkg/cache/v3/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ type Subscription interface {
// This considers subtleties related to the current migration of wildcard definitions within the protocol.
// More details on the behavior of wildcard are present at https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol#how-the-client-specifies-what-resources-to-return
IsWildcard() bool

// WatchesResources returns whether at least one of the resources provided is currently being watched by the subscription.
// It is currently only applicable to delta-xds.
// If the request is wildcard, it will always return true,
// otherwise it will compare the provided resources to the list of resources currently subscribed
WatchesResources(resourceNames map[string]struct{}) bool
}

// ConfigWatcher requests watches for configuration resources by a node, last
Expand Down
9 changes: 4 additions & 5 deletions pkg/cache/v3/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (

// groups together resource-related arguments for the createDeltaResponse function
type resourceContainer struct {
resourceMap map[string]types.Resource
versionMap map[string]string
systemVersion string
resourceMap map[string]types.Resource
versionMap map[string]string
}

func createDeltaResponse(ctx context.Context, req *DeltaRequest, sub Subscription, resources resourceContainer) *RawDeltaResponse {
func createDeltaResponse(ctx context.Context, req *DeltaRequest, sub Subscription, resources resourceContainer, cacheVersion string) *RawDeltaResponse {
// variables to build our response with
var nextVersionMap map[string]string
var filtered []types.Resource
Expand Down Expand Up @@ -81,7 +80,7 @@ func createDeltaResponse(ctx context.Context, req *DeltaRequest, sub Subscriptio
Resources: filtered,
RemovedResources: toRemove,
NextVersionMap: nextVersionMap,
SystemVersionInfo: resources.systemVersion,
SystemVersionInfo: cacheVersion,
Ctx: ctx,
}
}
Loading

0 comments on commit 99822ee

Please sign in to comment.