World Library  
Flag as Inappropriate
Email this Article

Optimistic concurrency control

Article Id: WHEBN0000233011
Reproduction Date:

Title: Optimistic concurrency control  
Author: World Heritage Encyclopedia
Language: English
Subject: Commitment ordering, Long-lived transaction, Long-running transaction, Non-lock concurrency control, HTTP ETag
Collection: Concurrency Control
Publisher: World Heritage Encyclopedia

Optimistic concurrency control

Optimistic concurrency control (OCC) is a concurrency control method applied to transactional systems such as relational database management systems and software transactional memory. OCC assumes that multiple transactions can frequently complete without interfering with each other. While running, transactions use data resources without acquiring locks on those resources. Before committing, each transaction verifies that no other transaction has modified the data it has read. If the check reveals conflicting modifications, the committing transaction rolls back and can be restarted.[1] Optimistic concurrency control was first proposed by H.T. Kung.[2]

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 contention for data resources is frequent, the cost of repeatedly restarting transactions hurts performance significantly; it is commonly thought that other concurrency control methods have better performance under these conditions. However, locking-based ("pessimistic") methods also can deliver poor performance because locking can drastically limit effective concurrency even when deadlocks are avoided.


  • OCC phases 1
  • Web usage 2
    • Examples 2.1
  • See also 3
  • References 4
  • External links 5

OCC phases

More specifically, OCC transactions involve these phases:

  • Begin: Record a timestamp marking the transaction's beginning.
  • Modify: Read database values, and tentatively write changes.
  • Validate: Check whether other transactions have modified data that this transaction has used (read or written). This includes transactions that completed after this transaction's start time, and optionally, transactions that are still active at validation time.
  • Commit/Rollback: If there is no conflict, make all changes take effect. If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible. Care must be taken to avoid a TOCTTOU bug, particularly if this phase and the previous one are not performed as a single atomic operation.

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 built-in OCC: The GET method returns an ETag for a resource and subsequent PUTs use the ETag value in the If-Match headers; while the first PUT will succeed, the second will not, as the value in If-Match is based on the first version of the resource.[3]

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.


See also


  1. ^ Johnson, Rohit (2003). "Common Data Access Issues". Expert One-on-One J2EE Design and Development. Wrox Press.  
  2. ^ Kung, H.T. (1981). "On Optimistic Methods for Concurrency Control". ACM Transactions on Database Systems. 
  3. ^ "Editing the Web - Detecting the Lost Update Problem Using Unreserved Checkout". W3C Note. 10 May 1999. 
  4. ^
  5. ^ "Bugzilla: FAQ: Administrative Questions". MozillaWiki. 11 April 2012. 
  6. ^ "Module ActiveRecord::Locking". Rails Framework Documentation. 
  7. ^ "Object Relational Mapping (GORM)". Grails Framework Documentation. 
  8. ^ "Transaction Processing". GT.M Programmers Guide UNIX Edition. 
  9. ^ "Tip 19 – How to use Optimistic Concurrency with the Entity Framework". MSDN Blogs. 19 May 2009. 
    • Most revision control systems support the "merge" model for concurrency, which is OCC.
  10. ^ "Transaction Concurrency - Optimistic Concurrency Control". Mimer Developers - Features. 26 February 2010. 
  11. ^ "The Datastore". What Is Google App Engine?. 27 August 2010. 
  12. ^ "Elasticsearch - Guide - Index API". Elasticsearch Guide. 22 March 2012. 
  13. ^ "Transactions - MonetDB". 16 January 2013. 
  14. ^ "Transactions in Redis". 

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.  
  • 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" ( 
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.