Search in sources :

Example 1 with Command

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

the class FindImplementation method apply.

@Override
public Status<FindResult> apply(Request req, Command<? super FindArgument, ? super FindResult> command, FindArgument arg, MongodTransaction context) {
    logFindCommand(arg);
    BsonDocument filter = arg.getFilter();
    Cursor<BsonDocument> cursor;
    switch(filter.size()) {
        case 0:
            {
                cursor = context.getTorodTransaction().findAll(req.getDatabase(), arg.getCollection()).asDocCursor().transform(t -> t.getRoot()).transform(ToBsonDocumentTranslator.getInstance());
                break;
            }
        case 1:
            {
                try {
                    cursor = getByAttributeCursor(context.getTorodTransaction(), req.getDatabase(), arg.getCollection(), filter).transform(ToBsonDocumentTranslator.getInstance());
                } catch (CommandFailed ex) {
                    return Status.from(ex);
                }
                break;
            }
        default:
            {
                return Status.from(ErrorCode.COMMAND_FAILED, "The given query is not supported right now");
            }
    }
    if (Long.valueOf(arg.getBatchSize()) > (long) Integer.MAX_VALUE) {
        return Status.from(ErrorCode.COMMAND_FAILED, "Only batchSize equals or lower than " + Integer.MAX_VALUE + " is supported");
    }
    OptionalLong batchSize = arg.getEffectiveBatchSize();
    List<BsonDocument> batch = cursor.getNextBatch(batchSize.isPresent() ? (int) batchSize.getAsLong() : 101);
    cursor.close();
    return Status.ok(new FindResult(CursorResult.createSingleBatchCursor(req.getDatabase(), arg.getCollection(), batch.iterator())));
}
Also used : Request(com.eightkdata.mongowp.server.api.Request) FindResult(com.torodb.mongodb.commands.signatures.general.FindCommand.FindResult) AttributeReference(com.torodb.core.language.AttributeReference) Cursor(com.torodb.core.cursors.Cursor) KvDocument(com.torodb.kvdocument.values.KvDocument) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) Command(com.eightkdata.mongowp.server.api.Command) ToBsonDocumentTranslator(com.torodb.kvdocument.conversion.mongowp.ToBsonDocumentTranslator) Singleton(javax.inject.Singleton) CursorResult(com.torodb.mongodb.commands.pojos.CursorResult) MongodTransaction(com.torodb.mongodb.core.MongodTransaction) OptionalLong(java.util.OptionalLong) KvValue(com.torodb.kvdocument.values.KvValue) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Status(com.eightkdata.mongowp.Status) FindArgument(com.torodb.mongodb.commands.signatures.general.FindCommand.FindArgument) TorodTransaction(com.torodb.torod.TorodTransaction) Builder(com.torodb.core.language.AttributeReference.Builder) ErrorCode(com.eightkdata.mongowp.ErrorCode) ReadTorodbCommandImpl(com.torodb.mongodb.commands.impl.ReadTorodbCommandImpl) CommandFailed(com.eightkdata.mongowp.exceptions.CommandFailed) LogManager(org.apache.logging.log4j.LogManager) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) CommandFailed(com.eightkdata.mongowp.exceptions.CommandFailed) OptionalLong(java.util.OptionalLong) FindResult(com.torodb.mongodb.commands.signatures.general.FindCommand.FindResult)

Example 2 with Command

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

the class UpdateImplementation method apply.

