List:Internals« Previous MessageNext Message »
From:Sasha Pachev Date:February 15 2001 3:18pm
Subject:Re: transparent query direction
View as plain text  
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
       <___/                  
Thread
transparent query directionHroi Sigurdsson14 Feb
  • Re: transparent query directionRussell E Glaue14 Feb
  • Re: transparent query directionSasha Pachev15 Feb
    • Re: transparent query directionHroi Sigurdsson15 Feb
      • Re: transparent query directionPaul Repacholi15 Feb
      • Re: transparent query directionSasha Pachev15 Feb
    • Re: transparent query directionJeremy D. Zawodny15 Feb
      • Re: transparent query directionSasha Pachev15 Feb
        • Re: transparent query directionPaul Repacholi15 Feb
          • Re: transparent query directionSasha Pachev15 Feb
            • Re: transparent query directionPaul Repacholi16 Feb
        • Re: transparent query directionJeremy D. Zawodny21 Feb
          • Re: transparent query directionSasha Pachev21 Feb
            • Re: transparent query directionHroi Sigurdsson21 Feb
              • Re: transparent query directionSasha Pachev21 Feb
                • Re: transparent query directionHroi Sigurdsson21 Feb
                  • Re: transparent query directionSasha Pachev22 Feb
                    • Re: transparent query directionMichael Widenius3 Mar
                      • Re: transparent query directionSasha Pachev5 Mar
  • Re: transparent query directionPaul Cadach5 Mar
    • Re: transparent query directionSasha Pachev5 Mar
  • Re: transparent query directionPaul Cadach5 Mar
    • Re: transparent query directionSasha Pachev5 Mar
  • Re: transparent query directionPaul Cadach6 Mar
  • Re: transparent query directionPaul Cadach7 Mar
  • Re: transparent query directionPaul Cadach7 Mar
  • Re: transparent query directionPaul Cadach7 Mar
Re: transparent query directionMichael Widenius5 Mar
Re: transparent query directionHeikki Tuuri7 Mar