Content deleted Content added
→Web usage: Grammar/formatting |
|||
(39 intermediate revisions by 23 users not shown) | |||
Line 1:
{{Short description|Concurrency control method}}
'''Optimistic concurrency control''' ('''OCC'''), also known as '''optimistic locking''', is a [[Non-lock concurrency control|non-locking 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.<ref>{{cite book | title = Expert One-on-One J2EE Design and Development | first = Rohit | last = Johnson | publisher = Wrox Press | year = 2003 | isbn = 978-0-7645-4385-2 | chapter = Common Data Access Issues |
OCC is generally used in environments with low [[Block contention|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
== Phases of optimistic concurrency control ==
▲More specifically, Optimistic concurrency control 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 [[
==Web usage==
Line 23 ⟶ 22:
* [[Bugzilla]] uses OCC; [[edit conflict]]s are called "mid-air collisions".<ref>{{cite web | url = https://wiki.mozilla.org/Bugzilla:FAQ#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 | title = Bugzilla: FAQ: Administrative Questions | work = MozillaWiki | date = 11 April 2012}}</ref>
* The [[Ruby on Rails]] framework has an API for OCC.<ref>{{cite web | url = http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html | title = Module ActiveRecord::Locking | work = Rails Framework Documentation}}</ref>
* The [[Grails (framework)|Grails]] framework uses OCC in its default conventions.<ref>{{cite web | url = http://grails.org/doc/1.0.x/guide/single.html#5.3.5%20Pessimistic%20and%20Optimistic%20Locking | title = Object Relational Mapping (GORM) | work = Grails Framework Documentation | url-status = dead |
* The [[GT.M]] database engine uses OCC for managing transactions<ref>{{cite web | url = http://tinco.pair.com/bhaskar/gtm/doc/books/pg/UNIX_manual/ch05s17.html | title = Transaction Processing | work = GT.M Programmers Guide UNIX Edition}}</ref> (even single updates are treated as mini-transactions).
* [[Microsoft]]'s [[Entity Framework]] (including Code-First) has built-in support for OCC based on a binary timestamp value.<ref>{{cite web | url =
* Most [[revision control]] systems support the "merge" model for concurrency, which is OCC.
* [[Mimer SQL]] is a [[DBMS]] that only implements optimistic concurrency control.<ref>{{cite web | url =
* [[Google App Engine]] data store uses OCC.<ref>{{cite web | url = http://code.google.com/appengine/docs/whatisgoogleappengine.html | title = The Datastore | work = What Is Google App Engine? | date = 27 August 2010}}</ref>
* The [[Apache Solr]] search engine supports OCC via the {{Mono|_version_}} field.<ref>{{cite web|url=https://lucene.apache.org/solr/guide/6_6/updating-parts-of-documents.html|title=Updating Parts of Documents|access-date=2018-06-28}}</ref>
* The [[Elasticsearch]] search engine
* [[CouchDB]] implements OCC through document revisions.<ref>{{cite web |
* The [[MonetDB]] [[Column-oriented DBMS|column-oriented]] [[database management system]]'s transaction management scheme is based on OCC.<ref>{{cite web | url = http://www.monetdb.org/Documentation/Manuals/SQLreference/Transactions | title = Transactions - MonetDB | date = 16 January 2013}}</ref>
* Most implementations of [[software transactional memory]] use OCC.{{citation needed|reason=Claim initially said optimistic locking, now says OCC, both claims unsourced|date=March 2019}}
* [[Redis]] provides OCC through WATCH command.<ref>{{cite web | url = http://redis.io/topics/transactions | title = Transactions in Redis }}</ref>
* [[Firebird (database server)|Firebird]] uses [[Multiversion concurrency control|Multi-generational architecture]] as an implementation of OCC for data management.{{
▲* [[Firebird (database server)|Firebird]] uses [[Multiversion concurrency control|Multi-generational architecture]] as an implementation of OCC for data management.{{cn|date = November 2020}}
* [[Amazon DynamoDB|DynamoDB]] uses conditional update as an implementation of OCC.<ref>{{cite web | url = https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.ConditionalUpdate| title = Working with Items and Attributes - Conditional Writes| access-date = 2 November 2020}}</ref>
* [[Kubernetes]] uses OCC when updating resources.<ref>{{cite web | url = https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#resource-operations-update | title = API Overview - Resource Operations| access-date = 3 November 2020}}</ref>
* [[YugabyteDB]] is a cloud-native database that primarily uses OCC.<ref>{{Cite web|last=Yugabyte|first=Team|title=Explicit locking {{!}} YugabyteDB Docs|url=https://docs.yugabyte.com/latest/architecture/transactions/explicit-locking/|access-date=2022-01-04|website=docs.yugabyte.com|language=en-us}}</ref>
* [[Firestore]] is a NoSQL database by [[Firebase]] that uses OCC in its transactions.
* [[Apache Iceberg]] uses OCC to update tables and run maintenance operations on them.
==See also==
Line 48 ⟶ 49:
==External links==
*{{cite journal|title=On optimistic methods for concurrency control|journal=ACM Transactions on Database Systems|date=June 1981|first=H. T.|last=Kung|author2=John T. Robinson|volume=6|issue=2|pages=213–226|doi=10.1145/319566.319567|citeseerx=10.1.1.101.8988|s2cid=61600099 }}
* 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}},
* {{cite conference | first = Andreas | last = Hollmann | title = Multi-Isolation: Virtues and Limitations |
{{DEFAULTSORT:Optimistic Concurrency Control}}
<!-- Categories -->
[[Category:Concurrency control]]
[[Category:Concurrency control algorithms]]
[[Category:Transaction processing]]
|