My Project
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Friends
Relay_log_info Class Reference
Inheritance diagram for Relay_log_info:
Rpl_info Slave_reporting_capability

List of all members.

Public Types

enum  enum_state_flag { IN_STMT, STATE_FLAGS_COUNT }
enum  {
  UNTIL_NONE = 0, UNTIL_MASTER_POS, UNTIL_RELAY_POS, UNTIL_SQL_BEFORE_GTIDS,
  UNTIL_SQL_AFTER_GTIDS, UNTIL_SQL_AFTER_MTS_GAPS, UNTIL_DONE
}
enum  { UNTIL_LOG_NAMES_CMP_UNKNOWN = -2, UNTIL_LOG_NAMES_CMP_LESS = -1, UNTIL_LOG_NAMES_CMP_EQUAL = 0, UNTIL_LOG_NAMES_CMP_GREATER = 1 }
enum  { MTS_NOT_IN_GROUP, MTS_IN_GROUP, MTS_END_GROUP, MTS_KILLED_GROUP }

Public Member Functions

bool belongs_to_client ()
Gtidget_last_retrieved_gtid ()
void set_last_retrieved_gtid (Gtid gtid)
int add_logged_gtid (rpl_sidno sidno, rpl_gno gno)
const Gtid_setget_gtid_set () const
int init_relay_log_pos (const char *log, ulonglong pos, bool need_data_lock, const char **errmsg, bool look_for_description_event)
void clear_until_condition ()
void clear_sql_delay ()
void notify_group_relay_log_name_update ()
void notify_group_master_log_name_update ()
void inc_event_relay_log_pos ()
int inc_group_relay_log_pos (ulonglong log_pos, bool need_data_lock)
int wait_for_pos (THD *thd, String *log_name, longlong log_pos, longlong timeout)
int wait_for_gtid_set (THD *thd, String *gtid, longlong timeout)
void close_temporary_tables ()
bool is_until_satisfied (THD *thd, Log_event *ev)
ulonglong until_pos ()
bool get_table_data (TABLE *table_arg, table_def **tabledef_var, TABLE **conv_table_var) const
void cached_charset_invalidate ()
bool cached_charset_compare (char *charset) const
void cleanup_context (THD *, bool)
void slave_close_thread_tables (THD *)
void clear_tables_to_lock ()
int purge_relay_logs (THD *thd, bool just_reset, const char **errmsg)
void init_workers (ulong)
void deinit_workers ()
bool is_mts_recovery () const
void clear_mts_recovery_groups ()
bool is_parallel_exec () const
bool is_mts_in_group ()
void reset_notified_relay_log_change ()
void reset_notified_checkpoint (ulong, time_t, bool)
bool mts_finalize_recovery ()
void cleanup_after_query ()
void cleanup_after_session ()
int stmt_done (my_off_t event_log_pos)
void set_flag (enum_state_flag flag)
bool get_flag (enum_state_flag flag)
void clear_flag (enum_state_flag flag)
bool is_in_group () const
int count_relay_log_space ()
int rli_init_info ()
void end_info ()
int flush_info (bool force=FALSE)
int flush_current_log ()
void set_master_info (Master_info *info)
ulonglong get_future_event_relay_log_pos ()
void set_future_event_relay_log_pos (ulonglong log_pos)
const char * get_group_master_log_name ()
ulonglong get_group_master_log_pos ()
void set_group_master_log_name (const char *log_file_name)
void set_group_master_log_pos (ulonglong log_pos)
const char * get_group_relay_log_name ()
ulonglong get_group_relay_log_pos ()
void set_group_relay_log_name (const char *log_file_name)
void set_group_relay_log_name (const char *log_file_name, size_t len)
void set_group_relay_log_pos (ulonglong log_pos)
const char * get_event_relay_log_name ()
ulonglong get_event_relay_log_pos ()
void set_event_relay_log_name (const char *log_file_name)
void set_event_relay_log_name (const char *log_file_name, size_t len)
void set_event_relay_log_pos (ulonglong log_pos)
const char * get_rpl_log_name ()
ulonglong get_future_master_log_pos ()
void start_sql_delay (time_t delay_end)
int32 get_sql_delay ()
void set_sql_delay (time_t _sql_delay)
time_t get_sql_delay_end ()
 Relay_log_info (bool is_slave_recovery, uint param_id)
