On Wednesday 14 February 2001 09:44, Hroi Sigurdsson wrote:
>Hello MySQL developers.
>
>We are looking into redirecting updates, inserts etc. directly on
>slave servers in a replicated set-up. Instead of having the clients
>figure out where to send updates, the slave will itself forward data
>manipulation queries to the master, wait for the same query from the
>master to arrive and complete, then return the result. The client will
>not know the difference (apart from the delay).
>
>What is the best place to start? We don't want to have a seperate
>proxy process doing the filtering, since authentication by ip address
>will then be impossible from the end-point's view (and to avoid the
>overhead).
>
>Can you point to some sections in the code that would be useful to
>look at? At which point in the code can we look at a query and
>determine whether it should be sent to the master? How are queries
>delimited?
>Is there a general overview/map of mysql server code/design on the
>web? The documentation was a little sparse on that area and I don't
>remember all that much of what was taught in your course (which was
>mostly about custom table handlers).
The cleanest way to do the above is to extend the client protocol, not just
the slave. We plan to do this in 4.0, however, if you cannot wait until we do
it, here is the basic outline:
* add a connection redirect response when redirect on update is requested to
COM_QUERY in the client protocol with mysql_query() automatically executing
the query on a different connection if it gets a redirect
* add the code in the slave to respond with a redirect to the current master
if the query is an update and redirect option is set
You should take a look at libmysql/libmysql.c ( client code), and
sql/sql_parse.cc ( server code). You may also need to follow some functioins
that are called from those file into other files to understand things better.
What you need to changes is mysql_real_query() to add requesting and handling
a redirect response, and in the switch statement in mysql_execute_command()
for SQLCOM_INSERT, SQLCOM_UPDATE, and others, add a check to see if there
glob_mi ( master info ) is initialized, and if it is and redirect is
requested, send a redirect instead of going on with the query. It would
probably be cleaner to just add a quick check before you even go into the
switch statement there.
--
MySQL Development Team
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Sasha Pachev <sasha@stripped>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, http://www.mysql.com/
/_/ /_/\_, /___/\___\_\___/ Provo, Utah, USA
<___/