Search in sources :

Example 11 with Request

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

the class OplogOperationApplier method executeTorodCommand.

private <A, R> Status<R> executeTorodCommand(String db, Command<? super A, ? super R> command, A arg, ExclusiveWriteMongodTransaction trans) throws MongoException {
    Request req = new Request(db, null, true, null);
    Status<R> result = trans.execute(req, command, arg);
    return result;
}
Also used : Request(com.eightkdata.mongowp.server.api.Request)

Example 12 with Request

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

the class AkkaDbCloner method insertDocuments.

private int insertDocuments(MongodServer localServer, String toDb, String collection, List<BsonDocument> docsToInsert) throws RollbackException {
    try (WriteMongodTransaction transaction = createWriteMongodTransaction(localServer)) {
        Status<InsertResult> insertResult = transaction.execute(new Request(toDb, null, true, null), InsertCommand.INSTANCE, new InsertArgument.Builder(collection).addDocuments(docsToInsert).setWriteConcern(WriteConcern.fsync()).setOrdered(true).build());
        if (!insertResult.isOk()) {
            throw new CloningException("Error while inserting a cloned document");
        }
        int insertedDocs = insertResult.getResult().getN();
        if (insertedDocs != docsToInsert.size()) {
            throw new CloningException("Expected to insert " + docsToInsert.size() + " but " + insertResult + " were inserted");
        }
        transaction.commit();
        return insertedDocs;
    } catch (UserException ex) {
        throw new CloningException("Unexpected error while cloning documents", ex);
    }
}
Also used : InsertResult(com.torodb.mongodb.commands.signatures.general.InsertCommand.InsertResult) WriteMongodTransaction(com.torodb.mongodb.core.WriteMongodTransaction) InsertArgument(com.torodb.mongodb.commands.signatures.general.InsertCommand.InsertArgument) Request(com.eightkdata.mongowp.server.api.Request) UserException(com.torodb.core.exceptions.user.UserException) Hint(com.torodb.core.retrier.Retrier.Hint)

Aggregations

Request (com.eightkdata.mongowp.server.api.Request)12 WriteMongodTransaction (com.torodb.mongodb.core.WriteMongodTransaction)5 Status (com.eightkdata.mongowp.Status)4 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)4 MongoException (com.eightkdata.mongowp.exceptions.MongoException)4 Command (com.eightkdata.mongowp.server.api.Command)4 UserException (com.torodb.core.exceptions.user.UserException)4 AttributeReference (com.torodb.core.language.AttributeReference)4 IndexOptions (com.torodb.mongodb.commands.pojos.index.IndexOptions)4 List (java.util.List)4 ErrorCode (com.eightkdata.mongowp.ErrorCode)3 InsertArgument (com.torodb.mongodb.commands.signatures.general.InsertCommand.InsertArgument)3 InsertResult (com.torodb.mongodb.commands.signatures.general.InsertCommand.InsertResult)3 Constants (com.torodb.mongodb.language.Constants)3 IndexFieldInfo (com.torodb.torod.IndexFieldInfo)3 Arrays (java.util.Arrays)3 CommandFailed (com.eightkdata.mongowp.exceptions.CommandFailed)2 BsonDocumentBuilder (com.eightkdata.mongowp.utils.BsonDocumentBuilder)2 Cursor (com.torodb.core.cursors.Cursor)2 Builder (com.torodb.core.language.AttributeReference.Builder)2