Search in sources :

Example 1 with RestartOperationRequestedException

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;
}
Also used : RExtItem(com.evolveum.midpoint.repo.sql.data.common.any.RExtItem) RestartOperationRequestedException(com.evolveum.midpoint.repo.sql.RestartOperationRequestedException) Contract(org.jetbrains.annotations.Contract)

Example 2 with RestartOperationRequestedException

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;
}
Also used : ExponentialBackoffComputer(com.evolveum.midpoint.util.backoff.ExponentialBackoffComputer) SystemException(com.evolveum.midpoint.util.exception.SystemException) BackoffComputer(com.evolveum.midpoint.util.backoff.BackoffComputer) ExponentialBackoffComputer(com.evolveum.midpoint.util.backoff.ExponentialBackoffComputer) RestartOperationRequestedException(com.evolveum.midpoint.repo.sql.RestartOperationRequestedException)

Aggregations

RestartOperationRequestedException (com.evolveum.midpoint.repo.sql.RestartOperationRequestedException)2 RExtItem (com.evolveum.midpoint.repo.sql.data.common.any.RExtItem)1 BackoffComputer (com.evolveum.midpoint.util.backoff.BackoffComputer)1 ExponentialBackoffComputer (com.evolveum.midpoint.util.backoff.ExponentialBackoffComputer)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 Contract (org.jetbrains.annotations.Contract)1