From 004f419fd042bbb12cd50febc7a9400143e035c6 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Fri, 12 Apr 2024 12:07:15 +0200 Subject: [PATCH] Leave a tombstone after the deletion of a cache entry This captures the scenario of multiple deletion calls in the current session. Closes #28672 Signed-off-by: Alexander Schwartz --- .../InfinispanKeycloakTransaction.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java index 0eb3f22acd..df77c2f32b 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanKeycloakTransaction.java @@ -36,6 +36,21 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { private final static Logger log = Logger.getLogger(InfinispanKeycloakTransaction.class); + /** + * Tombstone to mark an entry as already removed for the current session. + */ + private static final CacheTask TOMBSTONE = new CacheTask() { + @Override + public void execute() { + // noop + } + + @Override + public String toString() { + return "Tombstone after removal"; + } + }; + public enum CacheOperation { ADD, ADD_WITH_LIFESPAN, REMOVE, REPLACE, ADD_IF_ABSENT // ADD_IF_ABSENT throws an exception if there is existing value } @@ -205,7 +220,10 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction { CacheTask current = tasks.get(taskKey); if (current != null) { if (current instanceof CacheTaskWithValue && ((CacheTaskWithValue) current).getOperation() == Operation.PUT) { - tasks.remove(taskKey); + tasks.put(taskKey, TOMBSTONE); + return; + } + if (current == TOMBSTONE) { return; } }