Brad Fitzpatrick (brad) wrote,
Brad Fitzpatrick
brad

fake mysql server in perl

I just wrote a little Perl script that looks like a MySQL server. You connect to it, do the whole capability exchange (it has no modern capabilities like compression or SSL) and then it processes client packets... just QUIT or QUERY right now.

Oh, and it reports server version "1.2.3-yourmom" (for Whitaker).

Then in responds to queries:
bradfitz@bini:~$ mysql -hbrad -P3308
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1337 to server version: 1.2.3-yourmom

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select your_mom();
ERROR 1045: No access to my mom

Yup yup, workin' hard, workin' hard.

The real goal, of course, is twofold:

Goal 1) for our "global cluster" which is pretty small and all the data fits on a machine:

load balancing mysql proxy. track all machine's replication position and never direct selects to machines that aren't totally caught up. this way application thinks it's talking to a single machine, but really selects are load balanced without side-effects like out-of-date slaves. ideally then the proxies would communicate amongst themselves and elect a master, then the master would be able to do stuff like manage master election amongst the mysql machines, reparenting nodes against each other, copying their data around when a new node comes online, etc.

I think a dozen vendors do this, but what fun is that? Plus there should be some open source load-balancing mysql proxy out there.

Goal 2) for our user clusters which take a lot of disk space:

distributed database. that whole MogileFS + user per db thing, all users on 2 or 3 random machines, replication going crazy everywhere. the proxy would have to keep all their replication positions in sync.

Obviously goal 2 is a lot harder, so goal 1 is a good way to learn the MySQL protocol better and get something usable for most people (including ourselves) pretty quickly.
Tags: mysql, perl, tech
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 23 comments