@Override
public Status<UpdateResult> apply(Request req, Command<? super UpdateArgument, ? super UpdateResult> command, UpdateArgument arg, WriteMongodTransaction context) {
    UpdateStatus updateStatus = new UpdateStatus();
    try {
        if (!context.getTorodTransaction().existsCollection(req.getDatabase(), arg.getCollection())) {
            context.getTorodTransaction().createIndex(req.getDatabase(), arg.getCollection(), Constants.ID_INDEX, ImmutableList.<IndexFieldInfo>of(new IndexFieldInfo(new AttributeReference(Arrays.asList(new Key[] { new ObjectKey(Constants.ID) })), FieldIndexOrdering.ASC.isAscending())), true);
        }
        for (UpdateStatement updateStatement : arg.getStatements()) {
            BsonDocument query = updateStatement.getQuery();
            UpdateAction updateAction = UpdateActionTranslator.translate(updateStatement.getUpdate());
            Cursor<ToroDocument> candidatesCursor;
            switch(query.size()) {
                case 0:
                    {
                        candidatesCursor = context.getTorodTransaction().findAll(req.getDatabase(), arg.getCollection()).asDocCursor();
                        break;
                    }
                case 1:
                    {
                        try {
                            candidatesCursor = findByAttribute(context.getTorodTransaction(), req.getDatabase(), arg.getCollection(), query);
                        } catch (CommandFailed ex) {
                            return Status.from(ex);
                        }
                        break;
                    }
                default:
                    {
                        return Status.from(ErrorCode.COMMAND_FAILED, "The given query is not supported right now");
                    }
            }
            if (candidatesCursor.hasNext()) {
                try {
                    Stream<List<ToroDocument>> candidatesbatchStream;
                    if (updateStatement.isMulti()) {
                        candidatesbatchStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(candidatesCursor.batch(100), Spliterator.ORDERED), false);
                    } else {
                        candidatesbatchStream = Stream.of(ImmutableList.of(candidatesCursor.next()));
                    }
                    Stream<KvDocument> updatedCandidates = candidatesbatchStream.map(candidates -> {
                        updateStatus.increaseCandidates(candidates.size());
                        context.getTorodTransaction().delete(req.getDatabase(), arg.getCollection(), candidates);
                        return candidates;
                    }).flatMap(l -> l.stream()).map(candidate -> {
                        try {
                            updateStatus.increaseUpdated();
                            return update(updateAction, candidate);
                        } catch (UserException userException) {
                            throw new UserWrappedException(userException);
                        }
                    });
                    context.getTorodTransaction().insert(req.getDatabase(), arg.getCollection(), updatedCandidates);
                } catch (UserWrappedException userWrappedException) {
                    throw userWrappedException.getCause();
                }
            } else if (updateStatement.isUpsert()) {
                KvDocument toInsertCandidate;
                if (updateAction instanceof SetDocumentUpdateAction) {
                    toInsertCandidate = ((SetDocumentUpdateAction) updateAction).getNewValue();
                } else {
                    toInsertCandidate = update(updateAction, new ToroDocument(-1, (KvDocument) MongoWpConverter.translate(query)));
                }
                if (!toInsertCandidate.containsKey(Constants.ID)) {
                    KvDocument.Builder builder = new KvDocument.Builder();
                    for (DocEntry<?> entry : toInsertCandidate) {
                        builder.putValue(entry.getKey(), entry.getValue());
                    }
                    builder.putValue(Constants.ID, MongoWpConverter.translate(objectIdFactory.consumeObjectId()));
                    toInsertCandidate = builder.build();
                }
                updateStatus.increaseCandidates(1);
                updateStatus.increaseCreated(toInsertCandidate.get(Constants.ID));
                Stream<KvDocument> toInsertCandidates = Stream.of(toInsertCandidate);
                context.getTorodTransaction().insert(req.getDatabase(), arg.getCollection(), toInsertCandidates);
            }
        }
    } catch (UserException ex) {
        //TODO: Improve error reporting
        return Status.from(ErrorCode.COMMAND_FAILED, ex.getLocalizedMessage());
    }
    mongodMetrics.getUpdateModified().mark(updateStatus.updated);
    mongodMetrics.getUpdateMatched().mark(updateStatus.candidates);
    mongodMetrics.getUpdateUpserted().mark(updateStatus.upsertResults.size());
    return Status.ok(new UpdateResult(updateStatus.updated, updateStatus.candidates, ImmutableList.copyOf(updateStatus.upsertResults)));
}
Also used : Request(com.eightkdata.mongowp.server.api.Request) UpdateActionTranslator(com.torodb.mongodb.language.UpdateActionTranslator) Arrays(java.util.Arrays) UpdatedToroDocumentBuilder(com.torodb.mongodb.language.update.UpdatedToroDocumentBuilder) FieldIndexOrdering(com.torodb.core.transaction.metainf.FieldIndexOrdering) Spliterators(java.util.Spliterators) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) WriteTorodbCommandImpl(com.torodb.mongodb.commands.impl.WriteTorodbCommandImpl) UpdateAction(com.torodb.mongodb.language.update.UpdateAction) UpdateStatement(com.torodb.mongodb.commands.signatures.general.UpdateCommand.UpdateStatement) Singleton(javax.inject.Singleton) ToroDocument(com.torodb.core.document.ToroDocument) UpdateResult(com.torodb.mongodb.commands.signatures.general.UpdateCommand.UpdateResult) ArrayList(java.util.ArrayList) ObjectKey(com.torodb.core.language.AttributeReference.ObjectKey) IndexFieldInfo(com.torodb.torod.IndexFieldInfo) Inject(javax.inject.Inject) KvValue(com.torodb.kvdocument.values.KvValue) ImmutableList(com.google.common.collect.ImmutableList) MongoWpConverter(com.torodb.kvdocument.conversion.mongowp.MongoWpConverter) StreamSupport(java.util.stream.StreamSupport) Builder(com.torodb.core.language.AttributeReference.Builder) ErrorCode(com.eightkdata.mongowp.ErrorCode) CommandFailed(com.eightkdata.mongowp.exceptions.CommandFailed) UpdateException(com.torodb.core.exceptions.user.UpdateException) SharedWriteTorodTransaction(com.torodb.torod.SharedWriteTorodTransaction) AttributeReference(com.torodb.core.language.AttributeReference) Constants(com.torodb.mongodb.language.Constants) Cursor(com.torodb.core.cursors.Cursor) KvDocument(com.torodb.kvdocument.values.KvDocument) UpsertResult(com.torodb.mongodb.commands.signatures.general.UpdateCommand.UpsertResult) Command(com.eightkdata.mongowp.server.api.Command) UserException(com.torodb.core.exceptions.user.UserException) SetDocumentUpdateAction(com.torodb.mongodb.language.update.SetDocumentUpdateAction) ObjectIdFactory(com.torodb.mongodb.language.ObjectIdFactory) DocEntry(com.torodb.kvdocument.values.KvDocument.DocEntry) MongodMetrics(com.torodb.mongodb.core.MongodMetrics) WriteMongodTransaction(com.torodb.mongodb.core.WriteMongodTransaction) List(java.util.List) Stream(java.util.stream.Stream) Status(com.eightkdata.mongowp.Status) UserWrappedException(com.torodb.core.exceptions.UserWrappedException) UpdateArgument(com.torodb.mongodb.commands.signatures.general.UpdateCommand.UpdateArgument) Spliterator(java.util.Spliterator) Key(com.torodb.core.language.AttributeReference.Key) KvDocument(com.torodb.kvdocument.values.KvDocument) UpdateStatement(com.torodb.mongodb.commands.signatures.general.UpdateCommand.UpdateStatement) UpdateAction(com.torodb.mongodb.language.update.UpdateAction) SetDocumentUpdateAction(com.torodb.mongodb.language.update.SetDocumentUpdateAction) AttributeReference(com.torodb.core.language.AttributeReference) UpdatedToroDocumentBuilder(com.torodb.mongodb.language.update.UpdatedToroDocumentBuilder) Builder(com.torodb.core.language.AttributeReference.Builder) ObjectKey(com.torodb.core.language.AttributeReference.ObjectKey) DocEntry(com.torodb.kvdocument.values.KvDocument.DocEntry) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) UserWrappedException(com.torodb.core.exceptions.UserWrappedException) ToroDocument(com.torodb.core.document.ToroDocument) CommandFailed(com.eightkdata.mongowp.exceptions.CommandFailed) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Stream(java.util.stream.Stream) IndexFieldInfo(com.torodb.torod.IndexFieldInfo) UserException(com.torodb.core.exceptions.user.UserException) UpdateResult(com.torodb.mongodb.commands.signatures.general.UpdateCommand.UpdateResult) SetDocumentUpdateAction(com.torodb.mongodb.language.update.SetDocumentUpdateAction)

