What happens if the thread never unlocks the document? This has come
up because my python process has been crashing before the document is
unlocked. Therefore the document stays locked forever. Normally a lock
is unlocked when the lock goes out of scope. In C++ that would mean
that the function exited. Because I have to explicitly unlock the
document in the thread that locked it, if that thread dies, I have no
way to unlock it anymore.
Findandmondify is great, but it is more of a way to handle thread
collisions, then locking. If processing a document is very quick, then
the method works great. If processing a single document takes an hour,
you obviously want to minimize collisions.
Unlike most systems, I potentially will have threads on different
computers all vying to modify the same document.
I simply need a way to find out whether or not the thread that locked
the document crashed before it unlocked it, or is still alive and
processing the document. Since the threads will be on different
computers, the threads all have to communicate through the database.
Another way to do this is through a polling method, Each thread
updates a field in the database every 10 seconds. If more than 10
seconds pass between document updates, then you know that thread is
dead, and any locks it has on documents are no longer valid. That is a
common solution, just not very elegant.
Mark
On Aug 31, 3:26 pm, Michael Dirolf <
m...@10gen.com> wrote:
> I don't think there is currently any way to get an ID like that. I
> guess I'm not sure why you can't use findAndModify to do locking
> though? Query for an unlocked document and in the update set the lock
> field.
>