summaryrefslogtreecommitdiff
path: root/sql/rpl_rli.h
diff options
context:
space:
mode:
authorKristian Nielsen <knielsen@knielsen-hq.org>2016-09-22 08:26:45 +0200
committerKristian Nielsen <knielsen@knielsen-hq.org>2016-10-14 23:15:58 +0200
commit19abe79fd15ab6d8ac0c2f65476bc3c7d29a008d (patch)
treef5a34e32e5bceba084584efb471c2ff7b369eed4 /sql/rpl_rli.h
parent50f19ca8099994e992e1b411c7c05287855a7bdd (diff)
downloadmariadb-git-19abe79fd15ab6d8ac0c2f65476bc3c7d29a008d.tar.gz
MDEV-7145: Delayed replication, intermediate commit.
Initial merge of delayed replication from MySQL git. The code from the initial push into MySQL is merged, and the associated test case passes. A number of tasks are still pending: 1. Check full test suite run for any regressions or .result file updates. 2. Extend the feature to also work for parallel replication. 3. There are some todo-comments about future refactoring left from MySQL, these should be located and merged on top. 4. There are some later related MySQL commits, these should be checked and merged. These include: e134b9362ba0b750d6ac1b444780019622d14aa5 b38f0f7857c073edfcc0a64675b7f7ede04be00f fd2b210383358fe7697f201e19ac9779879ba72a afc397376ec50e96b2918ee64e48baf4dda0d37d 5. The testcase from MySQL relies heavily on sleep and timing for testing, and seems likely to sporadically fail on heavily loaded test servers in buildbot or distro build farms. Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
Diffstat (limited to 'sql/rpl_rli.h')
-rw-r--r--sql/rpl_rli.h115
1 files changed, 101 insertions, 14 deletions
diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h
index 96c3e7c3fac..0c8f16a0d16 100644
--- a/sql/rpl_rli.h
+++ b/sql/rpl_rli.h
@@ -29,11 +29,6 @@ class Master_info;
class Rpl_filter;
-enum {
- LINES_IN_RELAY_LOG_INFO_WITH_DELAY= 5
-};
-
-
/****************************************************************************
Replication SQL Thread
@@ -78,11 +73,17 @@ public:
};
/*
- If flag set, then rli does not store its state in any info file.
- This is the case only when we execute BINLOG SQL commands inside
- a client, non-replication thread.
+ The SQL thread owns one Relay_log_info, and each client that has
+ executed a BINLOG statement owns one Relay_log_info. This function
+ returns zero for the Relay_log_info object that belongs to the SQL
+ thread and nonzero for Relay_log_info objects that belong to
+ clients.
*/
- bool no_storage;
+ inline bool belongs_to_client()
+ {
+ DBUG_ASSERT(sql_driver_thd);
+ return !sql_driver_thd->slave_thread;
+ }
/*
If true, events with the same server id should be replicated. This
@@ -194,6 +195,11 @@ public:
relay log and finishing (commiting) on another relay log. Case which can
happen when, for example, the relay log gets rotated because of
max_binlog_size.
+
+ Note: group_relay_log_name, group_relay_log_pos must only be
+ written from the thread owning the Relay_log_info (SQL thread if
+ !belongs_to_client(); client thread executing BINLOG statement if
+ belongs_to_client()).
*/
char group_relay_log_name[FN_REFLEN];
ulonglong group_relay_log_pos;
@@ -205,16 +211,17 @@ public:
*/
char future_event_master_log_name[FN_REFLEN];
-#ifdef HAVE_valgrind
- bool is_fake; /* Mark that this is a fake relay log info structure */
-#endif
-
/*
Original log name and position of the group we're currently executing
(whose coordinates are group_relay_log_name/pos in the relay log)
in the master's binlog. These concern the *group*, because in the master's
binlog the log_pos that comes with each event is the position of the
beginning of the group.
+
+ Note: group_master_log_name, group_master_log_pos must only be
+ written from the thread owning the Relay_log_info (SQL thread if
+ !belongs_to_client(); client thread executing BINLOG statement if
+ belongs_to_client()).
*/
char group_master_log_name[FN_REFLEN];
volatile my_off_t group_master_log_pos;
@@ -244,6 +251,15 @@ public:
bool sql_thread_caught_up;
void clear_until_condition();
+ /**
+ Reset the delay.
+ This is used by RESET SLAVE to clear the delay.
+ */
+ void clear_sql_delay()
+ {
+ sql_delay= 0;
+ }
+
/*
Needed for problems when slave stops and we want to restart it
@@ -474,8 +490,72 @@ public:
m_flags&= ~flag;
}
+ /**
+ Text used in THD::proc_info when the slave SQL thread is delaying.
+ */
+ static const char *const state_delaying_string;
+
+ bool flush();
+
+ /**
+ Reads the relay_log.info file.
+ */
+ int init(const char* info_filename);
+
+ /**
+ Indicate that a delay starts.
+
+ This does not actually sleep; it only sets the state of this
+ Relay_log_info object to delaying so that the correct state can be
+ reported by SHOW SLAVE STATUS and SHOW PROCESSLIST.
+
+ Requires rli->data_lock.
+
+ @param delay_end The time when the delay shall end.
+ */
+ void start_sql_delay(time_t delay_end)
+ {
+ mysql_mutex_assert_owner(&data_lock);
+ sql_delay_end= delay_end;
+ thd_proc_info(sql_driver_thd, state_delaying_string);
+ }
+
+ int32 get_sql_delay() { return sql_delay; }
+ void set_sql_delay(time_t _sql_delay) { sql_delay= _sql_delay; }
+ time_t get_sql_delay_end() { return sql_delay_end; }
+
private:
+
+ /**
+ Delay slave SQL thread by this amount, compared to master (in
+ seconds). This is set with CHANGE MASTER TO MASTER_DELAY=X.
+
+ Guarded by data_lock. Initialized by the client thread executing
+ START SLAVE. Written by client threads executing CHANGE MASTER TO
+ MASTER_DELAY=X. Read by SQL thread and by client threads
+ executing SHOW SLAVE STATUS. Note: must not be written while the
+ slave SQL thread is running, since the SQL thread reads it without
+ a lock when executing flush_relay_log_info().
+ */
+ int sql_delay;
+
+ /**
+ During a delay, specifies the point in time when the delay ends.
+
+ This is used for the SQL_Remaining_Delay column in SHOW SLAVE STATUS.
+
+ Guarded by data_lock. Written by the sql thread. Read by client
+ threads executing SHOW SLAVE STATUS.
+ */
+ time_t sql_delay_end;
+
+ /*
+ Before the MASTER_DELAY parameter was added (WL#344),
+ relay_log.info had 4 lines. Now it has 5 lines.
+ */
+ static const int LINES_IN_RELAY_LOG_INFO_WITH_DELAY= 5;
+
/*
Holds the state of the data in the relay log.
We need this to ensure that we are not in the middle of a
@@ -874,7 +954,14 @@ public:
};
-// Defined in rpl_rli.cc
+/**
+ Reads the relay_log.info file.
+
+ @todo This is a wrapper around Relay_log_info::init(). It's only
+ kept for historical reasons. It would be good if we removed this
+ function and replaced all calls to it by calls to
+ Relay_log_info::init(). /SVEN
+*/
int init_relay_log_info(Relay_log_info* rli, const char* info_fname);