Search in sources :

Example 1 with ResourceSupplierInternalException

use of com.mongodb.internal.operation.OperationHelper.ResourceSupplierInternalException in project mongo-java-driver by mongodb.

the class CommandOperationHelper method shouldAttemptToRetryWrite.

static boolean shouldAttemptToRetryWrite(final RetryState retryState, final Throwable attemptFailure) {
    Throwable failure = attemptFailure instanceof ResourceSupplierInternalException ? attemptFailure.getCause() : attemptFailure;
    boolean decision = false;
    MongoException exceptionRetryableRegardlessOfCommand = null;
    if (failure instanceof MongoConnectionPoolClearedException) {
        decision = true;
        exceptionRetryableRegardlessOfCommand = (MongoException) failure;
    }
    if (retryState.attachment(AttachmentKeys.retryableCommandFlag()).orElse(false)) {
        if (exceptionRetryableRegardlessOfCommand != null) {
            /* We are going to retry even if `retryableCommand` is false,
                 * but we add the retryable label only if `retryableCommand` is true. */
            exceptionRetryableRegardlessOfCommand.addLabel(RETRYABLE_WRITE_ERROR_LABEL);
        } else if (decideRetryableAndAddRetryableWriteErrorLabel(failure, retryState.attachment(AttachmentKeys.maxWireVersion()).orElse(null))) {
            decision = true;
        } else {
            logUnableToRetry(retryState.attachment(AttachmentKeys.commandDescriptionSupplier()).orElse(null), failure);
        }
    }
    return decision;
}
Also used : MongoException(com.mongodb.MongoException) ResourceSupplierInternalException(com.mongodb.internal.operation.OperationHelper.ResourceSupplierInternalException) MongoConnectionPoolClearedException(com.mongodb.MongoConnectionPoolClearedException)

Aggregations

MongoConnectionPoolClearedException (com.mongodb.MongoConnectionPoolClearedException)1 MongoException (com.mongodb.MongoException)1 ResourceSupplierInternalException (com.mongodb.internal.operation.OperationHelper.ResourceSupplierInternalException)1