Search in sources :

Example 1 with BackoffComputer

use of com.evolveum.midpoint.util.backoff.BackoffComputer 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)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