Example 3 with Command

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

the class DropIndexesImplementation method apply.

@Override
public Status<DropIndexesResult> apply(Request req, Command<? super DropIndexesArgument, ? super DropIndexesResult> command, DropIndexesArgument arg, WriteMongodTransaction context) {
    int indexesBefore = (int) context.getTorodTransaction().getIndexesInfo(req.getDatabase(), arg.getCollection()).count();
    List<String> indexesToDrop;
    if (!arg.isDropAllIndexes()) {
        if (!arg.isDropByKeys()) {
            if (Constants.ID_INDEX.equals(arg.getIndexToDrop())) {
                return Status.from(ErrorCode.INVALID_OPTIONS, "cannot drop _id index");
            }
            indexesToDrop = Arrays.asList(arg.getIndexToDrop());
        } else {
            if (arg.getKeys().stream().anyMatch(key -> !(KnownType.contains(key.getType())) || (key.getType() != KnownType.asc.getIndexType() && key.getType() != KnownType.desc.getIndexType()))) {
                return getStatusForIndexNotFoundWithKeys(arg);
            }
            indexesToDrop = context.getTorodTransaction().getIndexesInfo(req.getDatabase(), arg.getCollection()).filter(index -> indexFieldsMatchKeys(index, arg.getKeys())).map(index -> index.getName()).collect(Collectors.toList());
            if (indexesToDrop.isEmpty()) {
                return getStatusForIndexNotFoundWithKeys(arg);
            }
        }
    } else {
        indexesToDrop = context.getTorodTransaction().getIndexesInfo(req.getDatabase(), arg.getCollection()).filter(indexInfo -> !Constants.ID_INDEX.equals(indexInfo.getName())).map(indexInfo -> indexInfo.getName()).collect(Collectors.toList());
    }
    for (String indexToDrop : indexesToDrop) {
        boolean dropped = context.getTorodTransaction().dropIndex(req.getDatabase(), arg.getCollection(), indexToDrop);
        if (!dropped) {
            return Status.from(ErrorCode.INDEX_NOT_FOUND, "index not found with name [" + indexToDrop + "]");
        }
    }
    return Status.ok(new DropIndexesResult(indexesBefore));
}
Also used : Request(com.eightkdata.mongowp.server.api.Request) Arrays(java.util.Arrays) AttributeReference(com.torodb.core.language.AttributeReference) Constants(com.torodb.mongodb.language.Constants) Iterator(java.util.Iterator) DropIndexesResult(com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesResult) Command(com.eightkdata.mongowp.server.api.Command) WriteTorodbCommandImpl(com.torodb.mongodb.commands.impl.WriteTorodbCommandImpl) Collectors(java.util.stream.Collectors) WriteMongodTransaction(com.torodb.mongodb.core.WriteMongodTransaction) IndexFieldInfo(com.torodb.torod.IndexFieldInfo) List(java.util.List) Status(com.eightkdata.mongowp.Status) KnownType(com.torodb.mongodb.commands.pojos.index.IndexOptions.KnownType) ErrorCode(com.eightkdata.mongowp.ErrorCode) IndexInfo(com.torodb.torod.IndexInfo) IndexOptions(com.torodb.mongodb.commands.pojos.index.IndexOptions) DropIndexesArgument(com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesArgument) DropIndexesResult(com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesResult)

Example 4 with Command

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

the class ServerStatusImplementation method apply.

@Override
public Status<ServerStatusReply> apply(Request req, Command<? super ServerStatusArgument, ? super ServerStatusReply> command, ServerStatusArgument arg, MongodConnection context) {
    ServerStatusReply.Builder replyBuilder = new ServerStatusReply.Builder();
    //TODO: improve and complete
    if (arg.isHost()) {
        try {
            replyBuilder.setHost(InetAddress.getLocalHost().getHostName() + ":" + selfHostAndPort.getPort());
        } catch (Throwable throwable) {
            replyBuilder.setHost("localhost:" + selfHostAndPort.getPort());
        }
    }
    if (arg.isVersion()) {
        replyBuilder.setVersion(MongoLayerConstants.VERSION_STRING);
    }
    if (arg.isProcess()) {
        replyBuilder.setProcess("mongod");
    }
    if (arg.isPid()) {
        try {
            replyBuilder.setPid(Integer.valueOf(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]));
        } catch (Throwable throwable) {
            LOGGER.warn("Cannot get PID: " + throwable.getMessage());
        }
    }
    if (arg.isUptime()) {
        replyBuilder.setUptime(ManagementFactory.getRuntimeMXBean().getUptime());
    }
    if (arg.isUptimeEstimate()) {
        replyBuilder.setUptimeEstimate(ManagementFactory.getRuntimeMXBean().getUptime());
    }
    if (arg.isLocalTime()) {
        replyBuilder.setLocalTime(Instant.now());
    }
    if (arg.isLocks()) {
        Locks.Count dummyCount = new Locks.Count(0, 0, 0, 0);
        Locks.Lock dummyLock = new Locks.Lock(dummyCount, dummyCount, dummyCount, dummyCount);
        replyBuilder.setLocks(new Locks(dummyLock, dummyLock, dummyLock, dummyLock, dummyLock, dummyLock));
    }
    if (arg.isGlobalLock()) {
        GlobalLock.GlobalLockStats dummyGlobalLockStats = new GlobalLock.GlobalLockStats(0, 0, 0);
        replyBuilder.setGlobalLock(new GlobalLock(0, dummyGlobalLockStats, dummyGlobalLockStats));
    }
    if (arg.isMem()) {
        replyBuilder.setMem(new Mem(0, 0, 0, false, 0, 0, ""));
    }
    if (arg.isConnections()) {
        replyBuilder.setConnections(new Connections(0, 0, 0));
    }
    if (arg.isExtraInfo()) {
        replyBuilder.setExtraInfo(new ExtraInfo("", 0, 0));
    }
    if (arg.isBackgroundFlushing()) {
        replyBuilder.setBackgroundFlushing(new BackgroundFlushing(0, 0, 0, 0, Instant.now()));
    }
    if (arg.isCursors()) {
        replyBuilder.setCursors(new Cursors("", 0, 0, 0, 0, 0));
    }
    if (arg.isNetwork()) {
        replyBuilder.setNetwork(new Network(0, 0, 0));
    }
    //}
    if (arg.isOpcountersRepl()) {
        replyBuilder.setOpcountersRepl(new Opcounters(0, 0, 0, 0, 0, 0));
    }
    if (arg.isOpcounters()) {
        replyBuilder.setOpcounters(new Opcounters(0, 0, 0, 0, 0, 0));
    }
    if (arg.isRangeDeleter()) {
        ImmutableList.Builder<RangeDeleter.LastDeletedStat> builder = ImmutableList.builder();
        replyBuilder.setRangeDeleter(new RangeDeleter(builder.build()));
    }
    if (arg.isSecurity()) {
        replyBuilder.setSecurity(new Security(null, false, null));
    }
    if (arg.isStorageEngine()) {
        replyBuilder.setStorageEngine(new StorageEngine("ToroDB"));
    }
    if (arg.isAsserts()) {
        replyBuilder.setAsserts(new Asserts(0, 0, 0, 0, 0));
    }
    if (arg.isDur()) {
        replyBuilder.setDur(new Dur(0, 0, 0, 0, 0, 0, new Dur.TimeMs(0, 0, 0, 0, 0, 0, 0)));
    }
    if (arg.isWriteBacksQueued()) {
        replyBuilder.setWritebacksQueued(0);
    }
    if (arg.isMetrics()) {
        ImmutableList.Builder<Metrics.Command> builder = ImmutableList.builder();
        Metrics.Stats dummyStats = new Metrics.Stats(0, 0);
        replyBuilder.setMetrics(new Metrics(builder.build(), new Metrics.Document(0, 0, 0, 0), new Metrics.GetLastError(dummyStats, 0), new Metrics.Operation(0, 0, 0), new Metrics.QueryExecutor(0), new Metrics.Record(0), new Metrics.Repl(new Metrics.Repl.Apply(dummyStats, 0), new Metrics.Repl.Buffer(0, 0, 0), new Metrics.Repl.Network(0, dummyStats, 0, 0), new Metrics.Repl.Oplog(dummyStats, 0), new Metrics.Repl.Preload(dummyStats, dummyStats)), new Metrics.Storage(new Metrics.Storage.Freelist(new Metrics.Storage.Freelist.Search(0, 0, 0))), new Metrics.Ttl(0, 0)));
    }
    return Status.ok(replyBuilder.build());
}
Also used : Connections(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Connections) ImmutableList(com.google.common.collect.ImmutableList) Security(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Security) StorageEngine(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.StorageEngine) GlobalLock(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.GlobalLock) Metrics(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Metrics) Opcounters(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Opcounters) RangeDeleter(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.RangeDeleter) Network(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Network) Cursors(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Cursors) ServerStatusReply(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.ServerStatusReply) Dur(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Dur) Locks(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Locks) ExtraInfo(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.ExtraInfo) BackgroundFlushing(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.BackgroundFlushing) GlobalLock(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.GlobalLock) Mem(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Mem) Command(com.eightkdata.mongowp.server.api.Command) Asserts(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Asserts)

Example 5 with Command

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

the class DropIndexesReplImpl method apply.

@Override
public Status<DropIndexesResult> apply(Request req, Command<? super DropIndexesArgument, ? super DropIndexesResult> command, DropIndexesArgument arg, SharedWriteTorodTransaction trans) {
    int indexesBefore = (int) trans.getIndexesInfo(req.getDatabase(), arg.getCollection()).count();
    List<String> indexesToDrop;
    if (!arg.isDropAllIndexes()) {
        if (!arg.isDropByKeys()) {
            if (Constants.ID_INDEX.equals(arg.getIndexToDrop())) {
                LOGGER.warn("Trying to drop index {}. Ignoring the whole request", arg.getIndexToDrop());
                return Status.ok(new DropIndexesResult(indexesBefore));
            }
            indexesToDrop = Arrays.asList(arg.getIndexToDrop());
        } else {
            indexesToDrop = trans.getIndexesInfo(req.getDatabase(), arg.getCollection()).filter(index -> indexFieldsMatchKeys(index, arg.getKeys())).map(index -> index.getName()).collect(Collectors.toList());
            if (indexesToDrop.isEmpty()) {
                LOGGER.warn("Index not found with keys [" + arg.getKeys().stream().map(key -> '"' + key.getKeys().stream().collect(Collectors.joining(".")) + "\" :" + key.getType().getName()).collect(Collectors.joining(", ")) + "]. Ignoring the whole request", arg.getIndexToDrop());
                return Status.ok(new DropIndexesResult(indexesBefore));
            }
        }
    } else {
        indexesToDrop = trans.getIndexesInfo(req.getDatabase(), arg.getCollection()).filter(indexInfo -> !Constants.ID_INDEX.equals(indexInfo.getName())).map(indexInfo -> indexInfo.getName()).collect(Collectors.toList());
    }
    for (String indexToDrop : indexesToDrop) {
        LOGGER.info("Dropping index {} on collection {}.{}", req.getDatabase(), arg.getCollection(), indexToDrop);
        boolean dropped = trans.dropIndex(req.getDatabase(), arg.getCollection(), indexToDrop);
        if (!dropped) {
            LOGGER.info("Trying to drop index {}, but it has not been " + "found. This is normal since the index could have been filtered or " + "we are reapplying oplog during a recovery. Ignoring it", indexToDrop);
        }
    }
    return Status.ok(new DropIndexesResult(indexesBefore));
}
Also used : Request(com.eightkdata.mongowp.server.api.Request) SharedWriteTorodTransaction(com.torodb.torod.SharedWriteTorodTransaction) Arrays(java.util.Arrays) AttributeReference(com.torodb.core.language.AttributeReference) Constants(com.torodb.mongodb.language.Constants) Iterator(java.util.Iterator) DropIndexesResult(com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesResult) Command(com.eightkdata.mongowp.server.api.Command) Collectors(java.util.stream.Collectors) IndexFieldInfo(com.torodb.torod.IndexFieldInfo) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Status(com.eightkdata.mongowp.Status) KnownType(com.torodb.mongodb.commands.pojos.index.IndexOptions.KnownType) IndexInfo(com.torodb.torod.IndexInfo) IndexOptions(com.torodb.mongodb.commands.pojos.index.IndexOptions) DropIndexesArgument(com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesArgument) LogManager(org.apache.logging.log4j.LogManager) DropIndexesResult(com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesResult)

Aggregations

Command (com.eightkdata.mongowp.server.api.Command)6 Status (com.eightkdata.mongowp.Status)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 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 ImmutableList (com.google.common.collect.ImmutableList)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 IndexOptions (com.torodb.mongodb.commands.pojos.index.IndexOptions)2 KnownType (com.torodb.mongodb.commands.pojos.index.IndexOptions.KnownType)2 DropIndexesArgument (com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesArgument)2