diff --git a/reference/mysqlnd_ms/changes.xml b/reference/mysqlnd_ms/changes.xml
index 5b86a4b8b1..c5c779af89 100644
--- a/reference/mysqlnd_ms/changes.xml
+++ b/reference/mysqlnd_ms/changes.xml
@@ -103,6 +103,7 @@
Fabric the actual shard servers involved in a business transaction may not be known
in advance. Thus, manually controlling a transaction that spawns multiple shards becomes
difficult.
+ Please, be warned about current limitations.
diff --git a/reference/mysqlnd_ms/concepts.xml b/reference/mysqlnd_ms/concepts.xml
index 4d7b4de02d..da834337b4 100755
--- a/reference/mysqlnd_ms/concepts.xml
+++ b/reference/mysqlnd_ms/concepts.xml
@@ -385,7 +385,7 @@
- Transaction handling
+ Local transaction handling
Transaction handling is fundamentally changed.
An SQL transaction is a unit of work that is run on one database server. The
@@ -1433,7 +1433,8 @@ Transient error retries before error: 2
As of MySQL 5.6.5-m8 the MySQL server features built-in global transaction identifiers.
- The MySQL built-in global transaction ID feature is supported by PECL/mysqlnd_ms 1.3.0-alpha or
+ The MySQL built-in global transaction ID feature is supported by
+ PECL/mysqlnd_ms 1.3.0-alpha or
later. Neither are client-side transaction boundary monitoring nor any setup
activities required if using the server feature.
@@ -1447,7 +1448,7 @@ Transient error retries before error: 2
Idea and client-side emulation
- PECL/mysqlnd_ms can do client-side transparent global transaction ID injection.
+ PECL/mysqlnd_ms can do client-side transparent global transaction ID injection.
In its most basic form, a global transaction identifier is a counter which is
incremented for every transaction executed on the master. The counter is held
in a table on the master. Slaves replicate the counter table.
@@ -1491,7 +1492,8 @@ Transient error retries before error: 2
Client-side global transaction ID injection has shortcomings. The potential
- issues are not specific to PECL/mysqlnd_ms but are rather of general nature.
+ issues are not specific to PECL/mysqlnd_ms
+ but are rather of general nature.
@@ -1522,7 +1524,8 @@ Transient error retries before error: 2
Using server-side global transaction identifier
- Starting with PECL/mysqlnd_ms 1.3.0-alpha the MySQL 5.6.5-m8 or newer built-in global
+ Starting with PECL/mysqlnd_ms 1.3.0-alpha
+ the MySQL 5.6.5-m8 or newer built-in global
transaction identifier feature is supported. Use of the server feature lifts
all of the above listed limitations. Please, see the MySQL Reference Manual
for limitations and preconditions for using server built-in global transaction
@@ -1589,7 +1592,7 @@ Transient error retries before error: 2
systems, such as a database cluster. Global transaction identifiers can
be used for, for example, system wide identification of transactions,
global ordering of transactions, heartbeat mechanism and
- for checking the replication status of replicas. PECL/mysqlnd_ms, a clientside
+ for checking the replication status of replicas. PECL/mysqlnd_ms, a clientside
driver based software, does focus on using GTIDs for tasks that can be
handled at the client, such as checking the replication status of replicas
for asynchronous replication setups.
@@ -1602,15 +1605,17 @@ Transient error retries before error: 2
Version requirement
- The feature requires use of PECL/mysqlnd_ms 1.3.0-beta or later,
- and PECL/mysqlnd_qc 1.1.0-alpha or newer. PECL/mysqlnd_ms must be
+ The feature requires use of PECL/mysqlnd_ms 1.3.0-beta or later,
+ and PECL/mysqlnd_qc 1.1.0-alpha or newer.
+ PECL/mysqlnd_ms must be
compiled to support the feature. PHP 5.4.0 or newer is required.
Setup: extension load order
- PECL/mysqlnd_ms must be loaded before PECL/mysqlnd_qc, when using shared
+ PECL/mysqlnd_ms must be loaded before
+ PECL/mysqlnd_qc, when using shared
extensions.
@@ -1631,7 +1636,8 @@ Transient error retries before error: 2
Support for MySQL replication clusters (asynchronous primary copy) is the
- main focus of PECL/mysqlnd_ms. The slaves of a MySQL replication cluster
+ main focus of PECL/mysqlnd_ms.
+ The slaves of a MySQL replication cluster
may or may not reflect the latest updates from the master.
Slaves are asynchronous and can lag behind the master. A read from a slave
is eventual consistent from a cluster-wide perspective.
@@ -1648,13 +1654,14 @@ Transient error retries before error: 2
replace a remote database access with a local cache access to gain better possibility.
- As of PECL/mysqlnd_ms 1.3.0-beta the plugin is capable of transparently controlling
- PECL/mysqlnd_ms 1.1.0-alpha or newer to cache a read-only query if explicitly
- allowed by setting an appropriate quality of service through
- mysqlnd_ms_set_qos. Please, see the
+ As of PECL/mysqlnd_ms 1.3.0-beta the plugin is
+ capable of transparently controlling PECL/mysqlnd_ms 1.1.0-alpha
+ or newer to cache a read-only query if explicitly allowed by setting an
+ appropriate quality of service through mysqlnd_ms_set_qos. P
+ lease, see the
quickstart for a code example.
- Both plugins must be installed, PECL/mysqlnd_ms must be compiled to support the
- cache feature and PHP 5.4.0 or newer has to be used.
+ Both plugins must be installed, PECL/mysqlnd_ms
+ must be compiled to support the cache feature and PHP 5.4.0 or newer has to be used.
Applications have full control of cache usage and can request fresh data
@@ -1667,7 +1674,7 @@ Transient error retries before error: 2
relaxed to eventual consistency the cache can be used again.
- If caching is enabled for a read-only statement, PECL/mysqlnd_ms may inject
+ If caching is enabled for a read-only statement, PECL/mysqlnd_ms may inject
SQL hints to control caching
by PECL/mysqlnd_qc. It may modify the SQL statement it got from the application.
Subsequent SQL processors are supposed to ignore the SQL hints. A SQL hint is a
@@ -1735,7 +1742,7 @@ Transient error retries before error: 2
- Inject the appropriate SQL hints to enable caching by PECL/mysqlnd_qc.
+ Inject the appropriate SQL hints to enable caching by PECL/mysqlnd_qc.
@@ -1746,9 +1753,10 @@ Transient error retries before error: 2
- PECL/mysqlnd_qc is loaded after PECL/mysqlnd_ms by PHP. Thus, it will see
- all query modifications of PECL/mysqlnd_ms and cache the query if instructed
- to do so.
+ PECL/mysqlnd_qc is loaded after
+ PECL/mysqlnd_ms by PHP. Thus, it will see
+ all query modifications of PECL/mysqlnd_ms and cache
+ the query if instructed to do so.
@@ -2124,6 +2132,201 @@ mysqlnd_ms.disable_rw_split=1
help to reduce collision rates and thus improve performance.
+
+
+ XA/Distributed transactions
+
+ Version requirement
+
+ XA related functions have been introduced in PECL/mysqlnd_ms version 1.6.0-alpha.
+
+
+
+ Early adaptors wanted
+
+ The feature is currently under development. There may be issues and/or
+ feature limitations. Do not use in production environments, although
+ early lab tests indicate reasonable quality.
+
+
+ Please, contact the development team if you are interested in this feature.
+ We are looking for real life feedback to complement the feature.
+
+
+ Below is a list of some feature restrictions.
+
+
+ The feature is not yet compatible with the MySQL Fabric support . This limitation is soon to be lifted.
+ XA transaction identifier are currently restricted to numbers. This limitation will be lifted upon request, it is a simplification used during the initial implementation.
+
+
+
+
+
+ MySQL server restrictions
+
+ The XA support by the MySQL server has some restrictions. Most noteably,
+ the servers binary log may lack changes made by XA transactions in case
+ of certain errors. Please, see the MySQL manual for details.
+
+
+
+ XA/Distributed transactions can spawn multiple MySQL servers.
+ Thus, they may seem like a perfect
+ tool for sharded MySQL clusters, for example, clusters managed with MySQL Fabric.
+ PECL/mysqlnd_ms hides most of the SQL commands
+ to control XA transactions and performs automatic administrative tasks in cases
+ of errors, to provide the user with a comprehensive API. Users should
+ setup the plugin carefully and be well aware of server restrictions prior
+ to using the feature.
+
+
+
+ General pattern for XA transactions
+
+query("UPDATE some_table SET col_a = 1");
+...
+
+/* COMMIT */
+mysqlnd_ms_xa_commit($link, 1);
+?>
+]]>
+
+
+
+
+ XA transactions use the two-phase commit protocol. The two-phase commit
+ protocol is a blocking protocol. During the first phase participating servers
+ begin a transaction and the client carries out its work. This phase is followed
+ by a second voting phase. During voting, the servers first make a firm promise
+ that they are ready to commit the work even in case of their possible unexpected
+ failure. Should a server crash in this phase, it will still recall the aborted
+ transaction after recover and wait for the client to decide on whether
+ it shall be committed or rolled back.
+
+
+ Should a client that has initiated a global transaction crash after all the
+ participating servers gave their promise to be ready to commit, then the servers
+ must wait for a decision. The servers are not allowed to uniliterally decide on the
+ transaction.
+
+
+ A client crash or disconnect from a participant, a server crash or server error
+ during the fist phase of the protocol is uncritical. In most cases, the server
+ will forget about the XA transaction and its work is rolled back. Additionally,
+ the plugin tries to reach out to as many participants as it can to instruct
+ the server to roll back the work immediately. It is not possible to disable this implicit
+ rollback carried out by PECL/mysqlnd_ms in case of errors
+ during the first phase of the protocol. This design decision has been made to
+ keep the implementation simple.
+
+
+ An error during the second phase of the commit protocol can develop into a
+ more severe situation. The servers will not forget about
+ prepared but unfinished transactions in all cases. The plugin will not
+ attempt to solve these cases immediately but waits for optional background
+ garbage collection to ensure progress of the commit protocol. It is assumed
+ that a solution will take significant time as it may include waiting
+ for a participating server to recover from a crash. This time span may
+ be longer than a developer and end user expects when trying to commit a
+ global transaction with mysqlnd_ms_xa_commit. Thus,
+ the function returns with the unfinished global transaction still
+ requiring attention. Please, be warned that at this point, it is not yet
+ clear whether the global transaction will be committed or rolled back later on.
+
+
+ Errors during the second phase can be ignored, handled by yourself or solved
+ by the build-int garbage collection logic. Ignoring them is not recommended
+ as you may experience unfinished global transactions on your servers that block
+ resources virtually indefinetly. Handling the errors requires knowing the
+ participants, checking their state and issueing appropriate SQL commands on them.
+ There are no user API calls to expose this very information. You will have to
+ configure a state store and make the plugin record its actions in it to receive
+ the desired facts.
+
+
+ Please, see the
+ quickstart and
+ related plugin
+ configuration file settings for an example how to configure a state.
+ In addition to configuring a state store, you have to setup some SQL tables.
+ The table definitions are given in the description of the plugin configuration
+ settings.
+
+
+ Setting up and configuring a state store is also a precondition for using the
+ built-in garbage collection for XA transactions that fail during the
+ second commit phase. Recording information about ongoing XA transactions is
+ an unavoidable extra task. The extra task consists of updating the state
+ store after each and every operation that changes the state of the global transaction
+ itself (started, committed, rolled back, errors and aborts), the addition of
+ participants (host, optionally user and password required to connect) and any
+ changes to a participants state. Please note, depending on configuration and your
+ security policies, these recordings may be considered sensitive.
+ It is therefore recommended to restrict access to the state store. Unless the
+ state store itself becomes overloaded, writing the state information may contribute
+ noteworthy to the runtime but should overall be only a minor factor.
+
+
+ It is possible that the effort it takes to implement your own routines for handling
+ XA transactions that failed during the second commit phase exceeds the benefits
+ of using the XA feature of PECL/mysqlnd_ms in the first place.
+ Thus, the manual focussed on using the built-on garbage collection only.
+
+
+ Garbage collection can be triggered manually or automatically in the background.
+ You may want to call mysqlnd_ms_xa_gc immediately after
+ a commit failure to attempt to solve any failed but still open global transactions
+ as soon as possible. You may also decide to disable the automatic background
+ garbage collection, implement your own rule set for invoking the built-in
+ garbage collection and trigger it when desired.
+
+
+ By default the plugin will start the garbage collection with a certain probability
+ in the extensions internal RSHUTDOWN method. The request
+ shutdown is called after your script finished. Whether the garbage collection
+ will be triggered is determined by computing a random value between
+ 1...1000 and comparing it with the configuration setting
+ probability
+ (default: 5). If the setting is
+ greater or equal to the random value, the garbage collection will be triggered.
+
+
+ Once started, the garbage collection acts upon up to
+ max_transactions_per_run (default: 100) global transactions
+ recorded. Records include successfully finished but also unfinished XA
+ transactions. Records for successful transactions are removed and unfinished
+ transactions are attempted to be solved. There are no statistics that help
+ you finding the right balance between keeping garbage collection runs short
+ by limiting the number of transactions considered per run and preventing the garbage
+ collection to fall behind, resulting in many records.
+
+
+ For each failed XA transaction the garbage collection makes
+ max_retries (default: 5) attempts to finish it. After that
+ PECL/mysqlnd_ms gives up and the XA transaction must be
+ cleaned up by a human operator. There are two possible reasons for this. Either
+ a participating server crashed and has not become accessible again within
+ max_retries invocations of the garbage collection, or there
+ is a situation that the built-in garbage collection cannot cope with. Likely, the
+ latter would be considered a bug.
+
+
+ The function mysqlnd_ms_get_stats
+ provides some statistics on how many XA transactions have been started,
+ committed, failed or rolled back.
+
+
+
+