MongoDB FindAndModify Sort

I am using FindAndModify in MongoDB in several parallel processes. The size of the collection is about 3 million records, and everything works like an explosion until I pass the sort parameter (indexed field). As soon as I try to do this, the following warning is logged:

warning: ClientCursor::yield can't unlock b/c of recursive lock ns: test_db.wengine_queue top: { opid: 424210, active: true, lockType: "write", waitingForLock: false, secs_running: 0, op: "query", ns: "test_db", query: { findAndModify: "wengine_queue", query: { locked: { $ne: 1 }, rule_completed: { $in: [ "", "0", null ] }, execute_at: { $lt: 1324381363 }, company_id: 23, debug: 0, system_id: "AK/AK1201" }, update: { $set: { locked: 1 } }, sort: { execute_at: -1 } }, client: "127.0.0.1:60873", desc: "conn", threadId: "0x1541bb000", connectionId: 1147, numYields: 0 } 

I have all the keys to the indexed query, here they are:

 PRIMARY> db.wengine_queue.getIndexes() [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "test_db.wengine_queue", "name" : "_id_" }, { "v" : 1, "key" : { "system_id" : 1, "company_id" : 1, "locked" : 1, "rule_completed" : 1, "execute_at" : -1, "debug" : 1 }, "ns" : "test_db.wengine_queue", "name" : "system_id_1_company_id_1_locked_1_rule_completed_1_execute_at_-1_debug_1" }, { "v" : 1, "key" : { "debug" : 1 }, "ns" : "test_db.wengine_queue", "name" : "debug_1" }, { "v" : 1, "key" : { "system_id" : 1 }, "ns" : "test_db.wengine_queue", "name" : "system_id_1" }, { "v" : 1, "key" : { "company_id" : 1 }, "ns" : "test_db.wengine_queue", "name" : "company_id_1" }, { "v" : 1, "key" : { "locked" : 1 }, "ns" : "test_db.wengine_queue", "name" : "locked_1" }, { "v" : 1, "key" : { "rule_completed" : 1 }, "ns" : "test_db.wengine_queue", "name" : "rule_completed_1" }, { "v" : 1, "key" : { "execute_at" : -1 }, "ns" : "test_db.wengine_queue", "name" : "execute_at_-1" }, { "v" : 1, "key" : { "thread_id" : 1 }, "ns" : "test_db.wengine_queue", "name" : "thread_id_1" }, { "v" : 1, "key" : { "rule_id" : 1 }, "ns" : "test_db.wengine_queue", "name" : "rule_id_1" } ] 

Is there any way around this?

+6
source share
2 answers

For those who are interested, I had to create a separate index ending with a key, which should sort the set.

+4
source

This warning is issued when an operation that wants to perform (for example, long updates, deletes, etc.) cannot do this, because for some reason it cannot release the lock.

Do you have a field that you sort by indexing? If you do not add an index for this, probably remove the warnings.

+1
source

Source: https://habr.com/ru/post/904146/


All Articles