Search in sources :

Example 21 with OplogOperation

use of com.eightkdata.mongowp.server.api.oplog.OplogOperation 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)

Example 22 with OplogOperation

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

the class ContinuousOplogFetcherTest method testShortOplog.

@Test
public void testShortOplog() throws Exception {
    int oplogSize = 2;
    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 23 with OplogOperation

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

the class StaticOplogReader method getBetweenIterator.

private Iterator<OplogOperation> getBetweenIterator(OpTime from, boolean includeFrom, OpTime to, boolean includeTo) {
    OpTime includedFrom;
    OpTime excludedTo;
    if (includeFrom || !oplog.containsKey(from)) {
        includedFrom = from;
    } else {
        //_from_ is excluded, but subMap includes it!
        SortedMap<OpTime, OplogOperation> tailMap = oplog.tailMap(from);
        if (tailMap.size() > 1) {
            includedFrom = tailMap.keySet().iterator().next();
        } else {
            //the _from_ key is the only key greater or equal than _from_ and we want to exclude it
            return Collections.emptyIterator();
        }
    }
    Iterator<OplogOperation> excludingIt = oplog.subMap(includedFrom, to).values().iterator();
    if (includeTo) {
        OplogOperation toOp = oplog.get(to);
        if (toOp != null) {
            return Iterators.concat(excludingIt, Collections.singleton(toOp).iterator());
        }
    }
    return excludingIt;
}
Also used : OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) OpTime(com.eightkdata.mongowp.OpTime)

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