← Back to team overview

mysql-proxy-discuss team mailing list archive

DB Splitting

 

Hi, list.

I 'm trying to implement query splitting based on a key word in query.
For example, we have 2 mysql servers: backend1 (master) and backend2
(slave), both are RW. If we get a query without a key word (let it be
'foobar') we should send it to backend1, if we get a query containing
the word 'foobar' we send it to backend2.
I've tried to do implement the schema using modified rw splitting
script, but the script becomes rather complex and it will be difficult
to support it in future and to explain to somebody (especially if he
sees LUA first time in his life) how it should work. So I need the
script to be as simple as possible (without connection pooling for
example). As far as I understand we should exam a query in the
'read_query' function:

 if string.match(string.lower (query), 'foobar')
            then use_slave = true
 end

And then we can send the query to backend2 (slave):

if proxy.global.backends[2].state ~= proxy.BACKEND_STATE_DOWN and use_db2 then
              proxy.connection.backend_ndx = 2
              print ("[foobar query, sending to backend] --> " ..
proxy.global.backends[2].dst.name)
end

Assuming that we start mysql-proxy in this way: mysql-proxy
--proxy-backend-addresses=backend1 --proxy-backend-addresses=backend2
--proxy-lua-script=/path/to/the/script.lua

Am I right? Any help is appreciated.

Thanks in advance,
Ilya.



Follow ups