Content deleted Content added
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5 |
|||
(32 intermediate revisions by 27 users not shown) | |||
Line 1:
{{Short description|Operation that applies a set of distinct changes as a single operation}}
The problem with atomic commits is that they require coordination between multiple systems.<ref>{{cite book |last=Bocchi |first=Wischik |title=A Process Calculus of Atomic Commit |year=2004}}</ref> As computer networks are unreliable services, this means no algorithm can coordinate with all systems as proven in the [[Two Generals' Problem|Two Generals Problem]]. As databases become more and more distributed, this coordination will increase the difficulty of making truly atomic commits.<ref>{{cite book |first1=Hector |last1=Garcia-Molina |first2=Jeff |last2=Ullman |first3=Jennifer |last3=Widom |title=Database Systems The Complete Book |url=https://archive.org/details/databasesystemsc0000_2ndedgarc |url-access=registration |pages=
==Usage==
Atomic commits are essential for multi-step updates to data. This can be clearly shown in a simple example of a money transfer between two checking accounts.<ref>{{Cite book |first1=Hector |last1=Garcia-Molina |first2=Jeff |last2=Ullman |first3=Jennifer |last3=Widom |title=Database Systems The Complete Book |url=https://archive.org/details/databasesystemsc0000_2ndedgarc |url-access=registration |page=[https://archive.org/details/databasesystemsc0000_2ndedgarc/page/299 299] |publisher=Prentice Hall |year=2009|isbn=9780131873254 }}</ref>
This example is complicated by a transaction to check the balance of account Y during a transaction for transferring 100 dollars from account X to Y. To start, first 100 dollars is removed from account X. Second, 100 dollars is added to account Y. If the entire operation is not completed as one atomic commit, then several problems could occur. If the system fails in the middle of the operation, after removing the money from X and before adding into Y, then 100 dollars has just disappeared. Another issue is if the balance of Y is checked before the 100 dollars is added
With atomic commits neither of these cases can happen, in the first case of the system failure, the atomic commit would be rolled back and the money returned to X. In the second case, the request of the balance of Y cannot occur until the atomic commit is fully completed.
==Database
Atomic commits in database systems fulfil two of the key properties of [[ACID]],<ref>{{cite book |last=Elmasri |first=Ramez |title=Fundamentals of Database Systems 5th Edition |page=620 |publisher=Addison Wesley |year=2006}}</ref> [[Atomicity (database systems)|atomicity]] and [[Consistency (database systems)|consistency]]. Consistency is only achieved if each change in the atomic commit is consistent.
Line 18:
The two-phase commit protocol requires a coordinator to maintain all the information needed to recover the original state of the database if something goes wrong. As the name indicates there are two phases, <u>voting</u> and <u>commit</u>.
During the <u>voting</u> phase each node writes the changes in the atomic commit to its own disk. The nodes then report their status to the coordinator. If any node does not report to the coordinator or their status message is lost the coordinator assumes the
During the <u>commit</u> phase the coordinator sends a commit message to each of the nodes to record in their individual logs. Until this message is added to a node's log, any changes made will be recorded as incomplete. If any of the nodes reported a failure the coordinator will instead send a rollback message. This will remove any changes the nodes have written to disk.<ref>{{cite book |last=Elmasri |first=Ramez |title=Fundamentals of Database Systems 5th Edition |page=688 |publisher=Addison Wesley |year=2006}}</ref><ref>{{cite book |first1=Philip A. |last1=Bernstein |first2=Vassos |last2=Hadzilacos |first3=Nathan |last3=Goodman |title=Concurrency Control and Recovery in Database Systems |chapter=Chapter 7 |publisher=Addison Wesley Publishing Company |year=1987 |url=http://research.microsoft.com/en-us/people/philbe/ccontrol.aspx}}</ref>
The three-phase commit protocol seeks to remove the main problem with the two phase commit protocol, which occurs if a coordinator and another node fail at the same time during the commit phase neither can tell what action should occur. To solve this problem a third phase is added to the protocol. The <u>prepare to commit</u> phase occurs after the <u>voting</u> phase and before the <u>commit</u> phase.
In the <u>voting</u> phase, similar to the two-phase commit, the coordinator requests that each node is ready to commit. If any node fails the coordinator will timeout while waiting for the failed node. If this happens the coordinator sends an abort message to every node. The same action will be undertaken if any of the nodes return a failure message.
Line 31:
commit message to each node. When each node receives this message it performs the actual commit. If the commit message does not reach a node due to the message being lost or the coordinator fails they will perform the commit if the timeout expires. If the coordinator fails upon recovery it will send a commit message to each node.<ref>{{cite book |first=Srinivas R. |last=Gaddam |title=Three-Phase Commit Protocol |url=http://ei.cs.vt.edu/~cs5204/fall99/distributedDBMS/sreenu/3pc.html}}</ref>
==Revision
Atomic commits are a common feature of [[revision control|version control software]], and crucial for maintaining a consistent state in the repository.<ref name="levenberg">{{cite web |last1=Levenberg |first1=Rachel Potvin, Josh |title=Why Google Stores Billions of Lines of Code in a Single Repository|url=https://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext |website=Communications of the ACM |accessdate=20 July 2018|date=July 2016}}</ref> Most version control software will not apply any part of a commit that fails. Notable exceptions are [[Concurrent Versions System|CVS]], [[Microsoft Visual SourceSafe|VSS]] and [[IBM Rational ClearCase]] (when in UCM mode).<ref>{{cite book |last1=Smart |first1=John Ferguson |title=Java Power Tools |date=2008 |publisher="O'Reilly Media, Inc." |isbn=9781491954546 |page=301 |url=https://books.google.com/books?id=kE0UDQAAQBAJ&q=visual+sourcesafe+atomic+commit&pg=PA301 |accessdate=26 July 2018 |language=en}}</ref>
For instance, if version control software encounters a [[Edit conflict|merge conflict]] that can not be automatically resolved, then no part of the [[changeset]] is merged. Instead, the developer is given an opportunity to either revert their changes or manually resolve the conflict.
This prevents the entire project from entering a broken state due to a partially applied change set, where one file from a commit is successfully committed, but another file with dependent changes fails.<ref name="versperman">{{cite book |last1=Vesperman |first1=Jennifer |title=Essential CVS. |date=2009 |publisher=O'Reilly Media, Inc. |___location=Sebastopol |isbn=9780596551407 |page=7 |edition=2nd |url=https://books.google.com/books?id=nIMNLXCBjn0C&q=atomic+commit+cvs&pg=PA7|quote=A feature that CVS doesn't have, and that many teams like, is atomic commits. This feature ensures that while one person is committing changes to the repository, no one else can. Thus, each commit is a separate process, and the repository is never in a state where it has mismatched files.}}</ref>
Atomic commits may also refer to the ability to simultaneously make changes across multiple projects using version control software in a single operation, using a version control software development strategy known as a [[monorepo]].<ref name="levenberg" />
▲==Atomic Commit Convention==
When using a revision control systems a common convention is to use small commits. These are sometimes referred to as atomic commits as they (ideally) only affect a single aspect of the system. These atomic commits allow for greater understandability, less effort to roll back changes, easier bug identification.<ref>{{cite web |publisher=Apache |title=Subversion Best Practices |url=http://svn.apache.org/repos/asf/subversion/trunk/doc/user/svn-best-practices.html}}</ref>
The greater understandability comes from the small size and focused nature of the commit. It is much easier to understand what is changed and reasoning behind the changes if
If only atomic commits are made then commits that introduce errors become much simpler to identify.
Atomic commits also allow bug fixes to be easily reviewed if only a single bug
==See also==
Line 57 ⟶ 60:
[[Category:Transaction processing]]
[[Category:
[[Category:Distributed computing problems]]
|