<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="xa">
      </a>
      15.3.8 XA Transactions
     </h3>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="xa-statements.html">
       15.3.8.1 XA Transaction SQL Statements
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="xa-states.html">
       15.3.8.2 XA Transaction States
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="xa-restrictions.html">
       15.3.8.3 Restrictions on XA Transactions
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <a class="indexterm" name="idm46045178138944">
  </a>
  <p>
   Support for
   <a class="link" href="glossary.html#glos_xa" title="XA">
    XA
   </a>
   transactions is
      available for the
   <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
    <code class="literal">
     InnoDB
    </code>
   </a>
   storage
      engine. The MySQL XA implementation is based on the X/Open CAE
      document
   <em class="citetitle">
    Distributed Transaction Processing: The XA
      Specification
   </em>
   . This document is published by The Open
      Group and available at
   <a class="ulink" href="http://www.opengroup.org/public/pubs/catalog/c193.htm" target="_blank">
    http://www.opengroup.org/public/pubs/catalog/c193.htm
   </a>
   .
      Limitations of the current XA implementation are described in
   <a class="xref" href="xa-restrictions.html" title="15.3.8.3 Restrictions on XA Transactions">
    Section 15.3.8.3, “Restrictions on XA Transactions”
   </a>
   .
  </p>
  <p>
   On the client side, there are no special requirements. The XA
      interface to a MySQL server consists of SQL statements that begin
      with the
   <code class="literal">
    XA
   </code>
   keyword. MySQL client programs must
      be able to send SQL statements and to understand the semantics of
      the XA statement interface. They do not need be linked against a
      recent client library. Older client libraries also work.
  </p>
  <p>
   Among the MySQL Connectors, MySQL Connector/J 5.0.0 and higher
      supports XA directly, by means of a class interface that handles
      the XA SQL statement interface for you.
  </p>
  <p>
   XA supports distributed transactions, that is, the ability to
      permit multiple separate transactional resources to participate in
      a global transaction. Transactional resources often are RDBMSs but
      may be other kinds of resources.
  </p>
  <p>
   A global transaction involves several actions that are
      transactional in themselves, but that all must either complete
      successfully as a group, or all be rolled back as a group. In
      essence, this extends ACID properties
   <span class="quote">
    “
    <span class="quote">
     up a level
    </span>
    ”
   </span>
   so
      that multiple ACID transactions can be executed in concert as
      components of a global operation that also has ACID properties.
      (As with nondistributed transactions,
   <a class="link" href="innodb-transaction-isolation-levels.html#isolevel_serializable">
    <code class="literal">
     SERIALIZABLE
    </code>
   </a>
   may be preferred
      if your applications are sensitive to read phenomena.
   <a class="link" href="innodb-transaction-isolation-levels.html#isolevel_repeatable-read">
    <code class="literal">
     REPEATABLE READ
    </code>
   </a>
   may not be
      sufficient for distributed transactions.)
  </p>
  <p>
   Some examples of distributed transactions:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      An application may act as an integration tool that combines a
          messaging service with an RDBMS. The application makes sure
          that transactions dealing with message sending, retrieval, and
          processing that also involve a transactional database all
          happen in a global transaction. You can think of this as
      <span class="quote">
       “
       <span class="quote">
        transactional email.
       </span>
       ”
      </span>
     </p>
    </li>
    <li class="listitem">
     <p>
      An application performs actions that involve different
          database servers, such as a MySQL server and an Oracle server
          (or multiple MySQL servers), where actions that involve
          multiple servers must happen as part of a global transaction,
          rather than as separate transactions local to each server.
     </p>
    </li>
    <li class="listitem">
     <p>
      A bank keeps account information in an RDBMS and distributes
          and receives money through automated teller machines (ATMs).
          It is necessary to ensure that ATM actions are correctly
          reflected in the accounts, but this cannot be done with the
          RDBMS alone. A global transaction manager integrates the ATM
          and database resources to ensure overall consistency of
          financial transactions.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Applications that use global transactions involve one or more
      Resource Managers and a Transaction Manager:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A Resource Manager (RM) provides access to transactional
          resources. A database server is one kind of resource manager.
          It must be possible to either commit or roll back transactions
          managed by the RM.
     </p>
    </li>
    <li class="listitem">
     <p>
      A Transaction Manager (TM) coordinates the transactions that
          are part of a global transaction. It communicates with the RMs
          that handle each of these transactions. The individual
          transactions within a global transaction are
      <span class="quote">
       “
       <span class="quote">
        branches
       </span>
       ”
      </span>
      of the global transaction. Global
          transactions and their branches are identified by a naming
          scheme described later.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The MySQL implementation of XA enables a MySQL server to act as a
      Resource Manager that handles XA transactions within a global
      transaction. A client program that connects to the MySQL server
      acts as the Transaction Manager.
  </p>
  <p>
   To carry out a global transaction, it is necessary to know which
      components are involved, and bring each component to a point when
      it can be committed or rolled back. Depending on what each
      component reports about its ability to succeed, they must all
      commit or roll back as an atomic group. That is, either all
      components must commit, or all components must roll back. To
      manage a global transaction, it is necessary to take into account
      that any component or the connecting network might fail.
  </p>
  <p>
   The process for executing a global transaction uses two-phase
      commit (2PC). This takes place after the actions performed by the
      branches of the global transaction have been executed.
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      In the first phase, all branches are prepared. That is, they
          are told by the TM to get ready to commit. Typically, this
          means each RM that manages a branch records the actions for
          the branch in stable storage. The branches indicate whether
          they are able to do this, and these results are used for the
          second phase.
     </p>
    </li>
    <li class="listitem">
     <p>
      In the second phase, the TM tells the RMs whether to commit or
          roll back. If all branches indicated when they were prepared
          that they were able to commit, all branches are told to
          commit. If any branch indicated when it was prepared that it
          was not able to commit, all branches are told to roll back.
     </p>
    </li>
   </ol>
  </div>
  <p>
   In some cases, a global transaction might use one-phase commit
      (1PC). For example, when a Transaction Manager finds that a global
      transaction consists of only one transactional resource (that is,
      a single branch), that resource can be told to prepare and commit
      at the same time.
  </p>
 </div>
 <br/>
</div>
