use of com.evolveum.midpoint.repo.sql.RestartOperationRequestedException in project midpoint by Evolveum.
the class ExtItemDictionary method createOrFindItemByDefinitionInternal.
@Contract("_, _, true -> !null")
private RExtItem createOrFindItemByDefinitionInternal(@NotNull ItemDefinition<?> definition, boolean create, boolean throwExceptionAfterCreate) {
boolean fetchedNow = fetchItemsIfNeeded();
RExtItem.Key key = RExtItem.createKeyFromDefinition(definition);
RExtItem item = itemsByKey.get(key);
if (item == null && !fetchedNow) {
LOGGER.debug("Ext item for {} not found, fetching all items.", key);
fetchItems();
item = itemsByKey.get(key);
}
if (item == null && create) {
LOGGER.debug("Ext item for {} not found even in current items; creating it.", key);
item = RExtItem.createFromDefinition(definition);
addExtItemAttempt(item);
if (throwExceptionAfterCreate) {
throw new RestartOperationRequestedException("Restarting parent operation because an extension item was created");
}
}
return item;
}
use of com.evolveum.midpoint.repo.sql.RestartOperationRequestedException in project midpoint by Evolveum.
the class BaseHelper method logOperationAttempt.
public int logOperationAttempt(String oid, String operation, int attempt, @NotNull RuntimeException ex, OperationResult result) {
if (ex instanceof RestartOperationRequestedException) {
// This is a special case: we would like to restart
}
if (!isExceptionRelatedToSerialization(ex)) {
// to be sure that we won't miss anything related to deadlocks, here is an ugly hack that checks it (with some probability...)
boolean serializationTextFound = ex.getMessage() != null && (exceptionContainsText(ex, "deadlock") || exceptionContainsText(ex, "could not serialize access"));
if (serializationTextFound) {
LOGGER.error("Transaction serialization-related problem (e.g. deadlock) was probably not caught correctly!", ex);
}
throw ex;
}
BackoffComputer backoffComputer = new ExponentialBackoffComputer(LOCKING_MAX_RETRIES, LOCKING_DELAY_INTERVAL_BASE, LOCKING_EXP_THRESHOLD, null);
long waitTime;
try {
waitTime = backoffComputer.computeDelay(attempt);
} catch (BackoffComputer.NoMoreRetriesException e) {
CONTENTION_LOGGER.error("A serialization-related problem occurred, maximum attempts ({}) reached.", attempt, ex);
LOGGER.error("A serialization-related problem occurred, maximum attempts ({}) reached.", attempt, ex);
if (result != null) {
result.recordFatalError("A serialization-related problem occurred.", ex);
}
throw new SystemException(ex.getMessage() + " [attempts: " + attempt + "]", ex);
}
String message = "A serialization-related problem occurred when {} object with oid '{}', retrying after " + "{} ms (this is retry {} of {})\n{}: {}";
Object[] objects = { operation, oid, waitTime, attempt, LOCKING_MAX_RETRIES, ex.getClass().getSimpleName(), ex.getMessage() };
if (attempt >= SqlRepositoryServiceImpl.CONTENTION_LOG_DEBUG_THRESHOLD) {
CONTENTION_LOGGER.debug(message, objects);
} else {
CONTENTION_LOGGER.trace(message, objects);
}
if (attempt >= SqlRepositoryServiceImpl.MAIN_LOG_WARN_THRESHOLD) {
LOGGER.warn(message, objects);
} else {
LOGGER.debug(message, objects);
}
if (waitTime > 0) {
try {
Thread.sleep(waitTime);
} catch (InterruptedException ex1) {
// ignore this
}
}
return attempt + 1;
}
Aggregations