Skip to content

Commit

Permalink
incremental: don't delete non-existent resources in non-wildcard mode…
Browse files Browse the repository at this point in the history
… in delta xds (#488)

* Respond with empty resource if it was explicitly requested by the client and doesn't exist on the server in delta xds

Signed-off-by: Sergey Matyukevich <s.matyukevich@gmail.com>
  • Loading branch information
s-matyukevich authored Sep 15, 2021
1 parent b892260 commit e483d0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/cache/v3/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ func createDeltaResponse(ctx context.Context, req *DeltaRequest, state stream.St
filtered = append(filtered, r)
}
nextVersionMap[name] = nextVersion
} else {
// We track non-existent resources for non-wildcard streams until the client explicitly unsubscribes from them.
nextVersionMap[name] = ""
}
}
}

// Compute resources for removal regardless of the request type
for name := range state.GetResourceVersions() {
if _, ok := resources.resourceMap[name]; !ok {
for name, prevVersion := range state.GetResourceVersions() {
// The prevVersion != "" check is in place to make sure we are only sending an update to the client once right after it is removed.
// If the client decides to keep the subscription we skip the add for every subsequent response.
if _, ok := resources.resourceMap[name]; !ok && prevVersion != "" {
toRemove = append(toRemove, name)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v3/linear_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestLinearDeltaExistingResources(t *testing.T) {
w := make(chan DeltaResponse, 1)
c.CreateDeltaWatch(&DeltaRequest{TypeUrl: testType}, state, w)
checkDeltaWatchCount(t, c, 0)
verifyDeltaResponse(t, w, []resourceInfo{{"b", hashB}}, []string{"c"})
verifyDeltaResponse(t, w, []resourceInfo{{"b", hashB}}, []string{})

state = stream.NewStreamState(false, map[string]string{"a": "", "b": ""})
w = make(chan DeltaResponse, 1)
Expand Down

0 comments on commit e483d0d

Please sign in to comment.