Skip to content

Instantly share code, notes, and snippets.

@n0ts
Created March 2, 2010 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0ts/319156 to your computer and use it in GitHub Desktop.
Save n0ts/319156 to your computer and use it in GitHub Desktop.
MySQL slave delay patch for MySQL 5.1.44
--- trunk/mysql/SOURCES/mysql-slave-delay-5.1.44.patch (rev 0)
+++ trunk/mysql/SOURCES/mysql-slave-delay-5.1.44.patch 2010-03-02 04:08:00 UTC (rev 71)
@@ -0,0 +1,84 @@
+diff -u mysql-5.1.44.bak/sql/mysqld.cc mysql-5.1.44/sql/mysqld.cc
+--- mysql-5.1.44.bak/sql/mysqld.cc 2010-02-04 20:39:50.000000000 +0900
++++ mysql-5.1.44/sql/mysqld.cc 2010-02-15 21:21:09.000000000 +0900
+@@ -523,6 +523,9 @@
+ ulong query_buff_size, slow_launch_time, slave_open_temp_tables;
+ ulong open_files_limit, max_binlog_size, max_relay_log_size;
+ ulong slave_net_timeout, slave_trans_retries;
++#if 1
++ulong slave_delay;
++#endif
+ ulong slave_exec_mode_options;
+ const char *slave_exec_mode_str= "STRICT";
+ ulong thread_cache_size=0, thread_pool_size= 0;
+@@ -5663,6 +5666,9 @@
+ OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT, OPT_RELAY_LOG_SPACE_LIMIT,
+ OPT_RELAY_LOG_PURGE,
+ OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
++#if 1
++ OPT_SLAVE_DELAY,
++#endif
+ OPT_SLAVE_TRANS_RETRIES, OPT_READONLY, OPT_DEBUGGING,
+ OPT_SORT_BUFFER, OPT_TABLE_OPEN_CACHE, OPT_TABLE_DEF_CACHE,
+ OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE,
+@@ -6983,6 +6989,12 @@
+ "Number of seconds to wait for more data from a master/slave connection before aborting the read.",
+ (uchar**) &slave_net_timeout, (uchar**) &slave_net_timeout, 0,
+ GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
++#if 1
++ {"slave_delay", OPT_SLAVE_DELAY,
++ "intentionally delay exection of slave sql thread by specified seconds",
++ (uchar**) &slave_delay, (uchar**) &slave_delay, 0,
++ GET_ULONG, REQUIRED_ARG, 0, 0, LONG_TIMEOUT, 0, 0, 0},
++#endif
+ {"slave_transaction_retries", OPT_SLAVE_TRANS_RETRIES,
+ "Number of times the slave SQL thread will retry a transaction in case "
+ "it failed with a deadlock or elapsed lock wait timeout, "
+Only in mysql-5.1.44.bak/sql: mysqld.cc.orig
+diff -u mysql-5.1.44.bak/sql/mysql_priv.h mysql-5.1.44/sql/mysql_priv.h
+--- mysql-5.1.44.bak/sql/mysql_priv.h 2010-02-04 20:39:50.000000000 +0900
++++ mysql-5.1.44/sql/mysql_priv.h 2010-02-15 21:20:16.000000000 +0900
+@@ -1960,6 +1960,9 @@
+ extern MYSQL_PLUGIN_IMPORT ulong max_connections;
+ extern ulong max_connect_errors, connect_timeout;
+ extern ulong slave_net_timeout, slave_trans_retries;
++#if 1
++extern ulong slave_delay;
++#endif
+ extern uint max_user_connections;
+ extern ulong what_to_log,flush_time;
+ extern ulong query_buff_size;
+Common subdirectories: mysql-5.1.44.bak/sql/share and mysql-5.1.44/sql/share
+diff -u mysql-5.1.44.bak/sql/slave.cc mysql-5.1.44/sql/slave.cc
+--- mysql-5.1.44.bak/sql/slave.cc 2010-02-04 20:39:51.000000000 +0900
++++ mysql-5.1.44/sql/slave.cc 2010-02-15 21:20:16.000000000 +0900
+@@ -2120,6 +2120,15 @@
+ log (remember that now the relay log starts with its Format_desc,
+ has a Rotate etc).
+ */
++#if 1
++ if (slave_delay > 0 && ev->when > 0) {
++ time_t ts = time(NULL);
++ int delay = ev->when + slave_delay - ts;
++ if (delay > 0) {
++ safe_sleep(thd, delay, (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
++ }
++ }
++#endif
+
+ thd->server_id = ev->server_id; // use the original server id for logging
+ thd->set_time(); // time the query
+diff -u mysql-5.1.44.bak/sql/sql_repl.cc mysql-5.1.44/sql/sql_repl.cc
+--- mysql-5.1.44.bak/sql/sql_repl.cc 2010-02-04 20:39:53.000000000 +0900
++++ mysql-5.1.44/sql/sql_repl.cc 2010-02-15 21:20:16.000000000 +0900
+@@ -1771,6 +1771,10 @@
+ (uchar*) &slave_load_tmpdir);
+ static sys_var_long_ptr sys_slave_net_timeout(&vars, "slave_net_timeout",
+ &slave_net_timeout);
++#if 1
++sys_var_long_ptr sys_slave_delay(&vars, "slave_delay",
++ &slave_delay);
++#endif
+ static sys_var_const sys_slave_skip_errors(&vars, "slave_skip_errors",
+ OPT_GLOBAL, SHOW_CHAR,
+ (uchar*) slave_skip_error_names);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment