Skip to content

Commit

Permalink
Fix cluster-wide cache clearance (MID-6440)
Browse files Browse the repository at this point in the history
(cherry picked from commit f8fbbfa)
  • Loading branch information
mederly committed Sep 16, 2020
1 parent d344f1d commit 9511e22
Showing 1 changed file with 27 additions and 3 deletions.
Expand Up @@ -6,6 +6,15 @@
*/
package com.evolveum.midpoint.model.impl;

import javax.annotation.PostConstruct;
import javax.ws.rs.core.Response;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.CacheInvalidationContext;
import com.evolveum.midpoint.TerminateSessionEvent;
import com.evolveum.midpoint.model.impl.security.NodeAuthenticationToken;
Expand Down Expand Up @@ -58,9 +67,8 @@ public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean

// Regular cache invalidation can be skipped for nodes not checking in. Cache entries will expire on such nodes
// eventually. (We can revisit this design decision if needed.)
clusterExecutionHelper.execute((client, result1) -> {
client.path(ClusterRestService.EVENT_INVALIDATION +
ObjectTypes.getRestTypeFromClass(type) + (oid != null ? "/" + oid : ""));
clusterExecutionHelper.execute((client, node, result1) -> {
client.path(getInvalidationRestPath(type, oid));
Response response = client.post(null);
Response.StatusType statusInfo = response.getStatusInfo();
if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
Expand All @@ -74,6 +82,22 @@ public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean
}, null, "cache invalidation", result);
}

@NotNull
private <O extends ObjectType> String getInvalidationRestPath(Class<O> type, String oid) {
StringBuilder sb = new StringBuilder(ClusterServiceConsts.EVENT_INVALIDATION);
if (type != null) {
sb.append(ObjectTypes.getRestTypeFromClass(type));
if (oid != null) {
sb.append("/").append(oid);
}
} else {
if (oid != null) {
LOGGER.warn("Cannot invalidate object type null with specific OID. Converting to global invalidation (type=null, oid=null).");
}
}
return sb.toString();
}

private <O extends ObjectType> boolean canExecute(Class<O> type, String oid, boolean clusterwide, CacheInvalidationContext context) {
if (!clusterwide) {
LOGGER.trace("Ignoring invalidate() call for type {} (oid={}) because clusterwide=false", type, oid);
Expand Down

0 comments on commit 9511e22

Please sign in to comment.