Search in sources :

Example 1 with ReadOplogTransaction

use of com.torodb.mongodb.repl.OplogManager.ReadOplogTransaction in project torodb by torodb.

the class DefaultOplogApplierService method createFetcher.

private OplogFetcher createFetcher() {
    OpTime lastAppliedOptime;
    long lastAppliedHash;
    try (ReadOplogTransaction oplogReadTrans = oplogManager.createReadTransaction()) {
        lastAppliedOptime = oplogReadTrans.getLastAppliedOptime();
        lastAppliedHash = oplogReadTrans.getLastAppliedHash();
    }
    return replFilters.filterOplogFetcher(oplogFetcherFactory.createFetcher(lastAppliedHash, lastAppliedOptime));
}
Also used : ReadOplogTransaction(com.torodb.mongodb.repl.OplogManager.ReadOplogTransaction) OpTime(com.eightkdata.mongowp.OpTime)

Example 2 with ReadOplogTransaction

use of com.torodb.mongodb.repl.OplogManager.ReadOplogTransaction in project torodb by torodb.

the class RecoveryService method applyOplog.

/**
   * Applies all the oplog operations stored on the remote server whose optime is higher than
   * <em>from</em> but lower or equal than <em>to</em>.
   *
   * @param myOplog
   * @param remoteOplog
   * @param to
   * @param from
   */
private void applyOplog(OplogReader remoteOplog, OpTime from, OpTime to) throws TryAgainException, MongoException, FatalErrorException {
    MongoCursor<OplogOperation> oplogCursor = remoteOplog.between(from, true, to, true);
    if (!oplogCursor.hasNext()) {
        throw new OplogStartMissingException(remoteOplog.getSyncSource());
    }
    OplogOperation firstOp = oplogCursor.next();
    if (!firstOp.getOpTime().equals(from)) {
        throw new TryAgainException("Remote oplog does not cointain our last operation");
    }
    OplogFetcher fetcher = new LimitedOplogFetcher(oplogCursor);
    ApplierContext context = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    try {
        oplogApplier.apply(fetcher, context).waitUntilFinished();
    } catch (StopReplicationException | RollbackReplicationException | CancellationException | UnexpectedOplogApplierException ex) {
        throw new FatalErrorException(ex);
    }
    OpTime lastAppliedOptime;
    try (ReadOplogTransaction oplogTrans = oplogManager.createReadTransaction()) {
        lastAppliedOptime = oplogTrans.getLastAppliedOptime();
    }
    if (!lastAppliedOptime.equals(to)) {
        LOGGER.warn("Unexpected optime for last operation to apply. " + "Expected " + to + ", but " + lastAppliedOptime + " found");
    }
}
Also used : OplogFetcher(com.torodb.mongodb.repl.oplogreplier.fetcher.OplogFetcher) LimitedOplogFetcher(com.torodb.mongodb.repl.oplogreplier.fetcher.LimitedOplogFetcher) ReadOplogTransaction(com.torodb.mongodb.repl.OplogManager.ReadOplogTransaction) OplogStartMissingException(com.eightkdata.mongowp.exceptions.OplogStartMissingException) RollbackReplicationException(com.torodb.mongodb.repl.oplogreplier.RollbackReplicationException) OpTime(com.eightkdata.mongowp.OpTime) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) LimitedOplogFetcher(com.torodb.mongodb.repl.oplogreplier.fetcher.LimitedOplogFetcher) CancellationException(java.util.concurrent.CancellationException) UnexpectedOplogApplierException(com.torodb.mongodb.repl.oplogreplier.OplogApplier.UnexpectedOplogApplierException) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) StopReplicationException(com.torodb.mongodb.repl.oplogreplier.StopReplicationException)

Aggregations

OpTime (com.eightkdata.mongowp.OpTime)2 ReadOplogTransaction (com.torodb.mongodb.repl.OplogManager.ReadOplogTransaction)2 OplogStartMissingException (com.eightkdata.mongowp.exceptions.OplogStartMissingException)1 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)1 ApplierContext (com.torodb.mongodb.repl.oplogreplier.ApplierContext)1 UnexpectedOplogApplierException (com.torodb.mongodb.repl.oplogreplier.OplogApplier.UnexpectedOplogApplierException)1 RollbackReplicationException (com.torodb.mongodb.repl.oplogreplier.RollbackReplicationException)1 StopReplicationException (com.torodb.mongodb.repl.oplogreplier.StopReplicationException)1 LimitedOplogFetcher (com.torodb.mongodb.repl.oplogreplier.fetcher.LimitedOplogFetcher)1 OplogFetcher (com.torodb.mongodb.repl.oplogreplier.fetcher.OplogFetcher)1 CancellationException (java.util.concurrent.CancellationException)1