Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ private synchronized void onAddOrUpdate(
}

private boolean canSkipEvent(R newObject, R oldObject, ResourceID resourceID) {
if (temporaryResourceCache.isKnownResourceVersion(newObject)) {
return true;
}
var res = temporaryResourceCache.getResourceFromCache(resourceID);
if (res.isEmpty()) {
return isEventKnownFromAnnotation(newObject, oldObject);
Expand All @@ -208,7 +205,8 @@ private boolean canSkipEvent(R newObject, R oldObject, ResourceID resourceID) {
"Resource found in temporal cache for id: {} resource versions equal: {}",
resourceID,
resVersionsEqual);
return resVersionsEqual;
return resVersionsEqual
|| temporaryResourceCache.isLaterResourceVersion(resourceID, res.get(), newObject);
}

private boolean isEventKnownFromAnnotation(R newObject, R oldObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,12 @@ void clean() {
private final ExpirationCache<String> tombstones = new ExpirationCache<>(1000000, 1200000);
private final ManagedInformerEventSource<T, ?, ?> managedInformerEventSource;
private final boolean parseResourceVersions;
private final ExpirationCache<String> knownResourceVersions;

public TemporaryResourceCache(
ManagedInformerEventSource<T, ?, ?> managedInformerEventSource,
boolean parseResourceVersions) {
this.managedInformerEventSource = managedInformerEventSource;
this.parseResourceVersions = parseResourceVersions;
if (parseResourceVersions) {
// keep up to the 50000 add/updates for up to 5 minutes
knownResourceVersions = new ExpirationCache<>(50000, 600000);
} else {
knownResourceVersions = null;
}
}

public synchronized void onDeleteEvent(T resource, boolean unknownState) {
Expand Down Expand Up @@ -122,9 +115,6 @@ public synchronized void putAddedResource(T newResource) {
* @param previousResourceVersion null indicates an add
*/
public synchronized void putResource(T newResource, String previousResourceVersion) {
if (knownResourceVersions != null) {
knownResourceVersions.add(newResource.getMetadata().getResourceVersion());
}
var resourceId = ResourceID.fromResource(newResource);
var cachedResource = managedInformerEventSource.get(resourceId).orElse(null);

Expand Down Expand Up @@ -159,17 +149,12 @@ public synchronized void putResource(T newResource, String previousResourceVersi
}
}

public synchronized boolean isKnownResourceVersion(T resource) {
return knownResourceVersions != null
&& knownResourceVersions.contains(resource.getMetadata().getResourceVersion());
}

/**
* @return true if {@link ConfigurationService#parseResourceVersionsForEventFilteringAndCaching()}
* is enabled and the resourceVersion of newResource is numerically greater than
* cachedResource, otherwise false
*/
private boolean isLaterResourceVersion(ResourceID resourceId, T newResource, T cachedResource) {
public boolean isLaterResourceVersion(ResourceID resourceId, T newResource, T cachedResource) {
try {
if (parseResourceVersions
&& Long.parseLong(newResource.getMetadata().getResourceVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ void removesResourceFromCache() {
void resourceVersionParsing() {
this.temporaryResourceCache = new TemporaryResourceCache<>(informerEventSource, true);

assertThat(temporaryResourceCache.isKnownResourceVersion(testResource())).isFalse();

ConfigMap testResource = propagateTestResourceToCache();

// an event with a newer version will not remove
Expand All @@ -108,7 +106,6 @@ void resourceVersionParsing() {
.endMetadata()
.build());

assertThat(temporaryResourceCache.isKnownResourceVersion(testResource)).isTrue();
assertThat(temporaryResourceCache.getResourceFromCache(ResourceID.fromResource(testResource)))
.isPresent();

Expand Down