@@ -143,29 +143,27 @@ func (cache *LinearCache) respond(value chan Response, staleResources []string)
143
143
}
144
144
}
145
145
146
- func (cache * LinearCache ) notifyAll (modified map [string ]struct {}, fromDeletion bool ) {
146
+ func (cache * LinearCache ) notifyAll (modified map [string ]struct {}) {
147
147
// de-duplicate watches that need to be responded
148
148
notifyList := make (map [chan Response ][]string )
149
- if ! fromDeletion {
150
- for name := range modified {
151
- for watch := range cache .watches [name ] {
152
- notifyList [watch ] = append (notifyList [watch ], name )
153
- }
154
- delete (cache .watches , name )
155
- }
156
- } else {
157
- for deletedName := range modified {
158
- for watch , streamState := range cache .watches [deletedName ] {
159
- resourceNames := streamState .GetKnownResourceNames (cache .typeURL )
160
- for resourceName := range resourceNames {
161
- // To avoid the stale in notifyList becomes empty slice.
162
- // Don't skip resource name that has been deleted here.
163
- // It would be filtered out in respond because the corresponding resource has been deleted.
164
- notifyList [watch ] = append (notifyList [watch ], resourceName )
149
+ for name := range modified {
150
+ for watch , streamState := range cache .watches [name ] {
151
+ resourceNames := streamState .GetKnownResourceNames (cache .typeURL )
152
+ modifiedNameInResourceName := false
153
+ for resourceName := range resourceNames {
154
+ if ! modifiedNameInResourceName && resourceName == name {
155
+ modifiedNameInResourceName = true
165
156
}
157
+ // To avoid the stale in notifyList becomes empty slice.
158
+ // Don't skip resource name that has been deleted here.
159
+ // It would be filtered out in respond because the corresponding resource has been deleted.
160
+ notifyList [watch ] = append (notifyList [watch ], resourceName )
161
+ }
162
+ if ! modifiedNameInResourceName {
163
+ notifyList [watch ] = append (notifyList [watch ], name )
166
164
}
167
- delete (cache .watches , deletedName )
168
165
}
166
+ delete (cache .watches , name )
169
167
}
170
168
171
169
for value , stale := range notifyList {
@@ -189,31 +187,6 @@ func (cache *LinearCache) notifyAll(modified map[string]struct{}, fromDeletion b
189
187
}
190
188
}
191
189
192
- func (cache * LinearCache ) notifyAllFromDeletion (modified map [string ]struct {}) {
193
- notifyList := make (map [chan Response ][]string )
194
- for deletedName := range modified {
195
- for watch , streamState := range cache .watches [deletedName ] {
196
- names := streamState .GetKnownResourceNames (cache .typeURL )
197
- for name := range names {
198
- if name == deletedName {
199
- // skip the resource name has been deleted.
200
- continue
201
- }
202
- notifyList [watch ] = append (notifyList [watch ], name )
203
- }
204
- }
205
- delete (cache .watches , deletedName )
206
- }
207
-
208
- for value , stale := range notifyList {
209
- cache .respond (value , stale )
210
- }
211
-
212
- for value := range cache .watchAll {
213
- cache .respond (value , nil )
214
- }
215
- }
216
-
217
190
func (cache * LinearCache ) respondDelta (request * DeltaRequest , value chan DeltaResponse , state stream.StreamState ) * RawDeltaResponse {
218
191
resp := createDeltaResponse (context .Background (), request , state , resourceContainer {
219
192
resourceMap : cache .resources ,
@@ -246,7 +219,7 @@ func (cache *LinearCache) UpdateResource(name string, res types.Resource) error
246
219
cache .resources [name ] = res
247
220
248
221
// TODO: batch watch closures to prevent rapid updates
249
- cache .notifyAll (map [string ]struct {}{name : {}}, false )
222
+ cache .notifyAll (map [string ]struct {}{name : {}})
250
223
251
224
return nil
252
225
}
@@ -261,7 +234,7 @@ func (cache *LinearCache) DeleteResource(name string) error {
261
234
delete (cache .resources , name )
262
235
263
236
// TODO: batch watch closures to prevent rapid updates
264
- cache .notifyAll (map [string ]struct {}{name : {}}, true )
237
+ cache .notifyAll (map [string ]struct {}{name : {}})
265
238
return nil
266
239
}
267
240
@@ -293,7 +266,7 @@ func (cache *LinearCache) SetResources(resources map[string]types.Resource) {
293
266
modified [name ] = struct {}{}
294
267
}
295
268
296
- cache .notifyAll (modified , false )
269
+ cache .notifyAll (modified )
297
270
}
298
271
299
272
// GetResources returns current resources stored in the cache
@@ -346,7 +319,10 @@ func (cache *LinearCache) CreateWatch(request *Request, streamState stream.Strea
346
319
// When a resource is removed, its version defaults 0 and it is not considered stale.
347
320
if lastVersion < version || (! has && exists ) {
348
321
stale = true
349
- staleResources = append (staleResources , name )
322
+
323
+ // Here we collect all requested names.
324
+ // It would be filtered out in respond if the resource name doesn't appear in cache.
325
+ staleResources = request .ResourceNames
350
326
}
351
327
}
352
328
}
0 commit comments