ReplicationFeatures/ScriptableReplication
Contents |
[edit] SCRIPTABLE REPLICATION
Developed by the MySQL Replication Team.
Feature preview to add the ability to execute Lua scripts as part of the replication process.
[edit] Provides:
This feature provides the ability to execute Lua scripts at various stages of the replication process. Currently, it is only possible to investigate the events and filter them out, but more advanced abilities to manipulate the replication events or the replication stream (for example, by adding new events) will be added in the future.
[edit] Use case:
- Filter events based on complex criteria
- Allow more complicated processing to be done, for example:
- Connect to the server through a dedicated client connection and execute statements based on events seen
- Log queries to separate files
[edit] User interface:
The Lua code to be executed is placed in separate modules for the binary log and the relay log. Each module then define the functions that are executed whenever an event is seen. The module for the binary log is replication.binary_log and the module for the relay log is replication.relay_log.
Modules are searched for under either the /etc/mysql/ext directory or the basdir/ext directory. Modules are organized hieraracly so that the replication.binary_log module is in the ext/replication/binary_log.lua file and the replication.relay_log module is placed correspondingly.
Place any code that should be executed when writing events to or reading events from the binary log in the replication.binary_log module.
Before writing an event to the binary log or relay log, the corresponding before_write function is called with a userdata object representing the event as parameter. If the function returns a value convertible to true, the event will be skipped, otherwise, it will be written to the binary log or relay log respectively.
After having read an event from the binary log or relay log, the corresponding after_read function is called with a userdata object representing the event as a parameter. If the function returns a value convertible to true, the event will be discarded. Otherwise, it is processed furthr, i.e., either sent to the slave or applied to the database depending on the module.
A short example of a module definition for the binary log to filter out all query log events containing the word "windows" is:
module(..., package.seeall)
function after_read(event)
local m = event.query
if m then
return string.match(m, "windows")
else
return false
end
end
[edit] References:
- http://www.lua.org/manual/5.1/
- http://luaforge.net/projects/luasql/
- WL#4008 Scriptable replication threads
[edit] Downloads:
- Linux binary: http://downloads.mysql.com/forge/replication_features_preview/mysql-5.1.24-rpl-lua-linux-i686.tar.gz
- Source code: Not yet here