optimistic and pessimistic locks

Posted by billmce on Stack Overflow See other posts from Stack Overflow or by billmce
Published on 2010-05-20T17:34:16Z Indexed on 2010/05/21 1:20 UTC
Read the original article Hit count: 212

Filed under:
|

Working on my first php/Codeigniter project and I’ve scoured the ‘net for information on locking access to editing data and haven’t found very much information.

I expect it to be a fairly regular occurrence for 2 users to attempt to edit the same form simultaneously.

My experience (in the stateful world of BBx, filePro, and other RAD apps) is that the data being edited is locked using a pessimistic lock—one user has access to the edit form at the time. The second user basically has to wait for the first to finish. I understand this can be done using Ajax sending XMLHttpRequests to maintain a ‘lock’ database.

The php world, lacking state, seems to prefer optimistic locking. If I understand it correctly it works like this: both users get to access the data and they each record a ‘before changes’ version of the data. Before saving their changes, the data is once again retrieved and compared the ‘before changes’ version. If the two versions are identical then the users changes are written. If they are different; the user is shown what has changed since he/she started editing and some mechanism is added to resolve the differences—or the user is shown a ‘Sorry, try again’ message.

I’m interested in any experience people here have had with implementing both pessimistic and optimistic locking. If there are any libraries, tools, or ‘how-to’s available I’m appreciate a link.

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about codeigniter