use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method modifyObjectDynamically.
@NotNull
@Override
@Experimental
public <T extends ObjectType> ModifyObjectResult<T> modifyObjectDynamically(@NotNull Class<T> type, @NotNull String oid, @Nullable Collection<SelectorOptions<GetOperationOptions>> getOptions, @NotNull ModificationsSupplier<T> modificationsSupplier, RepoModifyOptions modifyOptions, @NotNull OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
Validate.notNull(type, "Object class in delta must not be null.");
Validate.notEmpty(oid, "Oid must not null or empty.");
Validate.notNull(modificationsSupplier, "Modifications supplier must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
// TODO executeAttempts?
final String operation = "modifying";
int attempt = 1;
int restarts = 0;
boolean noFetchExtensionValueInsertionForbidden = false;
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(OP_MODIFY_OBJECT_DYNAMICALLY, type);
OperationResult result = parentResult.subresult(MODIFY_OBJECT_DYNAMICALLY).addQualifier(type.getSimpleName()).addParam("type", type.getName()).addParam("oid", oid).build();
ModifyObjectResult<T> rv = null;
try {
while (true) {
try {
ModificationsSupplier<T> innerModificationsSupplier = object -> {
Collection<? extends ItemDelta<?, ?>> modifications = modificationsSupplier.get(object);
checkModifications(modifications);
logNameChange(modifications);
return modifications;
};
rv = objectUpdater.modifyObjectDynamicallyAttempt(type, oid, getOptions, innerModificationsSupplier, modifyOptions, attempt, result, this, noFetchExtensionValueInsertionForbidden);
invokeConflictWatchers((w) -> w.afterModifyObject(oid));
rv.setPerformanceRecord(pm.registerOperationFinish(opHandle, attempt));
return rv;
} catch (RestartOperationRequestedException ex) {
// special case: we want to restart but we do not want to count these
LOGGER.trace("Restarting because of {}", ex.getMessage());
restarts++;
if (restarts > RESTART_LIMIT) {
throw new IllegalStateException("Too many operation restarts");
} else if (ex.isForbidNoFetchExtensionValueAddition()) {
noFetchExtensionValueInsertionForbidden = true;
}
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, result);
pm.registerOperationNewAttempt(opHandle, attempt);
}
}
} catch (Throwable t) {
LOGGER.debug("Got exception while processing dynamic modifications on {}:{}", type.getSimpleName(), oid, t);
pm.registerOperationFinish(opHandle, attempt);
throw t;
} finally {
OperationLogger.logModifyDynamically(type, oid, rv, modifyOptions, result);
}
}
use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method executeAttempts.
private <RV> RV executeAttempts(String oid, String operationName, Class<?> type, String operationVerb, OperationResult subResult, ResultSupplier<RV> supplier) throws ObjectNotFoundException, SchemaException {
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(operationName, type);
int attempt = 1;
try {
while (true) {
try {
return supplier.get();
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(oid, operationVerb, attempt, ex, subResult);
pm.registerOperationNewAttempt(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
}
}
use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method advanceSequence.
@Override
public long advanceSequence(String oid, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
Validate.notEmpty(oid, "Oid must not null or empty.");
Validate.notNull(parentResult, "Operation result must not be null.");
OperationResult result = parentResult.subresult(ADVANCE_SEQUENCE).addParam("oid", oid).build();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Advancing sequence {}", oid);
}
// TODO executeAttempts
int attempt = 1;
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(OP_ADVANCE_SEQUENCE, SequenceType.class);
try {
while (true) {
try {
return sequenceHelper.advanceSequenceAttempt(oid, result);
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(oid, "advanceSequence", attempt, ex, null);
pm.registerOperationNewAttempt(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
}
}
use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method executeQueryAttempts.
private <RV> RV executeQueryAttempts(ObjectQuery query, String operationName, Class<?> type, String operationVerb, OperationResult subResult, Supplier<RV> emptyQueryResultSupplier, ResultQueryBasedSupplier<RV> supplier) throws SchemaException {
if (query != null) {
query = simplify(query, subResult);
if (query == null) {
return emptyQueryResultSupplier.get();
}
}
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(operationName, type);
int attempt = 1;
try {
while (true) {
try {
return supplier.get(query);
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operationVerb, attempt, ex, subResult);
pm.registerOperationNewAttempt(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
}
}
use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method modifyObject.
@NotNull
@Override
public <T extends ObjectType> ModifyObjectResult<T> modifyObject(@NotNull Class<T> type, @NotNull String oid, @NotNull Collection<? extends ItemDelta<?, ?>> modifications, ModificationPrecondition<T> precondition, RepoModifyOptions options, @NotNull OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException, PreconditionViolationException {
Validate.notNull(modifications, "Modifications must not be null.");
Validate.notNull(type, "Object class in delta must not be null.");
Validate.notEmpty(oid, "Oid must not null or empty.");
Validate.notNull(result, "Operation result must not be null.");
OperationResult subResult = result.subresult(MODIFY_OBJECT).addQualifier(type.getSimpleName()).addParam("type", type.getName()).addParam("oid", oid).addArbitraryObjectCollectionAsParam("modifications", modifications).build();
if (modifications.isEmpty() && !RepoModifyOptions.isForceReindex(options)) {
LOGGER.debug("Modification list is empty, nothing was modified.");
subResult.recordStatus(OperationResultStatus.SUCCESS, "Modification list is empty, nothing was modified.");
return new ModifyObjectResult<>(modifications);
}
checkModifications(modifications);
logNameChange(modifications);
// TODO executeAttempts?
final String operation = "modifying";
int attempt = 1;
int restarts = 0;
boolean noFetchExtensionValueInsertionForbidden = false;
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(OP_MODIFY_OBJECT, type);
try {
while (true) {
try {
ModifyObjectResult<T> rv = objectUpdater.modifyObjectAttempt(type, oid, modifications, precondition, options, attempt, subResult, this, noFetchExtensionValueInsertionForbidden, null);
invokeConflictWatchers((w) -> w.afterModifyObject(oid));
rv.setPerformanceRecord(pm.registerOperationFinish(opHandle, attempt));
return rv;
} catch (RestartOperationRequestedException ex) {
// special case: we want to restart but we do not want to count these
LOGGER.trace("Restarting because of {}", ex.getMessage());
restarts++;
if (restarts > RESTART_LIMIT) {
throw new IllegalStateException("Too many operation restarts");
} else if (ex.isForbidNoFetchExtensionValueAddition()) {
noFetchExtensionValueInsertionForbidden = true;
}
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, subResult);
pm.registerOperationNewAttempt(opHandle, attempt);
}
}
} catch (Throwable t) {
LOGGER.debug("Got exception while processing modifications on {}:{}:\n{}", type.getSimpleName(), oid, DebugUtil.debugDump(modifications), t);
pm.registerOperationFinish(opHandle, attempt);
throw t;
} finally {
OperationLogger.logModify(type, oid, modifications, precondition, options, subResult);
}
}
Aggregations