<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="replication-semisync-interface">
      </a>
      19.4.10.2 Configuring Semisynchronous Replication
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045136179920">
  </a>
  <p>
   When you install the source and replica plugins for
        semisynchronous replication (see
   <a class="xref" href="replication-semisync-installation.html" title="19.4.10.1 Installing Semisynchronous Replication">
    Section 19.4.10.1, “Installing Semisynchronous Replication”
   </a>
   ), system
        variables become available to control plugin behavior.
  </p>
  <p>
   To check the current values of the status variables for
        semisynchronous replication, use
   <a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
    <code class="literal">
     SHOW
        VARIABLES
    </code>
   </a>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa29034999"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'rpl_semi_sync%'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   All the
   <code class="literal">
    rpl_semi_sync_
    <em class="replaceable">
     <code>
      xxx
     </code>
    </em>
   </code>
   system variables are described at
   <a class="xref" href="replication-options-source.html" title="19.1.6.2 Replication Source Options and Variables">
    Section 19.1.6.2, “Replication Source Options and Variables”
   </a>
   and
   <a class="xref" href="replication-options-replica.html" title="19.1.6.3 Replica Server Options and Variables">
    Section 19.1.6.3, “Replica Server Options and Variables”
   </a>
   . Some key system
        variables are:
  </p>
  <div class="variablelist">
   <dl class="variablelist">
    <dt>
     <span class="term">
      <a class="link" href="replication-options-source.html#sysvar_rpl_semi_sync_source_enabled">
       <code class="literal">
        rpl_semi_sync_source_enabled
       </code>
      </a>
     </span>
    </dt>
    <dd>
     <p>
      Controls whether semisynchronous replication is enabled on
              the source server. To enable or disable the plugin, set
              this variable to 1 or 0, respectively. The default is 0
              (off).
     </p>
    </dd>
    <dt>
     <span class="term">
      <a class="link" href="replication-options-replica.html#sysvar_rpl_semi_sync_replica_enabled">
       <code class="literal">
        rpl_semi_sync_replica_enabled
       </code>
      </a>
     </span>
    </dt>
    <dd>
     <p>
      Controls whether semisynchronous replication is enabled on
              the replica.
     </p>
    </dd>
    <dt>
     <span class="term">
      <a class="link" href="replication-options-source.html#sysvar_rpl_semi_sync_source_timeout">
       <code class="literal">
        rpl_semi_sync_source_timeout
       </code>
      </a>
     </span>
    </dt>
    <dd>
     <p>
      A value in milliseconds that controls how long the source
              waits on a commit for acknowledgment from a replica before
              timing out and reverting to asynchronous replication. The
              default value is 10000 (10 seconds).
     </p>
    </dd>
    <dt>
     <span class="term">
      <a class="link" href="replication-options-source.html#sysvar_rpl_semi_sync_source_wait_for_replica_count">
       <code class="literal">
        rpl_semi_sync_source_wait_for_replica_count
       </code>
      </a>
     </span>
    </dt>
    <dd>
     <p>
      Controls the number of replica acknowledgments the source
              must receive per transaction before returning to the
              session. The default is 1, meaning that the source only
              waits for one replica to acknowledge receipt of the
              transaction's events.
     </p>
    </dd>
   </dl>
  </div>
  <p>
   The
   <a class="link" href="replication-options-source.html#sysvar_rpl_semi_sync_source_wait_point">
    <code class="literal">
     rpl_semi_sync_source_wait_point
    </code>
   </a>
   system variable controls the point at which a semisynchronous
        source server waits for replica acknowledgment of transaction
        receipt before returning a status to the client that committed
        the transaction. These values are permitted:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       AFTER_SYNC
      </code>
      (the default): The source
            writes each transaction to its binary log and the replica,
            and syncs the binary log to disk. The source waits for
            replica acknowledgment of transaction receipt after the
            sync. Upon receiving acknowledgment, the source commits the
            transaction to the storage engine and returns a result to
            the client, which then can proceed.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       AFTER_COMMIT
      </code>
      : The source writes each
            transaction to its binary log and the replica, syncs the
            binary log, and commits the transaction to the storage
            engine. The source waits for replica acknowledgment of
            transaction receipt after the commit. Upon receiving
            acknowledgment, the source returns a result to the client,
            which then can proceed.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The replication characteristics of these settings differ as
        follows:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      With
      <code class="literal">
       AFTER_SYNC
      </code>
      , all clients see the
            committed transaction at the same time, which is after it
            has been acknowledged by the replica and committed to the
            storage engine on the source. Thus, all clients see the same
            data on the source.
     </p>
     <p>
      In the event of source failure, all transactions committed
            on the source have been replicated to the replica (saved to
            its relay log). An unexpected exit of the source and
            failover to the replica is lossless because the replica is
            up to date. As noted above, the source should not be reused
            after the failover.
     </p>
    </li>
    <li class="listitem">
     <p>
      With
      <code class="literal">
       AFTER_COMMIT
      </code>
      , the client issuing the
            transaction gets a return status only after the server
            commits to the storage engine and receives replica
            acknowledgment. After the commit and before replica
            acknowledgment, other clients can see the committed
            transaction before the committing client.
     </p>
     <p>
      If something goes wrong such that the replica does not
            process the transaction, then in the event of an unexpected
            source exit and failover to the replica, it is possible for
            such clients to see a loss of data relative to what they saw
            on the source.
     </p>
    </li>
   </ul>
  </div>
  <p>
   You can improve the performance of semisynchronous replication
        by enabling the system variables
   <a class="link" href="replication-options-replica.html#sysvar_replication_sender_observe_commit_only">
    <code class="literal">
     replication_sender_observe_commit_only
    </code>
   </a>
   ,
        which limits callbacks, and
   <a class="link" href="replication-options-replica.html#sysvar_replication_optimize_for_static_plugin_config">
    <code class="literal">
     replication_optimize_for_static_plugin_config
    </code>
   </a>
   ,
        which adds shared locks and avoids unnecessary lock
        acquisitions. These settings help as the number of replicas
        increases, because contention for locks can slow down
        performance. Semisynchronous replication source servers can also
        get performance benefits from enabling these system variables,
        because they use the same locking mechanisms as the replicas.
  </p>
 </div>
 <br/>
</div>
