- Optimistic concurrency control
-
In the field of relational database management systems, optimistic concurrency control (OCC) is a concurrency control method that assumes that multiple transactions can complete without affecting each other, and that therefore transactions can proceed without locking the data resources that they affect. Before committing, each transaction verifies that no other transaction has modified its data. If the check reveals conflicting modifications, the committing transaction rolls back.[1]
OCC is generally used in environments with low data contention . When conflicts are rare, transactions can complete without the expense of managing locks and without having transactions wait for other transactions' locks to clear, leading to higher throughput than other concurrency control methods. However, if conflicts happen often, the cost of repeatedly restarting transactions hurts performance significantly; other concurrency control methods have better performance under these conditions.
Contents
OCC phases
More specifically, OCC transactions involve these phases:
- Begin: Record a timestamp marking the transaction's beginning.
- Modify: Read and write database values.
- Validate: Check whether other transactions have modified data that this transaction has used (read or wrote). Always check transactions that completed after this transaction's start time. Optionally, check transactions that are still active at validation time.
- Commit/Rollback: If there is no conflict, make all changes part of the official state of the database. If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible.
Web usage
The stateless nature of HTTP makes locking infeasible for web user interfaces. It's common for a user to start editing a record, then leave without following a "cancel" or "logout" link. If locking is used, other users who attempt to edit the same record must wait until the first user's lock times out.
HTTP does provide a form of in-built OCC, using the ETag and If-Match headers.[2]
Some database management systems offer OCC natively - without requiring special application code. For others, the application can implement an OCC layer outside of the database, and avoid waiting or silently overwriting records. In such cases, the form includes a hidden field with the record's original content, a timestamp, a sequence number, or an opaque token. On submit, this is compared against the database. If it differs, the conflict resolution algorithm is invoked.
Examples
- MediaWiki's edit pages use OCC.[3]
- Bugzilla uses OCC; edit conflicts are called "mid-air collisions".[4]
- The Ruby on Rails framework has an API for OCC.[5]
- The Grails framework uses OCC in its default conventions.[6]
- Most revision control systems support the "merge" model for concurrency, which is OCC.
- Mimer SQL is a DBMS that only implements optimistic concurrency control.[7]
- Google App Engine data store uses OCC.[8]
See also
References
- ^ Johnson, Rohit (2003). "Common Data Access Issues". Expert One-on-One J2EE Design and Development. Wrox Press. ISBN 0764543857. http://learning.infocollections.com/ebook%202/Computer/Programming/Java/Expert_One-on-One_J2EE_Design_and_Development/6266final/LiB0080.html.
- ^ "Editing the Web - Detecting the Lost Update Problem Using Unreserved Checkout". W3C Note. 10 May 1999. http://www.w3.org/1999/04/Editing/.
- ^ Help:Edit conflict
- ^ "Bugzilla: FAQ: Administrative Questions". MozillaWiki. 23 January 2008. https://wiki.mozilla.org/Bugzilla:FAQ:Administrative_Questions#Does_Bugzilla_provide_record_locking_when_there_is_simultaneous_access_to_the_same_bug.3F_Does_the_second_person_get_a_notice_that_the_bug_is_in_use_or_how_are_they_notified.3F.
- ^ "Module ActiveRecord::Locking". Rails Framework Documentation. http://api.rubyonrails.com/classes/ActiveRecord/Locking.html.
- ^ "Object Relational Mapping (GORM)". Grails Framework Documentation. http://grails.org/doc/1.0.x/guide/single.html#5.3.5%20Pessimistic%20and%20Optimistic%20Locking.
- ^ "Transaction Concurrency - Optimistic Concurrency Control". Mimer Developers - Features. 26 February 2010. http://developer.mimer.com/features/feature_15.htm.
- ^ "The Datastore". What Is Google App Engine?. 27 August 2010. http://code.google.com/appengine/docs/whatisgoogleappengine.html.
External links
- Kung, H. T.; John T. Robinson (June 1981). "On optimistic methods for concurrency control". ACM Transactions on Database Systems 6 (2): 213–226. doi:10.1145/319566.319567.
- Enterprise JavaBeans, 3.0, By Bill Burke, Richard Monson-Haefel, Chapter 16. Transactions, Section 16.3.5. Optimistic Locking, Publisher: O'Reilly, Pub Date: May 16, 2006,Print ISBN 0-596-00978-X,
- Hollmann, Andreas (May 2009). "Multi-Isolation: Virtues and Limitations" (PDF). Multi-Isolation (what is between pessimistic and optimistic locking). 01069 Gutzkovstr. 30/F301.2, Dresden: Happy-Guys Software GbR. pp. 8. http://www.happy-guys.com/products/multi-isolation/publication/multi-isolation-part-1.pdf. Retrieved 2010-01-01.
Categories:
Wikimedia Foundation. 2010.