@@ -55,8 +55,9 @@ public class TemporaryResourceCache<T extends HasMetadata> {
5555 private static final Logger log = LoggerFactory .getLogger (TemporaryResourceCache .class );
5656
5757 private final Map <ResourceID , T > cache = new ConcurrentHashMap <>();
58- private final Map <ResourceID , EventFilterDetails > activeUpdates = new HashMap <>();
58+ private final Map <ResourceID , EventFilterDetails > cachingFilteringUpdates = new HashMap <>();
5959 private final boolean comparableResourceVersions ;
60+ private boolean informerOngoingRelist = false ;
6061
6162 private final ManagedInformerEventSource <T , ?, ?> managedInformerEventSource ;
6263
@@ -71,26 +72,22 @@ public synchronized void startEventFilteringModify(ResourceID resourceID) {
7172 if (!comparableResourceVersions ) {
7273 return ;
7374 }
74- var ed = activeUpdates .computeIfAbsent (resourceID , id -> new EventFilterDetails ());
75+ var ed =
76+ cachingFilteringUpdates .computeIfAbsent (
77+ resourceID , id -> new EventFilterDetails (informerOngoingRelist ));
7578 ed .increaseActiveUpdates ();
7679 }
7780
7881 public synchronized Optional <GenericResourceEvent > doneEventFilterModify (ResourceID resourceID ) {
7982 if (!comparableResourceVersions ) {
8083 return Optional .empty ();
8184 }
82- var ed = activeUpdates .get (resourceID );
85+ var ed = cachingFilteringUpdates .get (resourceID );
8386 if (!ed .decreaseActiveUpdates ()) {
8487 log .debug ("Active updates {} for resource id: {}" , ed .getActiveUpdates (), resourceID );
8588 return Optional .empty ();
8689 }
87-
88- if (ed .newerOrEqualEventReceivedForOwnLastUpdate ()) {
89- activeUpdates .remove (resourceID );
90- return ed .prepareSummaryEventIfNotOwnEventsPresent ();
91- } else {
92- return Optional .empty ();
93- }
90+ return finaleEventHandlingAndCleanup (resourceID , ed );
9491 }
9592
9693 public Optional <GenericResourceEvent > onDeleteEvent (T resource , boolean unknownState ) {
@@ -136,21 +133,20 @@ private synchronized Optional<GenericResourceEvent> onEvent(
136133 log .debug ("Received intermediate event." );
137134 }
138135 }
139- var au = activeUpdates .get (resourceId );
136+ var au = cachingFilteringUpdates .get (resourceId );
140137 if (au != null ) {
141138 log .debug ("Recording relevant event" );
142139 au .addRelatedEvent (
143140 new GenericResourceEvent (action , resource , prevResourceVersion , unknownState ));
144141 // this is to cover the situation when we finished the filtering and caching update but
145142 // did not receive events for our own updates yet.
146143 if (au .isNoActiveUpdate () && au .newerOrEqualEventReceivedForOwnLastUpdate ()) {
147- activeUpdates .remove (resourceId );
148- return au .prepareSummaryEventIfNotOwnEventsPresent ();
144+ return finaleEventHandlingAndCleanup (resourceId , au );
149145 }
150146 return Optional .empty ();
151147 } else {
152148 log .debug ("No active recording, event handling: {}" , result );
153- return result ;
149+ return informerOngoingRelist ? Optional . of ( actualEvent ) : result ;
154150 }
155151 }
156152
@@ -206,7 +202,7 @@ public synchronized void putResource(T newResource) {
206202
207203 // also make sure that we're later than the existing temporary entry
208204 var cachedResource = getResourceFromCache (resourceId ).orElse (null );
209- Optional .ofNullable (activeUpdates .get (resourceId ))
205+ Optional .ofNullable (cachingFilteringUpdates .get (resourceId ))
210206 .ifPresent (
211207 au -> au .addToOwnResourceVersions (newResource .getMetadata ().getResourceVersion ()));
212208
@@ -264,6 +260,20 @@ public void checkGhostResources() {
264260 }
265261 }
266262
263+ private Optional <GenericResourceEvent > finaleEventHandlingAndCleanup (
264+ ResourceID resourceID , EventFilterDetails ed ) {
265+ if (ed .newerOrEqualEventReceivedForOwnLastUpdate ()) {
266+ cachingFilteringUpdates .remove (resourceID );
267+ if (ed .isAffectedByReList ()) {
268+ return ed .summaryEventForReList ();
269+ } else {
270+ return ed .summaryEvent ();
271+ }
272+ } else {
273+ return Optional .empty ();
274+ }
275+ }
276+
267277 public synchronized Optional <T > getResourceFromCache (ResourceID resourceID ) {
268278 return Optional .ofNullable (cache .get (resourceID ));
269279 }
@@ -275,4 +285,13 @@ synchronized boolean isEmpty() {
275285 synchronized Map <ResourceID , T > getResources () {
276286 return Collections .unmodifiableMap (cache );
277287 }
288+
289+ public synchronized void setOngoingRelist () {
290+ this .informerOngoingRelist = true ;
291+ cachingFilteringUpdates .values ().forEach (EventFilterDetails ::affectedByReList );
292+ }
293+
294+ public synchronized void setRelistFinished () {
295+ this .informerOngoingRelist = false ;
296+ }
278297}
0 commit comments