php-doc-en/reference/mysqlnd_ms/constants.xml
2014-09-16 08:03:52 +00:00

326 lines
9.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<appendix xml:id="mysqlnd-ms.constants" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.constants;
&extension.constants;
<para>
<emphasis role="bold">SQL hint related</emphasis>
</para>
<para>
<example>
<title>Example demonstrating the usage of mysqlnd_ms constants</title>
<para>
The mysqlnd replication and load balancing plugin (<literal>mysqlnd_ms</literal>)
performs read/write splitting. This directs write queries to a MySQL
master server, and read-only queries to the MySQL slave servers.
The plugin has a built-in read/write split logic.
All queries which start with <literal>SELECT</literal> are considered read-only
queries, which are then sent to a MySQL slave server that is listed in
the plugin configuration file. All other queries are directed to the
MySQL master server that is also specified in the plugin configuration file.
</para>
<para>
User supplied SQL hints can be used to overrule automatic read/write splitting,
to gain full control on the process. SQL hints are standards compliant
SQL comments. The plugin will scan the beginning of a query string for
an SQL comment for certain commands, which then control query redirection.
Other systems involved in the query processing are unaffected by the
SQL hints because other systems will ignore the SQL comments.
</para>
<para>
The plugin supports three SQL hints to direct queries to either the MySQL slave
servers, the MySQL master server, or the last used MySQL server. SQL hints
must be placed at the beginning of a query to be recognized by the plugin.
</para>
<para>
For better portability, it is recommended to use the string constants
<constant>MYSQLND_MS_MASTER_SWITCH</constant>,
<constant>MYSQLND_MS_SLAVE_SWITCH</constant> and
<constant>MYSQLND_MS_LAST_USED_SWITCH</constant> instead of their literal
values.
</para>
<programlisting role="php">
<![CDATA[
<?php
/* Use constants for maximum portability */
$master_query = "/*" . MYSQLND_MS_MASTER_SWITCH . "*/SELECT id FROM test";
/* Valid but less portable: using literal instead of constant */
$slave_query = "/*ms=slave*/SHOW TABLES";
printf("master_query = '%s'\n", $master_query);
printf("slave_query = '%s'\n", $slave_query);
?>
]]>
</programlisting>
&examples.outputs;
<screen>
<![CDATA[
master_query = /*ms=master*/SELECT id FROM test
slave_query = /*ms=slave*/SHOW TABLES
]]>
</screen>
</example>
</para>
<para>
<variablelist>
<varlistentry xml:id="constant.mysqlnd-ms-master-switch">
<term>
<constant>MYSQLND_MS_MASTER_SWITCH</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
SQL hint used to send a query to the MySQL replication master server.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-slave-switch">
<term>
<constant>MYSQLND_MS_SLAVE_SWITCH</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
SQL hint used to send a query to one of the MySQL replication slave servers.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-last-used-switch">
<term>
<constant>MYSQLND_MS_LAST_USED_SWITCH</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
SQL hint used to send a query to the last used MySQL server. The last
used MySQL server can either be a master or a slave server in a
MySQL replication setup.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<function>mysqlnd_ms_query_is_select</function>
related
</para>
<para>
<variablelist>
<varlistentry xml:id="constant.mysqlnd-ms-query-use-master">
<term>
<constant>MYSQLND_MS_QUERY_USE_MASTER</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
If <function>mysqlnd_ms_is_select</function> returns
<constant>MYSQLND_MS_QUERY_USE_MASTER</constant> for a given query, the
built-in read/write split mechanism recommends sending the query to
a MySQL replication master server.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-query-use-slave">
<term>
<constant>MYSQLND_MS_QUERY_USE_SLAVE</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
If <function>mysqlnd_ms_is_select</function> returns
<constant>MYSQLND_MS_QUERY_USE_SLAVE</constant> for a given query, the
built-in read/write split mechanism recommends sending the query to
a MySQL replication slave server.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-query-use-last-used">
<term>
<constant>MYSQLND_MS_QUERY_USE_LAST_USED</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
If <function>mysqlnd_ms_is_select</function> returns
<constant>MYSQLND_MS_QUERY_USE_LAST_USED</constant> for a given query, the
built-in read/write split mechanism recommends sending the query to
the last used server.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<function>mysqlnd_ms_set_qos</function>,
quality of service filter and service level related
</para>
<para>
<variablelist>
<varlistentry xml:id="constant.mysqlnd-ms-qos-consistency-eventual">
<term>
<constant>MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Use to request the service level eventual consistency from the
<function>mysqlnd_ms_set_qos</function>. Eventual consistency is the
default quality of service when reading from an asynchronous MySQL
replication slave. Data returned in this service level may or may not
be stale, depending on whether the selected slaves happen to have replicated
the latest changes from the MySQL replication master or not.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-qos-consistency-session">
<term>
<constant>MYSQLND_MS_QOS_CONSISTENCY_SESSION</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Use to request the service level session consistency from the
<function>mysqlnd_ms_set_qos</function>. Session consistency
is defined as read your writes. The client is guaranteed to see his
latest changes.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-qos-consistency-strong">
<term>
<constant>MYSQLND_MS_QOS_CONSISTENCY_STRONG</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Use to request the service level strong consistency from the
<function>mysqlnd_ms_set_qos</function>. Strong consistency
is used to ensure all clients see each others changes.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-qos-option-gtid">
<term>
<constant>MYSQLND_MS_QOS_OPTION_GTID</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Used as a service level option with
<function>mysqlnd_ms_set_qos</function> to parameterize session
consistency.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-qos-option-age">
<term>
<constant>MYSQLND_MS_QOS_OPTION_AGE</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Used as a service level option with
<function>mysqlnd_ms_set_qos</function> to parameterize eventual
consistency.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<emphasis role="bold">Other</emphasis>
</para>
<para>
The plugins version number can be obtained using
<constant>MYSQLND_MS_VERSION</constant> or
<constant>MYSQLND_MS_VERSION_ID</constant>.
<constant>MYSQLND_MS_VERSION</constant>
is the string representation of the numerical version number
<constant>MYSQLND_MS_VERSION_ID</constant>, which is an integer such as 10000.
Developers can calculate the version number as follows.
</para>
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Version (part)</entry>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry>Major*10000</entry>
<entry>1*10000 = 10000</entry>
</row>
<row>
<entry>Minor*100</entry>
<entry>0*100 = 0</entry>
</row>
<row>
<entry>Patch</entry>
<entry>0 = 0</entry>
</row>
<row>
<entry>MYSQLND_MS_VERSION_ID</entry>
<entry>10000</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
<variablelist>
<varlistentry xml:id="constant.mysqlnd-ms-version">
<term>
<constant>MYSQLND_MS_VERSION</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
Plugin version string, for example, <quote>1.0.0-prototype</quote>.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="constant.mysqlnd-ms-version-id">
<term>
<constant>MYSQLND_MS_VERSION_ID</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Plugin version number, for example, 10000.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</appendix>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->