Author: mcbrown
Date: 2007-08-21 12:49:46 +0200 (Tue, 21 Aug 2007)
New Revision: 7491
Log:
Added the connect_server() description and example
Modified:
trunk/refman-common/mysql-proxy.xml
Modified: trunk/refman-common/mysql-proxy.xml
===================================================================
--- trunk/refman-common/mysql-proxy.xml 2007-08-21 10:09:49 UTC (rev 7490)
+++ trunk/refman-common/mysql-proxy.xml 2007-08-21 10:49:46 UTC (rev 7491)
Changed blocks: 5, Lines Added: 42, Lines Deleted: 1; 2505 bytes
@@ -1467,8 +1467,45 @@
<title>Capturing a connection with <literal>connect_server()</literal></title>
- <para></para>
+ <para>
+ When the proxy accepts a connection from a MySQL client, the
+ <function>connect_server()</function> function is called.
+ </para>
+ <para>
+ There are no arguments to the function, but you can use and if
+ necessary manipulate the information in the
+ <literal>proxy.connection</literal> table, which is unique to
+ each client session.
+ </para>
+
+ <para>
+ For example, if you have multiple backend servers then you can
+ set the server to be used by that connection by setting the
+ value of <literal>proxy.connection.backend_ndx</literal> to a
+ valid server number. The code below will choose between two
+ servers based on whether the current time in minutes is odd or
+ even:
+ </para>
+
+<programlisting>function connect_server()
+ print("--> a client really wants to talk to a server")
+ if (tonumber(os.date("%M")) % 2 == 0) then
+ proxy.connection.backend_ndx = 2
+ print("Choosing backend 2")
+ else
+ proxy.connection.backend_ndx = 1
+ print("Choosing backend 1")
+ end
+ print("Using " .. proxy.servers[proxy.connection.backend_ndx].address)
+end</programlisting>
+
+ <para>
+ In this example the IP address/port combination is also
+ displayed by accessing the information from the internal
+ <literal>proxy.servers</literal> table.
+ </para>
+
</section>
<section id="mysql-proxy-scripting-read-handshake">
@@ -1990,6 +2027,7 @@
</para>
</note>
+<!--
<para>
You can control how clients are distributed among backend servers,
for example, choosing slaves in a master/slave replication
@@ -2038,6 +2076,7 @@
<xref
linkend="mysql-proxy-using-customresultset"/>.
</para>
+-->
<section id="mysql-proxy-using-admin">
@@ -2095,6 +2134,7 @@
</section>
+<!--
<section id="mysql-proxy-using-connfilter">
<title>Using MySQL Proxy to Filter Connections</title>
@@ -2154,6 +2194,7 @@
</para>
</section>
+-->
</section>
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r7491 - trunk/refman-common | mcbrown | 21 Aug |