Search in sources :

Example 1 with QueryKey

use of com.evolveum.midpoint.repo.cache.local.QueryKey in project midpoint by Evolveum.

the class GlobalQueryCache method dumpContent.

public void dumpContent() {
    if (cache != null && LOGGER_CONTENT.isInfoEnabled()) {
        cache.invokeAll(cache.keys(), e -> {
            QueryKey key = e.getKey();
            GlobalCacheQueryValue<?> value = e.getValue();
            @NotNull SearchResultList<?> queryResult = value.getResult();
            LOGGER_CONTENT.info("Cached query of {} ({} object(s), cached {} ms ago): {}: {}", key.getType().getSimpleName(), queryResult.size(), value.getAge(), key.getQuery(), queryResult);
            return null;
        });
    }
}
Also used : QueryKey(com.evolveum.midpoint.repo.cache.local.QueryKey) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with QueryKey

use of com.evolveum.midpoint.repo.cache.local.QueryKey in project midpoint by Evolveum.

the class GlobalQueryCache method getStateInformation.

public Collection<SingleCacheStateInformationType> getStateInformation() {
    Map<Class<?>, MutablePair<Integer, Integer>> counts = new HashMap<>();
    AtomicInteger queries = new AtomicInteger(0);
    AtomicInteger objects = new AtomicInteger(0);
    if (cache != null) {
        cache.invokeAll(cache.keys(), e -> {
            QueryKey queryKey = e.getKey();
            Class<?> objectType = queryKey.getType();
            int resultingObjects = e.getValue().getResult().size();
            MutablePair<Integer, Integer> value = counts.get(objectType);
            if (value == null) {
                value = new MutablePair<>(0, 0);
                counts.put(objectType, value);
            }
            value.setLeft(value.getLeft() + 1);
            value.setRight(value.getRight() + resultingObjects);
            queries.incrementAndGet();
            objects.addAndGet(resultingObjects);
            return null;
        });
        SingleCacheStateInformationType info = new SingleCacheStateInformationType(prismContext).name(GlobalQueryCache.class.getName()).size(queries.get()).secondarySize(objects.get());
        counts.forEach((type, pair) -> info.beginComponent().name(type.getSimpleName()).size(pair.getLeft()).secondarySize(pair.getRight()));
        return Collections.singleton(info);
    } else {
        return Collections.emptySet();
    }
}
Also used : HashMap(java.util.HashMap) QueryKey(com.evolveum.midpoint.repo.cache.local.QueryKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MutablePair(org.apache.commons.lang3.tuple.MutablePair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)

Example 3 with QueryKey

use of com.evolveum.midpoint.repo.cache.local.QueryKey in project midpoint by Evolveum.

the class Invalidator method clearQueryResultsGlobally.

private <T extends ObjectType> void clearQueryResultsGlobally(Class<T> type, String oid, CacheInvalidationContext context) {
    // TODO implement more efficiently
    // Safe invalidation means we evict queries without looking at details of the change.
    boolean safeIfUnknown = !context.isFromRemoteNode() || globalQueryCache.shouldDoSafeRemoteInvalidationFor(type);
    ChangeDescription change = ChangeDescription.getFrom(type, oid, context, safeIfUnknown);
    long start = System.currentTimeMillis();
    AtomicInteger all = new AtomicInteger(0);
    AtomicInteger removed = new AtomicInteger(0);
    globalQueryCache.deleteMatching(entry -> {
        QueryKey queryKey = entry.getKey();
        all.incrementAndGet();
        if (change.mayAffect(queryKey, entry.getValue().getResult(), matchingRuleRegistry)) {
            LOGGER.trace("Removing (from global cache) query for type={}, change={}: {}", type, change, queryKey.getQuery());
            removed.incrementAndGet();
            return true;
        } else {
            return false;
        }
    });
    LOGGER.trace("Removed (from global cache) {} (of {}) query result entries of type {} in {} ms", removed, all, type, System.currentTimeMillis() - start);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryKey(com.evolveum.midpoint.repo.cache.local.QueryKey)

Aggregations

QueryKey (com.evolveum.midpoint.repo.cache.local.QueryKey)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SingleCacheStateInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)1 HashMap (java.util.HashMap)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 NotNull (org.jetbrains.annotations.NotNull)1