Optimistic concurrency control

From Wikipedia, the free encyclopedia

In computer science, in the field of databases, optimistic concurrency control, (OCC) is a concurrency control method used in relational databases without using locking. It is commonly referred to as optimistic locking, a misnomer.

Optimistic concurrency control is based on the assumption that most database transactions don't conflict with other transactions, allowing OCC to be as permissive as possible in allowing transactions to execute.

There are three phases in an OCC transaction:

  1. Read: The client reads values from the database, storing them to a private sandbox or cache that the client can then edit.
  2. Validate: When the client has completed editing of the values in its sandbox or cache, it initiates the storage of the changes back to the database. During validation, an algorithm checks if the changes to the data would conflict with either
    • already-committed transactions in the case of backward validation schemes, or
    • currently executing transactions in the case of forward validation schemes.
    If a conflict exists, a conflict resolution algorithm must be used to resolve the conflict somehow (ideally by minimizing the number of changes made by the user) or, as a last resort, the entire transaction can be aborted (resulting in the loss of all changes made by the user).
  3. Write: If there is no possibility of conflict, the transaction commits.

When conflicts are rare, validation can be done efficiently, leading to higher throughput than other concurrency control methods.[citation needed] However, if conflicts happen often, the cost of repeatedly restarting transactions, hurts performance significantly — other non-lock concurrency control methods have better performance when there are many conflicts.

The stateless nature of HTTP makes locking infeasible for web user interfaces.[citation needed] 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 expires.

OCC is a natural choice. It is simple to implement and avoids unnecessary waiting or silently overwritten records. Typically the form presented to the user 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.

  • MediaWiki's edit pages use OCC. The conflict resolution algorithm is described here.
  • Bugzilla uses OCC; conflicts are called "mid-air collisions". [1]
  • The Ruby on Rails framework has an API for OCC. [2]
  • Most revision control systems support the "merge" model for concurrency, which is OCC.
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.