Search in sources :

Example 6 with Status

use of com.eightkdata.mongowp.Status in project torodb by torodb.

the class OplogOperationApplier method insertIndex.

private void insertIndex(BsonDocument indexDoc, String database, ExclusiveWriteMongodTransaction trans) throws OplogApplyingException {
    try {
        CreateIndexesCommand command = CreateIndexesCommand.INSTANCE;
        IndexOptions indexOptions = IndexOptions.unmarshall(indexDoc);
        CreateIndexesArgument arg = new CreateIndexesArgument(indexOptions.getCollection(), Arrays.asList(new IndexOptions[] { indexOptions }));
        Status executionResult = executeReplCommand(database, command, arg, trans.getTorodTransaction());
        if (!executionResult.isOk()) {
            throw new OplogApplyingException(new MongoException(executionResult));
        }
    } catch (MongoException ex) {
        throw new OplogApplyingException(ex);
    }
}
Also used : Status(com.eightkdata.mongowp.Status) MongoException(com.eightkdata.mongowp.exceptions.MongoException) CreateIndexesArgument(com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand.CreateIndexesArgument) IndexOptions(com.torodb.mongodb.commands.pojos.index.IndexOptions) CreateIndexesCommand(com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand)

Example 7 with Status

use of com.eightkdata.mongowp.Status in project torodb by torodb.

the class OplogOperationApplier method applyCmd.

@SuppressWarnings("unchecked")
private void applyCmd(DbCmdOplogOperation op, ExclusiveWriteMongodTransaction trans, ApplierContext applierContext) throws OplogApplyingException {
    LibraryEntry librayEntry = library.find(op.getRequest());
    if (librayEntry == null) {
        throw new OplogApplyingException(new CommandNotFoundException(op.getRequest().isEmpty() ? "?" : op.getRequest().getFirstEntry().getKey()));
    }
    Command command = librayEntry.getCommand();
    if (command == null) {
        BsonDocument document = op.getRequest();
        if (document.isEmpty()) {
            throw new OplogApplyingException(new CommandNotFoundException("Empty document query"));
        }
        String firstKey = document.getFirstEntry().getKey();
        throw new OplogApplyingException(new CommandNotFoundException(firstKey));
    }
    Object arg;
    try {
        arg = command.unmarshallArg(op.getRequest(), librayEntry.getAlias());
    } catch (MongoException ex) {
        throw new OplogApplyingException(ex);
    }
    Status executionResult = executeReplCommand(op.getDatabase(), command, arg, trans.getTorodTransaction());
    if (!executionResult.isOk()) {
        throw new OplogApplyingException(new MongoException(executionResult));
    }
}
Also used : Status(com.eightkdata.mongowp.Status) LibraryEntry(com.eightkdata.mongowp.server.api.CommandsLibrary.LibraryEntry) MongoException(com.eightkdata.mongowp.exceptions.MongoException) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) DeleteCommand(com.torodb.mongodb.commands.signatures.general.DeleteCommand) Command(com.eightkdata.mongowp.server.api.Command) UpdateCommand(com.torodb.mongodb.commands.signatures.general.UpdateCommand) CreateIndexesCommand(com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand) InsertCommand(com.torodb.mongodb.commands.signatures.general.InsertCommand) CommandNotFoundException(com.eightkdata.mongowp.exceptions.CommandNotFoundException)

Aggregations

Status (com.eightkdata.mongowp.Status)7 Command (com.eightkdata.mongowp.server.api.Command)5 Request (com.eightkdata.mongowp.server.api.Request)4 AttributeReference (com.torodb.core.language.AttributeReference)4 List (java.util.List)4 ErrorCode (com.eightkdata.mongowp.ErrorCode)3 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)3 IndexOptions (com.torodb.mongodb.commands.pojos.index.IndexOptions)3 WriteMongodTransaction (com.torodb.mongodb.core.WriteMongodTransaction)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 MongoException (com.eightkdata.mongowp.exceptions.MongoException)2 Cursor (com.torodb.core.cursors.Cursor)2 Builder (com.torodb.core.language.AttributeReference.Builder)2 KvDocument (com.torodb.kvdocument.values.KvDocument)2 KvValue (com.torodb.kvdocument.values.KvValue)2 WriteTorodbCommandImpl (com.torodb.mongodb.commands.impl.WriteTorodbCommandImpl)2 KnownType (com.torodb.mongodb.commands.pojos.index.IndexOptions.KnownType)2