Search in sources :

Example 6 with OplogOperation

use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.

the class ContinuousOplogFetcherTest method testOldOplog.

@Test(expected = RollbackReplicationException.class)
public void testOldOplog() throws Exception {
    int oplogSize = 2;
    List<OplogOperation> oplog = createInsertStream(this::createSimpleInsert).limit(oplogSize).collect(Collectors.toList());
    oplogSupplier = () -> oplog;
    OplogOperation lastOp = oplog.get(oplog.size() - 1);
    ContinuousOplogFetcher fetcher = factory.createFetcher(0, opTimeFactory.getNextOpTime(lastOp.getOpTime()));
    fetcher.fetch();
}
Also used : InsertOplogOperation(com.eightkdata.mongowp.server.api.oplog.InsertOplogOperation) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) Test(org.junit.Test)

Example 7 with OplogOperation

use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.

the class ContinuousOplogFetcherTest method testMediumOplog.

@Test
public void testMediumOplog() throws Exception {
    int oplogSize = 1000;
    List<OplogOperation> oplog = createInsertStream(this::createSimpleInsert).limit(oplogSize).collect(Collectors.toList());
    oplogSupplier = () -> oplog;
    OplogOperation firstOp = oplog.get(0);
    ContinuousOplogFetcher fetcher = factory.createFetcher(firstOp.getHash(), firstOp.getOpTime());
    List<OplogOperation> recivedOplog = new ArrayList<>(oplogSize);
    OplogBatch batch = null;
    while (batch == null || !(batch.isLastOne() || batch.isReadyForMore())) {
        batch = fetcher.fetch();
        recivedOplog.addAll(batch.getOps());
    }
    assertEquals("Unexpected number of oplog entries fetched: ", oplog.size() - 1, recivedOplog.size());
    assertEquals(oplog.subList(1, oplog.size()), recivedOplog);
}
Also used : OplogBatch(com.torodb.mongodb.repl.oplogreplier.OplogBatch) InsertOplogOperation(com.eightkdata.mongowp.server.api.oplog.InsertOplogOperation) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) Test(org.junit.Test)

Example 8 with OplogOperation

use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.

the class ContinuousOplogFetcherTest method testBigOplog.

@Test
public void testBigOplog() throws Exception {
    int oplogSize = 100000;
    List<OplogOperation> oplog = createInsertStream(this::createSimpleInsert).limit(oplogSize).collect(Collectors.toList());
    oplogSupplier = () -> oplog;
    OplogOperation firstOp = oplog.get(0);
    ContinuousOplogFetcher fetcher = factory.createFetcher(firstOp.getHash(), firstOp.getOpTime());
    List<OplogOperation> recivedOplog = new ArrayList<>(oplogSize);
    OplogBatch batch = null;
    while (batch == null || !(batch.isLastOne() || !batch.isReadyForMore())) {
        batch = fetcher.fetch();
        recivedOplog.addAll(batch.getOps());
    }
    assertEquals("Unexpected number of oplog entries fetched: ", oplog.size() - 1, recivedOplog.size());
    assertEquals(oplog.subList(1, oplog.size()), recivedOplog);
}
Also used : OplogBatch(com.torodb.mongodb.repl.oplogreplier.OplogBatch) InsertOplogOperation(com.eightkdata.mongowp.server.api.oplog.InsertOplogOperation) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) Test(org.junit.Test)

Example 9 with OplogOperation

use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.

the class OplogTestParser method getOps.