time_t get_row_stmt_start_timestamp ()
time_t set_row_stmt_start_timestamp ()
void reset_row_stmt_start_timestamp ()
void set_long_find_row_note_printed ()
void unset_long_find_row_note_printed ()
bool is_long_find_row_note_printed ()
virtual void set_rli_description_event (Format_description_log_event *fdle)
Format_description_log_eventget_rli_description_event () const
void adapt_to_master_version (Format_description_log_event *fdle)

Static Public Member Functions

static size_t get_number_info_rli_fields ()

Public Attributes

bool replicate_same_server_id
File cur_log_fd
MYSQL_BIN_LOG relay_log
LOG_INFO linfo
IO_CACHE cache_buf
IO_CACHE * cur_log
bool is_relay_log_recovery
TABLEsave_temporary_tables
Master_info * mi
uint32 cur_log_old_open_count
ulonglong log_space_limit
ulonglong log_space_total
bool ignore_log_space_limit
bool sql_force_rotate_relay
time_t last_master_timestamp
volatile uint32 slave_skip_counter
volatile ulong abort_pos_wait
mysql_mutex_t log_space_lock
mysql_cond_t log_space_cond
enum Relay_log_info:: { ... }  until_condition
char until_log_name [FN_REFLEN]
ulonglong until_log_pos
ulong until_log_name_extension
Gtid_set until_sql_gtids
bool until_sql_gtids_first_event
enum Relay_log_info:: { ... }  until_log_names_cmp_result
char cached_charset [6]
ulong trans_retries
ulong retried_trans
char ign_master_log_name_end [FN_REFLEN]
ulonglong ign_master_log_pos_end
char slave_patternload_file [FN_REFLEN]
size_t slave_patternload_file_size
struct timespec last_clock
RPL_TABLE_LISTtables_to_lock
uint tables_to_lock_count
table_mapping m_table_map
Rows_query_log_eventrows_query_ev
time_t last_event_start_time
Deferred_log_eventsdeferred_events
bool deferred_events_collecting
DYNAMIC_ARRAY workers
volatile ulong pending_jobs
mysql_mutex_t pending_jobs_lock
mysql_cond_t pending_jobs_cond
mysql_mutex_t exit_count_lock
ulong mts_slave_worker_queue_len_max
ulonglong mts_pending_jobs_size
ulonglong mts_pending_jobs_size_max
bool mts_wq_oversize
Slave_worker * last_assigned_worker
Slave_committed_queue * gaq
DYNAMIC_ARRAY curr_group_assigned_parts
DYNAMIC_ARRAY curr_group_da
bool curr_group_seen_gtid
bool curr_group_seen_begin
bool curr_group_isolated
bool mts_end_group_sets_max_dbs
volatile ulong mts_wq_underrun_w_id
volatile long mts_wq_excess_cnt
long mts_worker_underrun_level
ulong mts_coordinator_basic_nap
ulong opt_slave_parallel_workers
ulong slave_parallel_workers
ulong exit_counter
ulonglong max_updated_index
ulong recovery_parallel_workers
uint checkpoint_seqno
uint checkpoint_group
MY_BITMAP recovery_groups
bool recovery_groups_inited
ulong mts_recovery_group_cnt
ulong mts_recovery_index
bool mts_recovery_group_seen_begin
enum Relay_log_info:: { ... }  mts_group_status
ulonglong mts_events_assigned
ulonglong mts_groups_assigned
volatile ulong mts_wq_overrun_cnt
ulong wq_size_waits_cnt
ulong mts_wq_no_underrun_cnt
ulong mts_wq_overfill_cnt
DYNAMIC_ARRAY least_occupied_workers
time_t mts_last_online_stat
bool reported_unsafe_warning
uchar slave_version_split [3]

