Commit log

from Wikipedia, the free encyclopedia

Commit protocols regulate the writing down ( commit ) of data that is to be changed by a (distributed) transaction, for example in a database management system .

Necessity and requirements

The desirable properties of (distributed) transactions are defined by ACID . The commit protocol is responsible for ensuring these properties. Depending on the commit protocol, not all properties have to be fulfilled.

Basic principle

In order to meet their respective requirements, commit protocols describe how the processes participating in a transaction must communicate with one another via a coordinator, how information is recorded (logged) and finally how the data concerned is recorded. Various error situations are intercepted by the protocol, such as B. a crash of the coordinator during a phase (depending on the protocol).

variants

In distributed systems , a transaction often extends over several processes (also referred to as agents in this context ) that change data jointly and independently of one another. A distributed commit protocol is required here to ensure atomicity .

Two-phase commit protocols

The best-known procedure standardized via X / Open XA is the so-called "two-phase commit" or two-phase commit (2PC).

In the first phase of the protocol, a coordinator (usually the process that initiates the recording) obtains approval or rejection of the recording of the data changes from all processes involved (also known as the “coordination phase”). The coordinator only decides on "commit" if all participants agree, otherwise the decision is "rollback".

Once the decision has been made, the coordinator informs the participants of the result in the second phase (“commit phase”) of the protocol. According to this common result, either the entire transaction is reset, or all partial transactions are brought to a successful end by releasing the resources that have been blocked in the meantime.

algorithm

During the two phases, the following messages are exchanged between the participants:

Two-phase commit protocol: messages between coordinator and participant
  • Commit request phase
    1. The coordinator sends a prepare to all participants and waits for responses from all participants.
    2. The participants process the transaction to the point where the transaction is either committed or rolled back. You write entries in your undo log and in your redo log .
    3. The participants respond with ready if the transaction was successful - or they respond with failed if the transaction failed.
  • Commit phase:
    • When the coordinator has received a ready message from all participants :
      1. The coordinator sends commit to all participants.
      2. The participants complete the transaction with commit and release all locks and resources.
      3. The participants send back an acknowledgment .
      4. The coordinator ends the transaction when he has received confirmation from all participants.
    • If at least one of the participants sends a failed :
      1. The coordinator sends abort to all participants.
      2. The participants complete the transaction with rollback (using the undo log) and release all locks and resources.
      3. The participants send back an acknowledgment .
      4. The coordinator also ends the transaction with rollback when he has received confirmation from all participants.

The fundamental problem with two-phase commit is that participants are temporarily blocked . This happens as soon as a participant has communicated his or her local “commit” decision to the coordinator. Then the participant waits for the global (joint) decision. This becomes particularly problematic if the coordinator has been down in the meantime. In this situation, the participant can neither release the blocked resources nor roll back the local transaction. At most, the participant can find out about the global commit decision from another participant.

correctness

The 2PC protocol guarantees correctness even if one or more computers fail or if network partitions occur, so that communication between operable computers is prevented. Correctness means: It cannot happen that a transaction comes to different results with different participants.

Three-phase commit protocols

Numerous variants of the 2PC protocol are discussed in the specialist literature to reduce the number of logging processes required, the number of messages required and to increase robustness. For example, the so-called three-phase commit protocol ( 3PC ) aims to avoid the risk of blocking. This requires an increase in the number of message rounds so that if the coordinator fails in the meantime, the protocol can be completed by a new coordinator.

See also

Individual evidence

  1. ^ Alfons Kemper, André Eickler: Database systems . An introduction. 6th edition. Oldenbourg, Munich 2006, ISBN 978-3-486-57690-0 .