Date

In preparation for the MySQL UC and my session about binlogs I started to implement a first few ideas. In a short coding rush I moved some of the C-code from mysql-binlog-dump.c to the right places in the libraries and wrapped it nicely for Lua.

My overall goal is to make a clean cut between

  • a library to work with binlogs
  • wrapping with for Lua's use
  • a front-end that's making use of all of it

With code in hands I can now toss in a liitle lua script to dump a simple statement-based binlog:

local binlog = assert(require("mysql.binlog"))
local basedir = "/usr/local/mysql/data/"
local file    = "jan-kneschkes-macbook-pro-bin.001005"

while file do
    local f = assert(binlog.open(basedir .. file))

    file = nil

    for event in f:next() do
            if event.type == "QUERY_EVENT" then
                    print(("/* threadid: %d */ %s"):format(
                            event.query.thread_id,
                            event.query.query))
            elseif event.type == "ROTATE_EVENT" then
                    print(("/* rotate to: %s */"):format(
                            event.rotate.binlog_file))
                    file = event.rotate.binlog_file -- rotate to the next binlog
            elseif event.type == "XID_EVENT" then
                    print(("COMMIT /* xid = %d */"):format(event.xid.xid_id))
            elseif event.type == "FORMAT_DESCRIPTION_EVENT" then
                    print(("/* version: %d from %s created at %d */"):format(
                            event.format.binlog_version, 
                            event.format.master_version, 
                            event.format.created_ts))
            end
    end

    f:close()
end

Just a little code to run through all the rotated binlogs and dump them.

If you want you can add your own filters, toss out records and just analyse the binlogs.

Next step is finishing the row-based support making it easier to work with them.


Comments

Enable javascript to load comments.