MySQL, High Availability and other goodies…

Ruby Succinctness competition

For some reason I never was that excited about trying to accomplish these sorts of things in Perl:

1..rand(256)).inject("") {|string,n| string + ('a'..'z').to_a[rand(25)] }

This generates a string from 1 to 256 characters long, containing random letters from 'a' to 'z'.  

Normally, I wouldn't use something that's quite so unreadable, but I'm starting to like Ruby's way of taking what should be a very simple operation that I might have done in 3-5 lines in Perl and boiling it down to a single line.

Read more →

Event Scheduling reliability

I created my Events to handle adding new partitions (and removing old ones) from my log table and they seem to be working.  However, today I noticed that the events ran a few hours later than they ran yesterday.  

          EVENT_TYPE: RECURRING
          EXECUTE_AT: NULL
      INTERVAL_VALUE: 1
      INTERVAL_FIELD: DAY
            SQL_MODE: 
              STARTS: 2008-02-13 05:36:21
                ENDS: NULL
              STATUS: ENABLED
       ON_COMPLETION: NOT PRESERVE
             CREATED: 2008-02-13 05:36:21
        LAST_ALTERED: 2008-02-13 05:36:21
       LAST_EXECUTED: 2008-02-14 07:32:22

My addpartition event is current date dependent: it creates a partition for tomorrow hopefully before tomorrow comes so we don't miss a partition and so my INSERTs don't get "No partition" errors.  So if it waits a few extra hours more each day, gradually it will push past midnight and screw things up.  

I couldn't find any information about how this computation is actually made in the online documentation.  I was expecting this to be a little more exact.  

Can anyone shed a little more light on this?  
Read more →

Using Events to manage a Table Partitioned by Date

I want to create a log table in 5.1 that is partitioned by day.  I want to roll-off old data and create new partitions for each day automatically.  Without writing a script and a cronjob, it seems like this should be possible with Events.  Let's start with the table:

create table log (
    logged datetime not null,
    id int not null auto_increment,
    text varchar(256),
    PRIMARY KEY ( logged, id )
)
PARTITION BY RANGE( TO_DAYS( logged ) ) (
    PARTITION p20080206 VALUES LESS THAN (733444),
    PARTITION p20080207 VALUES LESS THAN (733445),
    PARTITION p20080208 VALUES LESS THAN (733446)
);
Read more →

Implementing a Replication precacher

I've completed a beta implementation of my take on the replication pre-cache tool. Sorry — nothing to download yet; I have to get it through an internal committee at Yahoo before I can release it (and you can imagine things are kind of crazy here). I wrote it myself because:

  1. I had it mostly done before I found out there were other versions out there
  2. I have to maintain it inside of Yahoo anyway
  3. I wanted to learn Ruby 🙂

It's just over 250 lines of Ruby, my new favourite language and fairly compact. It doesn't use the Ruby Mysql library, rather just IO.popen calls to the mysql command line client. I did this for two reasons:

  1. I haven't figured out the “right” way to deploy ruby gems at Yahoo yet (it's complicated).
Read more →

MyQ Gadgets 0.0.6 released

Thanks to those who tried it out and left feedback, much appreciated.

  • Changed /usr/local/bin/perl to /usr/bin/env perl to make the open source crowd happy.  Make sure the proper perl directory is first in your $PATH    
  • Made the usage string contain the valid modes in myq_status
  • Added check for mysql binary in MySQL_Script_Utils.pm
  • Quoted the --password option in MySQL_Script_Utils.pm to handle passwords with strange characters in them.
  • Setup default options string to be clearer which options are available to the scripts (like -? and -d)
  • Bumped the minimum repeat time for myq_status down to 1 second.  Note that it still might take more than 1 second for the check to run.
Read more →