I have two clients (dragon) manipulate a single archive, the collection is used as a pool , And each single record int archive can be used only in one client, I'm using the code below to make sure (this is not a critical system, so a slight mistake can be tolerated). Recorded ["used1"] = (100): record = collection.find_one ({"[" $ 1 ": {" $ exists ": incorrect}})
True collection. Record (record) ... I want to do this ...But I found that sometimes two clients do not sync, the local client gets a record And after 10 seconds, the remote client will also have the same record.
In fact, if 2 clients are less than 2 seconds, which is tolerant, but 10 seconds is too long.
Seeming Is there buffer / synchronization issues here, what can I do to reduce such problems?
What you need to use is the command that is atomic By the way, "truth" is not in the old existence and then it returns the same record to the customer who has just updated it.
It guarantees that each document will be used only by one thread, however, you still have to deal with the same problem. Your code is now - if this "used1" field is true then the customer The process ends, but before its work, your data will be in an inconsistent state.
Comments
Post a Comment