Protected Attributes

char group_relay_log_name [FN_REFLEN]
ulonglong group_relay_log_pos
char event_relay_log_name [FN_REFLEN]
ulonglong event_relay_log_pos
ulonglong future_event_relay_log_pos
char group_master_log_name [FN_REFLEN]
volatile my_off_t group_master_log_pos
ulonglong future_master_log_pos
Format_description_log_eventrli_description_event

Friends

class Rpl_info_factory

Member Enumeration Documentation

Flags for the state of the replication.

Enumerator:
IN_STMT 

The replication thread is inside a statement

STATE_FLAGS_COUNT 

Flag counter. Should always be last


Member Function Documentation

adaptation for the slave applier to specific master versions.

The method lists rules of adaptation for the slave applier to specific master versions. It's executed right before a new master FD is set for slave appliers execution context. Comparison of the old and new version yields the adaptive actions direction. Current execution FD's version, V_0, is compared with the new being set up FD (the arg), let's call it V_1. In the case of downgrade features that are defined in [V_0, V_1-1] range (V_1 excluded) are "removed" by running the downgrade actions. In the upgrade case the featured defined in [V_0 + 1, V_1] range are "added" by running the upgrade actions.

Notice, that due to relay log may have two FD events, one the slave local and the other from the Master. That can lead to extra adapt_to_master_version() calls and in case Slave and Master are of different versions the extra two calls should compensate each other.

Also, at composing downgrade/upgrade actions keep in mind that at initialization Slave sets up FD of version 4.0 and then transits to the current server version. At transition all upgrading actions in the range of [4.0..current] are run.

Parameters:
fdlea pointer to new Format Description event that is being set up for execution context.

Last charset (6 bytes) seen by slave SQL thread is cached here; it helps the thread save 3 get_charset() per Query_log_event if the charset is not changing from event to event (common situation). When the 6 bytes are equal to 0 is used to mean "cache is invalidated".

Clear the value of a replication state flag.

Parameters:
flagFlag to clear

Reset the delay. This is used by RESET SLAVE to clear the delay.

Resets UNTIL condition for Relay_log_info

The method to invoke at slave threads stop

int Relay_log_info::flush_info ( bool  force = FALSE)

Stores the file and position where the execute-slave thread are in the relay log:

  • As this is only called by the slave thread or on STOP SLAVE, with the log_lock grabbed and the slave thread stopped, we don't need to have a lock here.
  • If there is an active transaction, then we don't update the position in the relay log. This is to ensure that we re-execute statements if we die in the middle of an transaction that was rolled back.
  • As a transaction never spans binary logs, we don't have to handle the case where we do a relay-log-rotation in the middle of the transaction. If this would not be the case, we would have to ensure that we don't delete the relay log file where the transaction started when we switch to a new relay log file.
Return values:
0ok,
1write error, otherwise. Store the file and position where the slave's SQL thread are in the relay log.

Notes:

  • This function should be called either from the slave SQL thread, or when the slave thread is not running. (It reads the group_{relay|master}_log_{pos|name} and delay fields in the rli object. These may only be modified by the slave SQL thread or by a client thread when the slave SQL thread is not running.)
  • If there is an active transaction, then we do not update the position in the relay log. This is to ensure that we re-execute statements if we die in the middle of an transaction that was rolled back.
  • As a transaction never spans binary logs, we don't have to handle the case where we do a relay-log-rotation in the middle of the transaction. If transactions could span several binlogs, we would have to ensure that we do not delete the relay log file where the transaction started before switching to a new relay log file.
  • Error can happen if writing to file fails or if flushing the file fails.
Parameters:
rliThe object representing the Relay_log_info.
Todo:
Change the log file information to a binary format to avoid calling longlong2str.
Returns:
0 on success, 1 on error.
bool Relay_log_info::get_flag ( enum_state_flag  flag) [inline]

