Search in sources :

Example 11 with RetrierGiveUpException

use of com.torodb.core.retrier.RetrierGiveUpException in project torodb by torodb.

the class SimpleAnalyzedOplogBatchExecutor method visit.

@Override
public OplogOperation visit(CudAnalyzedOplogBatch batch, ApplierContext arg) throws RetrierGiveUpException {
    metrics.getCudBatchSize().update(batch.getOriginalBatch().size());
    try (Context context = metrics.getCudBatchTimer().time()) {
        try {
            execute(batch, arg);
        } catch (UserException | NamespaceJobExecutionException ex) {
            throw new RetrierGiveUpException("Unexpected exception while replying", ex);
        } catch (RollbackException ex) {
            ApplierContext retryingReplingContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
            retrier.retry(() -> {
                try {
                    execute(batch, retryingReplingContext);
                    return Empty.getInstance();
                } catch (UserException | NamespaceJobExecutionException ex2) {
                    throw new RetrierAbortException("Unexpected user exception while applying " + "the batch " + batch, ex2);
                }
            }, Hint.CRITICAL, Hint.TIME_SENSIBLE);
        }
    }
    List<OplogOperation> originalBatch = batch.getOriginalBatch();
    return originalBatch.get(originalBatch.size() - 1);
}
Also used : ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Context(com.codahale.metrics.Timer.Context) RetrierAbortException(com.torodb.core.retrier.RetrierAbortException) UserException(com.torodb.core.exceptions.user.UserException) RetrierGiveUpException(com.torodb.core.retrier.RetrierGiveUpException) RollbackException(com.torodb.core.transaction.RollbackException) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext)

Aggregations

RetrierGiveUpException (com.torodb.core.retrier.RetrierGiveUpException)11 RetrierAbortException (com.torodb.core.retrier.RetrierAbortException)8 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)7 Timer (com.codahale.metrics.Timer)6 Context (com.codahale.metrics.Timer.Context)6 ApplierContext (com.torodb.mongodb.repl.oplogreplier.ApplierContext)6 MongoException (com.eightkdata.mongowp.exceptions.MongoException)4 RollbackException (com.torodb.core.transaction.RollbackException)4 UserException (com.torodb.core.exceptions.user.UserException)3 WriteMongodTransaction (com.torodb.mongodb.core.WriteMongodTransaction)3 Test (org.junit.Test)3 Request (com.eightkdata.mongowp.server.api.Request)2 BsonDocumentBuilder (com.eightkdata.mongowp.utils.BsonDocumentBuilder)2 DatabaseNotFoundException (com.torodb.core.exceptions.user.DatabaseNotFoundException)2 Locked (com.torodb.mongodb.annotations.Locked)2 ReadOnlyMongodTransaction (com.torodb.mongodb.core.ReadOnlyMongodTransaction)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 OpTime (com.eightkdata.mongowp.OpTime)1