Skip to content

Commit

Permalink
multithreaded CoD, switched from PointInTime.CURRENT to use staleness…
Browse files Browse the repository at this point in the history
…(0L) flag for the retry part
  • Loading branch information
1azyman committed Nov 23, 2022
1 parent 1b38d16 commit 8c52293
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext;
import com.evolveum.midpoint.repo.common.expression.ExpressionUtil;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;
import com.evolveum.midpoint.schema.cache.CacheType;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
Expand Down Expand Up @@ -414,7 +417,7 @@ private List<V> executeSearchAttempt(
extendOptions(options, searchOnResource);

if (createOnDemandRetry) {
options = GetOperationOptions.updateRootOptions(options, opt -> opt.pointInTimeType(PointInTimeType.CURRENT));
options = GetOperationOptions.updateRootOptions(options, opt -> opt.setStaleness(0L));
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public <F extends ObjectType> ModelContext<F> previewChanges(

TaskExecutionMode executionMode = task.getExecutionMode();
if (executionMode == null || TaskExecutionMode.PRODUCTION.equals(executionMode)) {
LOGGER.warn("Task {} has execution mode undefined or set to PRODUCTION when executing previewChanges, setting to SIMULATED_PRODUCTION", task.getName());

task.setExecutionMode(TaskExecutionMode.SIMULATED_PRODUCTION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

package com.evolveum.midpoint.repo.cache.handlers;

import static com.evolveum.midpoint.repo.cache.handlers.PassReason.PassReasonType.*;
import static com.evolveum.midpoint.schema.GetOperationOptions.createRetrieve;

import java.util.Collection;

import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RetrieveOption;
import com.evolveum.midpoint.schema.SelectorOptions;
Expand All @@ -15,14 +22,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

import org.jetbrains.annotations.Nullable;

import java.util.Collection;

import static com.evolveum.midpoint.repo.cache.handlers.PassReason.PassReasonType.*;
import static com.evolveum.midpoint.repo.cache.handlers.PassReason.PassReasonType.UNSUPPORTED_OPTION;
import static com.evolveum.midpoint.schema.GetOperationOptions.createRetrieve;

/**
* Reason why an operation request passes a cache.
*/
Expand All @@ -38,18 +37,34 @@ final class PassReason {
*/
private final String comment;

/**
* If soft equals true, we don't want to fully pass cache. Meaning, in this case we would like ignore content in cache,
* execute query and cache results (override existing if necessary) afterwards.
* <p/>
* If soft equals false, we'd like to fully pass cache.
*/
private final boolean soft;

enum PassReasonType {
NOT_CACHEABLE_TYPE, MULTIPLE_OPTIONS, NON_ROOT_OPTIONS, UNSUPPORTED_OPTION, INCLUDE_OPTION_PRESENT, ZERO_STALENESS_REQUESTED
}

private PassReason(PassReasonType type) {
this.type = type;
this.comment = null;
this(type, null);
}

private PassReason(PassReasonType type, String comment) {
this(type, comment, false);
}

private PassReason(PassReasonType type, String comment, boolean soft) {
this.type = type;
this.comment = comment;
this.soft = soft;
}

public boolean isSoft() {
return soft;
}

/**
Expand All @@ -75,7 +90,7 @@ static PassReason determine(Collection<SelectorOptions<GetOperationOptions>> opt
}
Long staleness = selectorOptions.getOptions().getStaleness();
if (staleness != null && staleness == 0) {
return new PassReason(ZERO_STALENESS_REQUESTED);
return new PassReason(ZERO_STALENESS_REQUESTED, null, true);
}
GetOperationOptions cloned = selectorOptions.getOptions().clone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import static com.evolveum.midpoint.schema.util.TraceUtil.isAtLeastMinimal;

import java.util.Collection;
import java.util.Objects;

import com.evolveum.midpoint.repo.cache.other.MonitoringUtil;

import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
Expand All @@ -27,6 +24,7 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.cache.RepositoryCache;
import com.evolveum.midpoint.repo.cache.local.QueryKey;
import com.evolveum.midpoint.repo.cache.other.MonitoringUtil;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -65,22 +63,21 @@ public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(Cla
try {
// Checks related to both caches
PassReason passReason = PassReason.determine(options, type);
if (passReason != null) {
if (passReason != null && !passReason.isSoft()) {
exec.reportLocalAndGlobalPass(passReason);
SearchResultList<PrismObject<T>> objects = searchObjectsInternal(type, query, options, exec.result);
return exec.prepareReturnValueAsIs(objects);
}
QueryKey<T> key = new QueryKey<>(type, query);

final GetOperationOptions rootOption = SelectorOptions.findRootOptions(options);
final boolean skipCaches = rootOption != null && Objects.equals(PointInTimeType.CURRENT, rootOption.getPointInTimeType());
final boolean softPass = passReason != null && passReason.isSoft();

// Let's try local cache
if (!exec.local.available) {
exec.reportLocalNotAvailable();
} else if (!exec.local.supports) {
exec.reportLocalPass();
} else if (!skipCaches) {
} else if (!softPass) {
SearchResultList<PrismObject<T>> cachedResult = exec.local.getCache().get(key);
if (cachedResult != null) {
exec.reportLocalHit();
Expand All @@ -101,7 +98,7 @@ public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(Cla
return exec.prepareReturnValueAsIs(objects);
}

if (!skipCaches) {
if (!softPass) {
SearchResultList<PrismObject<T>> cachedResult = globalQueryCache.get(key);

if (cachedResult != null) {
Expand Down

0 comments on commit 8c52293

Please sign in to comment.