Search in sources :

Example 11 with ApplierContext

use of com.torodb.mongodb.repl.oplogreplier.ApplierContext in project torodb by torodb.

the class SimpleAnalyzedOplogBatchExecutorTest method testVisit_SingleOp_UserEx.

@Test
public void testVisit_SingleOp_UserEx() throws Exception {
    //GIVEN
    OplogOperation operation = mock(OplogOperation.class);
    SingleOpAnalyzedOplogBatch batch = new SingleOpAnalyzedOplogBatch(operation);
    ApplierContext applierContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    Timer timer = mock(Timer.class);
    Context context = mock(Context.class);
    given(metrics.getSingleOpTimer(operation)).willReturn(timer);
    given(timer.time()).willReturn(context);
    doThrow(new DatabaseNotFoundException("test")).when(executor).execute(operation, applierContext);
    //WHEN
    try {
        executor.visit(batch, applierContext);
        fail("An exception was expected");
    } catch (RetrierGiveUpException | RetrierAbortException ignore) {
    }
    //THEN
    then(metrics).should().getSingleOpTimer(operation);
    then(timer).should().time();
    then(executor).should(times(1)).execute(operation, applierContext);
}
Also used : ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Context(com.codahale.metrics.Timer.Context) Timer(com.codahale.metrics.Timer) RetrierAbortException(com.torodb.core.retrier.RetrierAbortException) DatabaseNotFoundException(com.torodb.core.exceptions.user.DatabaseNotFoundException) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) RetrierGiveUpException(com.torodb.core.retrier.RetrierGiveUpException) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Test(org.junit.Test)

Example 12 with ApplierContext

use of com.torodb.mongodb.repl.oplogreplier.ApplierContext 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)

Example 13 with ApplierContext

use of com.torodb.mongodb.repl.oplogreplier.ApplierContext in project torodb by torodb.

the class SimpleAnalyzedOplogBatchExecutorTest method testExecute_OplogOperation.

@Test
public void testExecute_OplogOperation() throws Exception {
    //GIVEN
    OplogOperation op = mock(OplogOperation.class);
    ApplierContext applierContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    //WHEN
    executor.execute(op, applierContext);
    //THEN
    then(server).should().openConnection();
    then(conn).should().close();
    then(conn).should().openExclusiveWriteTransaction();
    then(writeTrans).should().close();
    then(applier).should().apply(op, writeTrans, applierContext);
}
Also used : OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Test(org.junit.Test)

Aggregations

ApplierContext (com.torodb.mongodb.repl.oplogreplier.ApplierContext)13 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)10 Context (com.codahale.metrics.Timer.Context)9 Test (org.junit.Test)9 Timer (com.codahale.metrics.Timer)7 RetrierGiveUpException (com.torodb.core.retrier.RetrierGiveUpException)6 RetrierAbortException (com.torodb.core.retrier.RetrierAbortException)4 RollbackException (com.torodb.core.transaction.RollbackException)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 DatabaseNotFoundException (com.torodb.core.exceptions.user.DatabaseNotFoundException)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 Answer (org.mockito.stubbing.Answer)2 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1 OpTime (com.eightkdata.mongowp.OpTime)1 MongoException (com.eightkdata.mongowp.exceptions.MongoException)1 OplogStartMissingException (com.eightkdata.mongowp.exceptions.OplogStartMissingException)1 UserException (com.torodb.core.exceptions.user.UserException)1 ReadOplogTransaction (com.torodb.mongodb.repl.OplogManager.ReadOplogTransaction)1 UnexpectedOplogApplierException (com.torodb.mongodb.repl.oplogreplier.OplogApplier.UnexpectedOplogApplierException)1