Search in sources :

Example 21 with HotRodClientException

use of org.infinispan.client.hotrod.exceptions.HotRodClientException in project keycloak by keycloak.

the class RemoteCacheInvoker method runTask.

public <K, V extends SessionEntity> void runTask(KeycloakSession kcSession, RealmModel realm, String cacheName, K key, MergedUpdate<V> task, SessionEntityWrapper<V> sessionWrapper) {
    RemoteCacheContext context = remoteCaches.get(cacheName);
    if (context == null) {
        return;
    }
    V session = sessionWrapper.getEntity();
    SessionUpdateTask.CacheOperation operation = task.getOperation(session);
    SessionUpdateTask.CrossDCMessageStatus status = task.getCrossDCMessageStatus(sessionWrapper);
    if (status == SessionUpdateTask.CrossDCMessageStatus.NOT_NEEDED) {
        if (logger.isTraceEnabled()) {
            logger.tracef("Skip writing to remoteCache for entity '%s' of cache '%s' and operation '%s'", key, cacheName, operation);
        }
        return;
    }
    long loadedMaxIdleTimeMs = context.maxIdleTimeLoader.getMaxIdleTimeMs(realm);
    // Increase the timeout to ensure that entry won't expire on remoteCache in case that write of some entities to remoteCache is postponed (eg. userSession.lastSessionRefresh)
    final long maxIdleTimeMs = loadedMaxIdleTimeMs + 1800000;
    if (logger.isTraceEnabled()) {
        logger.tracef("Running task '%s' on remote cache '%s' . Key is '%s'", operation, cacheName, key);
    }
    TopologyInfo topology = InfinispanUtil.getTopologyInfo(kcSession);
    Retry.executeWithBackoff((int iteration) -> {
        try {
            runOnRemoteCache(topology, context.remoteCache, maxIdleTimeMs, key, task, sessionWrapper);
        } catch (HotRodClientException re) {
            if (logger.isDebugEnabled()) {
                logger.debugf(re, "Failed running task '%s' on remote cache '%s' . Key: '%s', iteration '%s'. Will try to retry the task", operation, cacheName, key, iteration);
            }
            // Rethrow the exception. Retry will take care of handle the exception and eventually retry the operation.
            throw re;
        }
    }, 10, 10);
}
Also used : HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) SessionUpdateTask(org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask) TopologyInfo(org.keycloak.connections.infinispan.TopologyInfo)

Aggregations

HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)21 ActionTokenValueEntity (org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity)14 UUID (java.util.UUID)5 RemoteCache (org.infinispan.client.hotrod.RemoteCache)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Consumer (java.util.function.Consumer)2 OAuth2DeviceCodeModel (org.keycloak.models.OAuth2DeviceCodeModel)2 SessionUpdateTask (org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiFunction (java.util.function.BiFunction)1