private static List<OplogOperation> getOps(BsonDocument doc) {
    BsonValue<?> oplogValue = doc.get("oplog");
    if (oplogValue == null) {
        throw new AssertionError("Does not contain oplog");
    }
    AtomicInteger tsFactory = new AtomicInteger();
    AtomicInteger tFactory = new AtomicInteger();
    BsonInt32 twoInt32 = DefaultBsonValues.newInt(2);
    return oplogValue.asArray().asList().stream().map(BsonValue::asDocument).map(child -> {
        BsonDocumentBuilder builder = new BsonDocumentBuilder(child);
        if (child.get("ts") == null) {
            builder.appendUnsafe("ts", DefaultBsonValues.newTimestamp(tsFactory.incrementAndGet(), tFactory.incrementAndGet()));
        }
        if (child.get("h") == null) {
            builder.appendUnsafe("h", DefaultBsonValues.INT32_ONE);
        }
        if (child.get("v") == null) {
            builder.appendUnsafe("v", twoInt32);
        }
        return builder.build();
    }).map(child -> {
        try {
            return OplogOperationParser.fromBson(child);
        } catch (MongoException ex) {
            throw new AssertionError("Invalid oplog operation", ex);
        }
    }).collect(Collectors.toList());
}
Also used : java.util(java.util) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) Truth(com.google.common.truth.Truth) KvValue(com.torodb.kvdocument.values.KvValue) BsonValue(com.eightkdata.mongowp.bson.BsonValue) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) MongoWpConverter(com.torodb.kvdocument.conversion.mongowp.MongoWpConverter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TorodTransaction(com.torodb.torod.TorodTransaction) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder) MongoException(com.eightkdata.mongowp.exceptions.MongoException) DefaultBsonValues(com.eightkdata.mongowp.bson.utils.DefaultBsonValues) MongoBsonTranslator(com.eightkdata.mongowp.bson.org.bson.utils.MongoBsonTranslator) OplogOperationParser(com.torodb.mongodb.commands.pojos.OplogOperationParser) Charsets(com.google.common.base.Charsets) Files(java.nio.file.Files) BsonInt32(com.eightkdata.mongowp.bson.BsonInt32) KvDocument(com.torodb.kvdocument.values.KvDocument) Collectors(java.util.stream.Collectors) WriteMongodTransaction(com.torodb.mongodb.core.WriteMongodTransaction) Stream(java.util.stream.Stream) java.io(java.io) Paths(java.nio.file.Paths) ReadOnlyMongodTransaction(com.torodb.mongodb.core.ReadOnlyMongodTransaction) Assert(org.junit.Assert) BsonInt32(com.eightkdata.mongowp.bson.BsonInt32) MongoException(com.eightkdata.mongowp.exceptions.MongoException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder)

Example 10 with OplogOperation

use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.

the class SimpleAnalyzedOplogBatchExecutorTest method testVisit_CudAnalyzedOplog_UserEx.

@Test
public void testVisit_CudAnalyzedOplog_UserEx() throws Exception {
    //GIVEN
    OplogOperation lastOp = mock(OplogOperation.class);
    CudAnalyzedOplogBatch batch = mock(CudAnalyzedOplogBatch.class);
    ApplierContext applierContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    given(batch.getOriginalBatch()).willReturn(Lists.newArrayList(mock(OplogOperation.class), mock(OplogOperation.class), mock(OplogOperation.class), lastOp));
    Timer timer = mock(Timer.class);
    Context context = mock(Context.class);
    given(metrics.getCudBatchTimer()).willReturn(timer);
    given(timer.time()).willReturn(context);
    doThrow(new DatabaseNotFoundException("test")).when(executor).execute(eq(batch), any());
    //WHEN
    try {
        executor.visit(batch, applierContext);
        fail("An exception was expected");
    } catch (RetrierGiveUpException | RetrierAbortException ignore) {
    }
    //THEN
    then(metrics).should().getCudBatchTimer();
    then(timer).should().time();
    then(executor).should(times(1)).execute(batch, 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)

Aggregations

OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)23 ApplierContext (com.torodb.mongodb.repl.oplogreplier.ApplierContext)10 Test (org.junit.Test)10 Context (com.codahale.metrics.Timer.Context)8 Timer (com.codahale.metrics.Timer)7 RetrierGiveUpException (com.torodb.core.retrier.RetrierGiveUpException)7 RollbackException (com.torodb.core.transaction.RollbackException)6 MongoException (com.eightkdata.mongowp.exceptions.MongoException)5 RetrierAbortException (com.torodb.core.retrier.RetrierAbortException)5 InsertOplogOperation (com.eightkdata.mongowp.server.api.oplog.InsertOplogOperation)4 OplogBatch (com.torodb.mongodb.repl.oplogreplier.OplogBatch)4 OpTime (com.eightkdata.mongowp.OpTime)3 UserException (com.torodb.core.exceptions.user.UserException)3 OplogManagerPersistException (com.torodb.mongodb.repl.OplogManager.OplogManagerPersistException)3 WriteOplogTransaction (com.torodb.mongodb.repl.OplogManager.WriteOplogTransaction)3 OplogStartMissingException (com.eightkdata.mongowp.exceptions.OplogStartMissingException)2 FinishedOplogBatch (com.torodb.mongodb.repl.oplogreplier.FinishedOplogBatch)2 NormalOplogBatch (com.torodb.mongodb.repl.oplogreplier.NormalOplogBatch)2 NotReadyForMoreOplogBatch (com.torodb.mongodb.repl.oplogreplier.NotReadyForMoreOplogBatch)2 OplogFetcher (com.torodb.mongodb.repl.oplogreplier.fetcher.OplogFetcher)2