Get the value of a replication state flag.

Parameters:
flagFlag to get value of
Returns:
true if the flag was set, false otherwise.

Return the current Format_description_log_event.

int Relay_log_info::init_relay_log_pos ( const char *  log,
ulonglong  pos,
bool  need_data_lock,
const char **  errmsg,
bool  look_for_description_event 
)

Opens and intialize the given relay log. Specifically, it does what follows:

  • Closes old open relay log files.
  • If we are using the same relay log as the running IO-thread, then sets. rli->cur_log to point to the same IO_CACHE entry.
  • If not, opens the 'log' binary file.
Todo:
check proper initialization of group_master_log_name/group_master_log_pos. /alfranio
Parameters:
rli[in]Relay information (will be initialized)
log[in]Name of relay log file to read from. NULL = First log
pos[in]Position in relay log file
need_data_lock[in]If true, this function will acquire the relay_log.data_lock(); otherwise the caller should already have acquired it.
errmsg[out]On error, this function will store a pointer to an error message here
look_for_description_event[in]If true, this function will look for a Format_description_log_event. We only need this when the SQL thread starts and opens an existing relay log and has to execute it (possibly from an offset >4); then we need to read the first event of the relay log to be able to parse the events we have to execute.
Return values:
0ok,
1error. In this case, *errmsg is set to point to the error message.
void Relay_log_info::init_workers ( ulong  n_workers)

The method to invoke at slave threads start

bool Relay_log_info::is_in_group ( ) const [inline]

Is the replication inside a group?

Replication is inside a group if either:

  • The OPTION_BEGIN flag is set, meaning we're inside a transaction
  • The RLI_IN_STMT flag is set, meaning we're inside a statement
  • There is an GTID owned by the thd, meaning we've passed a SET GTID_NEXT
Return values:
trueReplication thread is currently inside a group
falseReplication thread is currently not inside a group

returns true if Coordinator is scheduling events belonging to the same group and has not reached yet its terminal event.

bool Relay_log_info::is_mts_recovery ( ) const [inline]

returns true if there is any gap-group of events to execute at slave starting phase.

bool Relay_log_info::is_parallel_exec ( ) const [inline]

returns true if events are to be executed in parallel

bool Relay_log_info::is_until_satisfied ( THD *  thd,
Log_event ev 
)

Checks if condition stated in UNTIL clause of START SLAVE is reached.

Specifically, it checks if UNTIL condition is reached. Uses caching result of last comparison of current log file name and target log file name. So cached value should be invalidated if current log file name changes (see Relay_log_info::notify_... functions).

This caching is needed to avoid of expensive string comparisons and strtol() conversions needed for log names comparison. We don't need to compare them each time this function is called, we only need to do this when current log name changes. If we have UNTIL_MASTER_POS condition we need to do this only after Rotate_log_event::do_apply_event() (which is rare, so caching gives real benifit), and if we have UNTIL_RELAY_POS condition then we should invalidate cached comarison value after inc_group_relay_log_pos() which called for each group of events (so we have some benefit if we have something like queries that use autoincrement or if we have transactions).

Should be called ONLY if until_condition != UNTIL_NONE !

Parameters:
master_beg_posposition of the beginning of to be executed event (not log_pos member of the event that points to the beginning of the following event)
Return values:
truecondition met or error happened (condition seems to have bad log file name),
falsecondition not met.

Called when gaps execution is ended so it is crash-safe to reset the last session Workers info.

Reset recovery info from Worker info table and mark MTS recovery is completed.

Returns:
false on success true when reset_notified_checkpoint failed.

The same as notify_group_relay_log_name_update but for group_master_log_name.

Invalidates cached until_log_name and group_relay_log_name comparison result. Should be called after any update of group_realy_log_name if there chances that sql_thread is running.

int Relay_log_info::purge_relay_logs ( THD *  thd,
bool  just_reset,
const char **  errmsg 
)

