Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/ExtCmd.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ ACTOR static Future<int> internal_doDropIndexesActor(Reference<DocTransaction> t
ACTOR static Future<Void> Internal_doDropCollection(Reference<DocTransaction> tr,
Reference<ExtMsgQuery> query,
Reference<MetadataManager> mm) {
query->ns.second = query->query.getField("drop").String();
state Reference<UnboundCollectionContext> unbound = wait(mm->getUnboundCollectionContext(tr, query->ns));
int _ = wait(internal_doDropIndexesActor(tr, query->ns, mm));
Void _ = wait(unbound->collectionDirectory->remove(tr->tr));
Expand Down Expand Up @@ -436,7 +435,6 @@ struct GetCountCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("count").String();
return getStreamCount(ec, query, reply);
}
};
Expand Down Expand Up @@ -552,7 +550,6 @@ struct FindAndModifyCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("findandmodify").String();
return doFindAndModify(ec, query, reply);
}
};
Expand Down Expand Up @@ -659,7 +656,6 @@ struct DropIndexesCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> nmc,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("dropIndexes").String();
return doDropIndexesActor(nmc, query, reply);
}
};
Expand All @@ -671,7 +667,6 @@ struct DeleteIndexesCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> nmc,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("deleteIndexes").String();
return doDropIndexesActor(nmc, query, reply);
}
};
Expand Down Expand Up @@ -700,7 +695,6 @@ struct CreateIndexesCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getStringField("createIndexes");
return doCreateIndexes(ec, query, reply);
}
};
Expand Down Expand Up @@ -807,7 +801,6 @@ struct CollectionStatsCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("collstats").String();
return getCollectionStats(ec, query, reply);
}
};
Expand Down Expand Up @@ -846,7 +839,6 @@ struct CreateCollectionCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("create").String();
return doCreateCollection(ec, query, reply);
}
};
Expand Down Expand Up @@ -1058,7 +1050,6 @@ struct InsertCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> nmc,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("insert").String();
return insertAndReply(nmc, query, reply);
}
};
Expand Down Expand Up @@ -1101,7 +1092,6 @@ struct DeleteCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> nmc,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("delete").String();
return deleteAndReply(nmc, query, reply);
}
};
Expand Down Expand Up @@ -1154,7 +1144,6 @@ struct UpdateCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> nmc,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("update").String();
return updateAndReply(nmc, query, reply);
}
};
Expand Down Expand Up @@ -1287,8 +1276,6 @@ struct ListIndexesCmd {
state Reference<DocTransaction> dtr = ec->getOperationTransaction();
loop {
try {
msg->ns.second = msg->query.getStringField("listIndexes");

Reference<UnboundCollectionContext> unbound = wait(ec->mm->indexesCollection(dtr, msg->ns.first));

auto getIndexesPlan = getIndexesForCollectionPlan(unbound, msg->ns);
Expand Down Expand Up @@ -1390,7 +1377,6 @@ struct GetDistinctCmd {
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
query->ns.second = query->query.getField("distinct").String();
return getStreamDistinct(ec, query, reply);
}
};
Expand Down
9 changes: 8 additions & 1 deletion src/ExtMsg.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,15 @@ ACTOR Future<Void> runCommand(Reference<ExtConnection> nmc,
Reference<ExtMsgQuery> query,
PromiseStream<Reference<ExtMsgReply>> replyStream) {
state Reference<ExtMsgReply> errReply(new ExtMsgReply(query->header));
state std::string cmd = getFirstKey(query->query);

// For OP_QUERY commands, first elements field name is the command name. And the value contains
// the collection name if the command is at collection level.
auto firstElement = query->query.begin().next();
state std::string cmd = firstElement.fieldName();
std::transform(cmd.begin(), cmd.end(), cmd.begin(), ::tolower);
if (firstElement.isString()) {
query->ns.second = firstElement.String();
}

try {
Reference<ExtMsgReply> reply = wait(ExtCmd::call(cmd, nmc, query, errReply));
Expand Down
29 changes: 29 additions & 0 deletions test/correctness/unit/find_and_modify_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def test_simple_remove(collection):
collection.insert({'A': 'Hello', 'B': 'World'})
collection.insert({'A': 'Hello', 'B': 'California'})
collection.find_and_modify({'A': 'Hello'}, remove=True)
return collection.count() == 1


def test_simple_update(collection):
collection.insert({'A': 'Hello', 'B': 'World'})
collection.insert({'A': 'Hello', 'B': 'California'})

collection.find_and_modify({'A': 'Hello'}, remove=True)
if collection.count() != 1:
return False

collection.find_and_modify({'A': 'Hello'}, update={'A': 'Bye'})
return collection.count({'A': 'Hello'}) == 0


tests = [locals()[attr] for attr in dir() if attr.startswith('test_')]


def test_all(collection1, collection2):
print "findAndModify tests only use first collection specified"
okay = True
for t in tests:
collection1.remove()
okay = t(collection1) and okay
return okay