From 1888bab781a22518af848cb20e9727bda51059e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 21 Feb 2024 10:22:21 +0100 Subject: [PATCH 1/2] improve: primary to secondary index edge case for dynamic mapper changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../informer/DefaultPrimaryToSecondaryIndex.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java index 113deef767..4b226d670a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java @@ -33,9 +33,13 @@ public synchronized void onDelete(R resource) { primaryResources.forEach( primaryResource -> { var secondaryResources = index.get(primaryResource); - secondaryResources.remove(ResourceID.fromResource(resource)); - if (secondaryResources.isEmpty()) { - index.remove(primaryResource); + // this can be null in just very special cases, like when the secondaryToPrimaryMapper is + // changing dynamically + if (secondaryResources != null) { + secondaryResources.remove(ResourceID.fromResource(resource)); + if (secondaryResources.isEmpty()) { + index.remove(primaryResource); + } } }); } From 7e44bee8780dbf174a914ea2e1c363390f8f6025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 27 Feb 2024 15:41:25 +0100 Subject: [PATCH 2/2] docs improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../event/source/informer/DefaultPrimaryToSecondaryIndex.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java index 4b226d670a..a1a5a96d36 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java @@ -34,7 +34,8 @@ public synchronized void onDelete(R resource) { primaryResource -> { var secondaryResources = index.get(primaryResource); // this can be null in just very special cases, like when the secondaryToPrimaryMapper is - // changing dynamically + // changing dynamically. Like if a list of ResourceIDs mapped dynamically extended in the + // mapper between the onAddOrUpdate and onDelete is called. if (secondaryResources != null) { secondaryResources.remove(ResourceID.fromResource(resource)); if (secondaryResources.isEmpty()) {