Purges relay logs. It assumes to have a run lock on rli and that no slave thread are running.

Parameters:
[in]THDconnection,
[in]just_resetif false, it tells that logs should be purged and init_relay_log_pos() should be called, [out] errmsg store pointer to an error message.
Return values:
0successfuly executed,
1otherwise error, where errmsg is set to point to the error message.
void Relay_log_info::reset_notified_checkpoint ( ulong  shift,
time_t  new_ts,
bool  need_data_lock 
)

While a group is executed by a Worker the relay log can change. Coordinator notifies Workers about this event. Coordinator and Workers maintain a bitmap of executed group that is reset with a new checkpoint.

This method is called in mts_checkpoint_routine() to mark that each worker is required to adapt to a new checkpoint data whose coordinates are passed to it through GAQ index.

Worker notices the new checkpoint value at the group commit to reset the current bitmap and starts using the clean bitmap indexed from zero of being reset checkpoint_seqno.

New seconds_behind_master timestamp is installed.

Parameters:
shiftnumber of bits to shift by Worker due to the current checkpoint change.
new_tsnew seconds_behind_master timestamp value unless zero. Zero could be due to FD event.
need_data_lockFalse if caller has locked data_lock

While a group is executed by a Worker the relay log can change. Coordinator notifies Workers about this event. Worker is supposed to commit to the recovery table with the new info.

Method is called when MTS coordinator senses the relay-log name has been changed. It marks each Worker member with this fact to make an action at time it will distribute a terminal event of a group to the Worker.

Worker receives the new name at the group commiting phase Slave_worker::slave_worker_ends_group().

void Relay_log_info::set_flag ( enum_state_flag  flag) [inline]

Set the value of a replication state flag.

Parameters:
flagFlag to set

Delete the existing event and set a new one. This class is responsible for freeing the event, the caller should not do that.

Delete the existing event and set a new one. This class is responsible for freeing the event, the caller should not do that. When a new FD is from the master adaptation routine is invoked to align the slave applier execution context with the master version.

The method is run by SQL thread/MTS Coordinator. Although notice that MTS worker runs it, inefficiently (see assert), once at its destruction time. todo: fix Slave_worker and Relay_log_info inheritance relation.

Parameters:
apointer to be installed into execution context FormatDescriptor event
void Relay_log_info::start_sql_delay ( time_t  delay_end) [inline]

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.

Parameters:
delay_endThe time when the delay shall end.
int Relay_log_info::stmt_done ( my_off_t  event_log_pos)

Helper function to do after statement completion.

This function is called from an event to complete the group by either stepping the group position, if the "statement" is not inside a transaction; or increase the event position, if the "statement" is inside a transaction.

Parameters:
event_log_posMaster log position of the event. The position is recorded in the relay log info and used to produce information for SHOW SLAVE STATUS.
int Relay_log_info::wait_for_pos ( THD *  thd,
String log_name,
longlong  log_pos,
longlong  timeout 
)

Waits until the SQL thread reaches (has executed up to) the log/position or timed out.

SYNOPSIS

Parameters:
[in]thdclient thread that sent SELECT MASTER_POS_WAIT,
[in]log_namelog name to wait for,
[in]log_posposition to wait for,
[in]timeouttimeout in seconds before giving up waiting. timeout is longlong whereas it should be ulong; but this is to catch if the user submitted a negative timeout.
Return values:
-2improper arguments (log_pos<0) or slave not running, or master info changed during the function's execution, or client thread killed. -2 is translated to NULL by caller,
-1timed out
>=0number of log events the function had to wait before reaching the desired log/position

Member Data Documentation

struct timespec Relay_log_info::last_clock

Identifies the last time a checkpoint routine has been executed.

The START SLAVE UNTIL SQL_*_GTIDS initializes until_sql_gtids. Each time a gtid is about to be processed, we check if it is in the set. Depending on until_condition, SQL thread is stopped before or after applying the gtid.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines