Mongodb FindAndModify problem with multiprocess use
I use python 2.6.6, pymongo 1.9, mongodb 1.6.5, Ubuntu 10.10
I have strange problem with FindAndModify command.
I have two identical process running at the same time. They get records from db with FindAndModify(implements some sort of queue).
So to make that only one process get record i do this:
find_and_modify({query:{"status":"loaded"},update:{"$set": {"status":"analyzing"}})
This works so:
1 process use findAndModify to get job 2 process use findAndModify to get job 1 process make job and save result 2 process make job and save result
So process get record with status "loaded" and change it to "analyzing". And if this operation is atomic second process should not seen this record because it not satisfy query.
But sometimes two process get one same record at the same time, and 开发者_运维技巧this is problem.
Can anyone tell why it's happens and how i can implement queue with mongodb which will lock documents from being reading by more then one process?
Thanks.
While was trying to reproduce this bug in standalone script, found that problem was not in MongoDB. MongoDB works as said in manual, so the question is closed now.
For thous who found same bug - Don't forget to check another threads/processes for modifying queue data at runtime.
You can use the snapshot=True flag to avoid getting these kind of duplicates.
精彩评论