MySQL  8.0.17
Source Code Documentation
rpl_rli.h
Go to the documentation of this file.
1 /* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef RPL_RLI_H
24 #define RPL_RLI_H
25 
26 #if defined(__SUNPRO_CC)
27 /*
28  Solaris Studio 12.5 has a bug where, if you use dynamic_cast
29  and then later #include this file (which Boost does), you will
30  get a compile error. Work around it by just including it right now.
31 */
32 #include <cxxabi.h>
33 #endif
34 
35 #include <sys/types.h>
36 #include <time.h>
37 #include <atomic>
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 #include "binlog_event.h"
43 #include "lex_string.h"
44 #include "m_string.h"
45 #include "map_helpers.h"
46 #include "my_bitmap.h"
47 #include "my_dbug.h"
48 #include "my_inttypes.h"
49 #include "my_io.h"
50 #include "my_loglevel.h"
51 #include "my_psi_config.h"
52 #include "my_sys.h"
56 #include "mysql/psi/mysql_mutex.h"
57 #include "mysql/thread_type.h"
58 #include "prealloced_array.h" // Prealloced_array
59 #include "sql/binlog.h" // MYSQL_BIN_LOG
60 #include "sql/log_event.h" //Gtid_log_event
61 #include "sql/psi_memory_key.h"
62 #include "sql/query_options.h"
63 #include "sql/rpl_gtid.h" // Gtid_set
64 #include "sql/rpl_info.h" // Rpl_info
65 #include "sql/rpl_mts_submode.h" // enum_mts_parallel_type
67 #include "sql/rpl_tblmap.h" // table_mapping
68 #include "sql/rpl_utility.h" // Deferred_log_events
69 #include "sql/sql_class.h" // THD
70 #include "sql/system_variables.h"
71 #include "sql/table.h"
72 
74 class Master_info;
75 class Rpl_filter;
76 class Rpl_info_handler;
78 class Slave_worker;
79 class String;
80 struct LEX_MASTER_INFO;
82 
84 
86 
87 typedef struct slave_job_item {
92 
93 /*******************************************************************************
94 Replication SQL Thread
95 
96 Relay_log_info contains:
97  - the current relay log
98  - the current relay log offset
99  - master log name
100  - master log sequence corresponding to the last update
101  - misc information specific to the SQL thread
102 
103 Relay_log_info is initialized from a repository, i.e. table or file, if there is
104 one. Otherwise, data members are intialized with defaults by calling
105 init_relay_log_info().
106 
107 The relay.info table/file shall be updated whenever: (i) the relay log file
108 is rotated, (ii) SQL Thread is stopped, (iii) while processing a Xid_log_event,
109 (iv) after a Query_log_event (i.e. commit or rollback) and (v) after processing
110 any statement written to the binary log without a transaction context.
111 
112 The Xid_log_event is a commit for transactional engines and must be handled
113 differently to provide reliability/data integrity. In this case, positions
114 are updated within the context of the current transaction. So
115 
116  . If the relay.info is stored in a transactional repository and the server
117  crashes before successfully committing the transaction the changes to the
118  position table will be rolled back along with the data.
119 
120  . If the relay.info is stored in a non-transactional repository, for instance,
121  a file or a system table created using MyIsam, and the server crashes before
122  successfully committing the transaction the changes to the position table
123  will not be rolled back but data will.
124 
125 In particular, when there are mixed transactions, i.e a transaction that updates
126 both transaction and non-transactional engines, the Xid_log_event is still used
127 but reliability/data integrity cannot be achieved as we shall explain in what
128 follows.
129 
130 Changes to non-transactional engines, such as MyIsam, cannot be rolled back if a
131 failure happens. For that reason, there is no point in updating the positions
132 within the boundaries of any on-going transaction. This is true for both commit
133 and rollback. If a failure happens after processing the pseudo-transaction but
134 before updating the positions, the transaction will be re-executed when the
135 slave is up most likely causing an error that needs to be manually circumvented.
136 This is a well-known issue when non-transactional statements are executed.
137 
138 Specifically, if rolling back any transaction, positions are updated outside the
139 transaction boundaries. However, there may be a problem in this scenario even
140 when only transactional engines are updated. This happens because if there is a
141 rollback and such transaction is written to the binary log, a non-transactional
142 engine was updated or a temporary table was created or dropped within its
143 boundaries.
144 
145 In particular, in both STATEMENT and MIXED logging formats, this happens because
146 any temporary table is automatically dropped after a shutdown/startup.
147 See BUG#26945 for further details.
148 
149 Statements written to the binary log outside the boundaries of a transaction are
150 DDLs or maintenance commands which are not transactional. These means that they
151 cannot be rolled back if a failure happens. In such cases, the positions are
152 updated after processing the events. If a failure happens after processing the
153 statement but before updating the positions, the statement will be
154 re-executed when the slave is up most likely causing an error that needs to be
155 manually circumvented. This is a well-known issue when non-transactional
156 statements are executed.
157 
158 The --sync-relay-log-info does not have effect when a system table, either
159 transactional or non-transactional is used.
160 
161 To correctly recovery from failures, one should combine transactional system
162 tables along with the --relay-log-recovery.
163 *******************************************************************************/
164 class Relay_log_info : public Rpl_info {
165  friend class Rpl_info_factory;
166 
167  public:
168  /*
169  The per-channel filter associated with this RLI
170  */
172  /**
173  Flags for the state of the replication.
174  */
176  /** The replication thread is inside a statement */
178 
179  /** Flag counter. Should always be last */
181  };
182 
183  /*
184  The SQL thread owns one Relay_log_info, and each client that has
185  executed a BINLOG statement owns one Relay_log_info. This function
186  returns zero for the Relay_log_info object that belongs to the SQL
187  thread and nonzero for Relay_log_info objects that belong to
188  clients.
189  */
190  inline bool belongs_to_client() {
192  return !info_thd->slave_thread;
193  }
194 /* Instrumentation key for performance schema for mts_temp_table_LOCK */
195 #ifdef HAVE_PSI_INTERFACE
197 #endif
198  /*
199  Lock to protect race condition while transferring temporary table from
200  worker thread to coordinator thread and vice-versa
201  */
203  /*
204  Lock to acquire by methods that concurrently update lwm of committed
205  transactions and the min waited timestamp and its index.
206  */
209  /*
210  If true, events with the same server id should be replicated. This
211  field is set on creation of a relay log info structure by copying
212  the value of ::replicate_same_server_id and can be overridden if
213  necessary. For example of when this is done, check sql_binlog.cc,
214  where the BINLOG statement can be used to execute "raw" events.
215  */
217 
218  /*
219  Protected with internal locks.
220  Must get data_lock when resetting the logs.
221  */
223 
224  /*
225  Identifies when the recovery process is going on.
226  See sql/rpl_slave.h:init_recovery for further details.
227  */
229 
230  /* The following variables are safe to read any time */
231 
232  /*
233  When we restart slave thread we need to have access to the previously
234  created temporary tables. Modified only on init/end and by the SQL
235  thread, read only by SQL thread.
236  */
238 
239  /* parent Master_info structure */
241 
242  /* number of temporary tables open in this channel */
243  std::atomic<int32> atomic_channel_open_temp_tables{0};
244 
245  /** the status of the commit timestamps for the relay log */
246  enum {
247  /*
248  no GTID log event has been processed, so it is not known if this log
249  has commit timestamps
250  */
252  // the immediate master does not support commit timestamps
254  // the immediate master supports commit timestamps
257 
258  /**
259  @return the pointer to the Gtid_monitoring_info.
260  */
262  return gtid_monitoring_info;
263  }
264 
265  /**
266  Stores the details of the transaction which has just started processing.
267 
268  This function is called by the STS applier or MTS worker when applying a
269  Gtid.
270 
271  @param gtid_arg the gtid of the trx
272  @param original_ts_arg the original commit timestamp of the transaction
273  @param immediate_ts_arg the immediate commit timestamp of the transaction
274  @param skipped true if the transaction was gtid skipped
275  */
276  void started_processing(Gtid gtid_arg, ulonglong original_ts_arg,
277  ulonglong immediate_ts_arg, bool skipped = false) {
278  gtid_monitoring_info->start(gtid_arg, original_ts_arg, immediate_ts_arg,
279  skipped);
280  }
281 
282  /**
283  Stores the details of the transaction which has just started processing.
284 
285  This function is called by the MTS coordinator when queuing a Gtid to
286  a worker.
287 
288  @param gtid_log_ev_arg the gtid log event of the trx
289  */
290  void started_processing(Gtid_log_event *gtid_log_ev_arg) {
291  Gtid gtid = {0, 0};
292  if (gtid_log_ev_arg->get_type() == ASSIGNED_GTID) {
293  gtid = {gtid_log_ev_arg->get_sidno(true), gtid_log_ev_arg->get_gno()};
294  }
295  started_processing(gtid, gtid_log_ev_arg->original_commit_timestamp,
296  gtid_log_ev_arg->immediate_commit_timestamp);
297  }
298 
299  /**
300  When the processing of a transaction is completed, that timestamp is
301  recorded, the information is copied to last_processed_trx and the
302  information in processing_trx is cleared.
303 
304  If the transaction was "applied" but GTID-skipped, the copy will not
305  happen and the last_processed_trx will keep its current value.
306  */
308 
309  /**
310  @return True if there is a transaction being currently processed
311  */
314  }
315 
316  /**
317  Clears the processing_trx structure fields. Normally called when there is an
318  error while processing the transaction.
319  */
321 
322  /**
323  Clears the Gtid_monitoring_info fields.
324  */
326 
327  /**
328  When a transaction is retried, the error number and message, and total number
329  of retries are stored. The timestamp for this error is also set here.
330 
331  @param transient_errno_arg Transient error number.
332  @param transient_err_message_arg Transient error message.
333  @param trans_retries_arg Number of times this transaction has been
334  retried so far.
335  */
336  void retried_processing(uint transient_errno_arg,
337  const char *transient_err_message_arg,
338  ulong trans_retries_arg) {
340  transient_errno_arg, transient_err_message_arg, trans_retries_arg);
341  }
342 
343  /*
344  If on init_info() call error_on_rli_init_info is true that means
345  that previous call to init_info() terminated with an error, RESET
346  SLAVE must be executed and the problem fixed manually.
347  */
349 
350  /**
351  Variable is set to true as long as
352  original_commit_timestamp > immediate_commit_timestamp so that the
353  corresponding warning is only logged once.
354  */
356 
357  /*
358  Let's call a group (of events) :
359  - a transaction
360  or
361  - an autocommiting query + its associated events (INSERT_ID,
362  TIMESTAMP...)
363  We need these rli coordinates :
364  - relay log name and position of the beginning of the group we currently are
365  executing. Needed to know where we have to restart when replication has
366  stopped in the middle of a group (which has been rolled back by the slave).
367  - relay log name and position just after the event we have just
368  executed. This event is part of the current group.
369  Formerly we only had the immediately above coordinates, plus a 'pending'
370  variable, but this dealt wrong with the case of a transaction starting on a
371  relay log and finishing (commiting) on another relay log. Case which can
372  happen when, for example, the relay log gets rotated because of
373  max_binlog_size.
374  */
375  protected:
376  /**
377  Event group means a group of events of a transaction. group_relay_log_name
378  and group_relay_log_pos record the place before where all event groups
379  are applied. When slave starts, it resume to apply events from
380  group_relay_log_pos. They will be initialized to the begin of the first
381  relay log file if it is a new slave(including SLAVE RESET). Then,
382  group_relay_log_pos is advanced after each transaction is applied
383  successfully in single thread slave. For MTS, group_relay_log_pos
384  is updated by mts checkpoint mechanism. group_relay_log_pos and
385  group_relay_log_name are stored into relay_log_info file/table
386  periodically. When server startup, they are loaded from relay log info
387  file/table.
388  */
392  /* The suffix number of relay log name */
396 
397  /* current event's start position in relay log */
399  /*
400  Original log name and position of the group we're currently executing
401  (whose coordinates are group_relay_log_name/pos in the relay log)
402  in the master's binlog. These concern the *group*, because in the master's
403  binlog the log_pos that comes with each event is the position of the
404  beginning of the group.
405 
406  Note: group_master_log_name, group_master_log_pos must only be
407  written from the thread owning the Relay_log_info (SQL thread if
408  !belongs_to_client(); client thread executing BINLOG statement if
409  belongs_to_client()).
410  */
413 
414  private:
416  /*
417  Identifies when this object belongs to the SQL thread and was not
418  created for a client thread or some other purpose including
419  Slave_worker instance initializations. Ends up serving the same
420  purpose as the belongs_to_client method, but its value is set
421  earlier on in the class constructor.
422  */
423  bool rli_fake;
424  /* Flag that ensures the retrieved GTID set is initialized only once. */
426 
427  /**
428  Stores information on the last processed transaction or the transaction
429  that is currently being processed.
430 
431  STS:
432  - timestamps of the currently applying/last applied transaction
433 
434  MTS:
435  - coordinator thread: timestamps of the currently scheduling/last scheduled
436  transaction in a worker's queue
437  - worker thread: timestamps of the currently applying/last applied
438  transaction
439  */
441 
442  /**
443  It will be set to true when receiver truncated relay log for some reason.
444  The truncated data may already be read by applier. So applier need to check
445  it each time the binlog_end_pos is updated.
446  */
447  bool m_relay_log_truncated = false;
448 
449  public:
451 
453 
455 
456  void add_logged_gtid(rpl_sidno sidno, rpl_gno gno) {
458  DBUG_ASSERT(sidno <= get_sid_map()->get_max_sidno());
459  gtid_set->ensure_sidno(sidno);
460  gtid_set->_add_gtid(sidno, gno);
461  }
462 
463  /**
464  Adds a GTID set to received GTID set.
465 
466  @param gtid_set the gtid_set to add
467 
468  @return RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.
469  */
471 
472  const Gtid_set *get_gtid_set() const { return gtid_set; }
473 
474  bool reinit_sql_thread_io_cache(const char *log, bool need_data_lock);
475 
476  /**
477  Check if group_relay_log_name is in index file.
478 
479  @param [out] errmsg An error message is returned if error happens.
480 
481  @retval false It is valid.
482  @retval true It is invalid. In this case, *errmsg is set to point to
483  the error message.
484 */
485  bool is_group_relay_log_name_invalid(const char **errmsg);
486  /**
487  Reset group_relay_log_name and group_relay_log_pos to the start of the
488  first relay log file. The caller must hold data_lock.
489 
490  @param[out] errmsg An error message is set into it if error happens.
491 
492  @retval false Success
493  @retval true Error
494  */
495  bool reset_group_relay_log_pos(const char **errmsg);
496  /*
497  Update the error number, message and timestamp fields. This function is
498  different from va_report() as va_report() also logs the error message in the
499  log apart from updating the error fields.
500  */
501  void fill_coord_err_buf(loglevel level, int err_code,
502  const char *buff_coord) const;
503 
504  /*
505  Flag that the group_master_log_pos is invalid. This may occur
506  (for example) after CHANGE MASTER TO RELAY_LOG_POS. This will
507  be unset after the first event has been executed and the
508  group_master_log_pos is valid again.
509  */
511 
512  /*
513  Handling of the relay_log_space_limit optional constraint.
514  ignore_log_space_limit is used to resolve a deadlock between I/O and SQL
515  threads, the SQL thread sets it to unblock the I/O thread and make it
516  temporarily forget about the constraint.
517  */
520 
521  /*
522  Used by the SQL thread to instructs the IO thread to rotate
523  the logs when the SQL thread needs to purge to release some
524  disk space.
525  */
527 
529 
530  /**
531  Reset the delay.
532  This is used by RESET SLAVE to clear the delay.
533  */
534  void clear_sql_delay() { sql_delay = 0; }
535 
536  /*
537  Needed for problems when slave stops and we want to restart it
538  skipping one or more events in the master log that have caused
539  errors, and have been manually applied by DBA already.
540  */
542  volatile ulong abort_pos_wait; /* Incremented on change master */
545 
546  /*
547  Condition and its parameters from START SLAVE UNTIL clause.
548 
549  UNTIL condition is tested with is_until_satisfied() method that is
550  called by exec_relay_log_event(). is_until_satisfied() caches the result
551  of the comparison of log names because log names don't change very often;
552  this cache is invalidated by parts of code which change log names with
553  notify_*_log_name_updated() methods. (They need to be called only if SQL
554  thread is running).
555  */
556  enum {
565  } until_condition;
566 
567  char cached_charset[6];
568 
569  /*
570  trans_retries varies between 0 to slave_transaction_retries and counts how
571  many times the slave has retried the present transaction; gets reset to 0
572  when the transaction finally succeeds. retried_trans is a cumulative
573  counter: how many times the slave has retried a transaction (any) since
574  slave started.
575  */
577 
578  /*
579  If the end of the hot relay log is made of master's events ignored by the
580  slave I/O thread, these two keep track of the coords (in the master's
581  binlog) of the last of these events seen by the slave I/O thread. If not,
582  ign_master_log_name_end[0] == 0.
583  As they are like a Rotate event read/written from/to the relay log, they
584  are both protected by rli->relay_log.LOCK_binlog_end_pos.
585  */
588 
589  /*
590  Indentifies where the SQL Thread should create temporary files for the
591  LOAD DATA INFILE. This is used for security reasons.
592  */
595 
596  /**
597  Identifies the last time a checkpoint routine has been executed.
598  */
599  struct timespec last_clock;
600 
601  /**
602  Invalidates cached until_log_name and event_relay_log_name comparison
603  result. Should be called after switch to next relay log if
604  there chances that sql_thread is running.
605  */
606  inline void notify_relay_log_change() {
608  dynamic_cast<Until_position *>(until_option)->notify_log_name_change();
609  }
610 
611  /**
612  Receiver thread notifies that it truncated some data from relay log.
613  data_lock will be acquired, so the caller should not hold data_lock.
614  */
616  /**
617  Applier clears the flag after it handled the situation. The caller must
618  hold data_lock.
619  */
621 
622  /**
623  The same as @c notify_group_relay_log_name_update but for
624  @c group_master_log_name.
625  */
628  dynamic_cast<Until_position *>(until_option)->notify_log_name_change();
629  }
630 
631  inline void inc_event_relay_log_pos() {
633  }
634 
635  /**
636  Last executed event group coordinates are updated and optionally
637  forcibly flushed to a repository.
638  @param log_pos a value of the executed position to update to
639  @param need_data_lock whether data_lock should be acquired
640  @param force the value is passed to eventual flush_info()
641  */
642  int inc_group_relay_log_pos(ulonglong log_pos, bool need_data_lock,
643  bool force = false);
644 
645  int wait_for_pos(THD *thd, String *log_name, longlong log_pos,
646  double timeout);
647  /**
648  Wait for a GTID set to be executed.
649 
650  @param thd The thread for status changes and kill status
651  @param gtid A char array with a GTID set
652  @param timeout Number of seconds to wait before timing out
653  @param update_THD_status Shall the method update the THD stage
654 
655  @retval 0 The set is already executed
656  @retval -1 There was a timeout waiting for the set
657  @retval -2 There was an issue while waiting.
658  */
659  int wait_for_gtid_set(THD *thd, const char *gtid, double timeout,
660  bool update_THD_status = true);
661  /**
662  Wait for a GTID set to be executed.
663 
664  @param thd The thread for status changes and kill status
665  @param gtid A String with a GTID set
666  @param timeout Number of seconds to wait before timing out
667  @param update_THD_status Shall the method update the THD stage
668 
669  @retval 0 The set is already executed
670  @retval -1 There was a timeout waiting for the set
671  @retval -2 There was an issue while waiting.
672  */
673  int wait_for_gtid_set(THD *thd, String *gtid, double timeout,
674  bool update_THD_status = true);
675  /**
676  Wait for a GTID set to be executed.
677 
678  @param thd The thread for status changes and kill status
679  @param wait_gtid_set A GTID_set object
680  @param timeout Number of seconds to wait before timing out
681  @param update_THD_status Shall the method update the THD stage
682 
683  @retval 0 The set is already executed
684  @retval -1 There was a timeout waiting for the set
685  @retval -2 There was an issue while waiting.
686  */
687  int wait_for_gtid_set(THD *thd, const Gtid_set *wait_gtid_set, double timeout,
688  bool update_THD_status = true);
689 
690  void close_temporary_tables();
691 
692  RPL_TABLE_LIST *tables_to_lock; /* RBR: Tables to lock */
693  uint tables_to_lock_count; /* RBR: Count of tables to lock */
694  table_mapping m_table_map; /* RBR: Mapping table-id to table */
695  /* RBR: Record Rows_query log event */
697 
698  bool get_table_data(TABLE *table_arg, table_def **tabledef_var,
699  TABLE **conv_table_var) const {
700  DBUG_ASSERT(tabledef_var && conv_table_var);
701  for (TABLE_LIST *ptr = tables_to_lock; ptr != nullptr;
702  ptr = ptr->next_global)
703  if (ptr->table == table_arg) {
704  *tabledef_var = &static_cast<RPL_TABLE_LIST *>(ptr)->m_tabledef;
705  *conv_table_var = static_cast<RPL_TABLE_LIST *>(ptr)->m_conv_table;
706  DBUG_PRINT("debug", ("Fetching table data for table %s.%s:"
707  " tabledef: %p, conv_table: %p",
708  table_arg->s->db.str, table_arg->s->table_name.str,
709  *tabledef_var, *conv_table_var));
710  return true;
711  }
712  return false;
713  }
714 
715  /**
716  Last charset (6 bytes) seen by slave SQL thread is cached here; it helps
717  the thread save 3 @c get_charset() per @c Query_log_event if the charset is
718  not changing from event to event (common situation). When the 6 bytes are
719  equal to 0 is used to mean "cache is invalidated".
720  */
722  bool cached_charset_compare(char *charset) const;
723 
724  void cleanup_context(THD *, bool);
726  void clear_tables_to_lock();
727  int purge_relay_logs(THD *thd, const char **errmsg, bool delete_only = false);
728 
729  /*
730  Used to defer stopping the SQL thread to give it a chance
731  to finish up the current group of events.
732  The timestamp is set and reset in @c sql_slave_killed().
733  */
735 
736  /* The original master commit timestamp in microseconds since epoch */
738 
739  /*
740  A container to hold on Intvar-, Rand-, Uservar- log-events in case
741  the slave is configured with table filtering rules.
742  The withhold events are executed when their parent Query destiny is
743  determined for execution as well.
744  */
746 
747  /*
748  State of the container: true stands for IRU events gathering,
749  false does for execution, either deferred or direct.
750  */
752 
753  /*****************************************************************************
754  WL#5569 MTS
755 
756  legends:
757  C - Coordinator;
758  W - Worker;
759  WQ - Worker Queue containing event assignments
760  */
761  // number's is determined by global slave_parallel_workers
763 
764  // To map a database to a worker
765  malloc_unordered_map<std::string,
768  bool inited_hash_workers; // flag to check if mapping_db_to_worker is inited
769 
770  mysql_mutex_t slave_worker_hash_lock; // for mapping_db_to_worker
771  mysql_cond_t slave_worker_hash_cond; // for mapping_db_to_worker
772 
773  /*
774  For the purpose of reporting the worker status in performance schema table,
775  we need to preserve the workers array after worker thread was killed. So, we
776  copy this array into the below vector which is used for reporting
777  until next init_workers(). Note that we only copy those attributes that
778  would be useful in reporting worker status. We only use a few attributes in
779  this object as of now but still save the whole object. The idea is
780  to be future proof. We will extend performance schema tables in future
781  and then we would use a good number of attributes from this object.
782  */
783 
784  std::vector<Slave_worker *> workers_copy_pfs;
785 
786  /*
787  This flag is turned ON when the workers array is initialized.
788  Before destroying the workers array we check this flag to make sure
789  we are not destroying an unitilized array. For the purpose of reporting the
790  worker status in performance schema table, we need to preserve the workers
791  array after worker thread was killed. So, we copy this array into
792  workers_copy_pfs array which is used for reporting until next
793  init_workers().
794  */
796 
797  volatile ulong pending_jobs;
800  mysql_mutex_t exit_count_lock; // mutex of worker exit count
802  ulonglong mts_pending_jobs_size; // actual mem usage by WQ:s
803  ulonglong mts_pending_jobs_size_max; // max of WQ:s size forcing C to wait
804  bool mts_wq_oversize; // C raises flag to wait some memory's released
806  *last_assigned_worker; // is set to a Worker at assigning a group
807  /*
808  master-binlog ordered queue of Slave_job_group descriptors of groups
809  that are under processing. The queue size is @c checkpoint_group.
810  */
812  /*
813  Container for references of involved partitions for the current event group
814  */
815  // CGAP dynarray holds id:s of partitions of the Current being executed Group
817  // deferred array to hold partition-info-free events
819 
820  bool curr_group_seen_gtid; // current group started with Gtid-event or not
821  bool curr_group_seen_begin; // current group started with B-event or not
822  bool curr_group_isolated; // current group requires execution in isolation
823  bool mts_end_group_sets_max_dbs; // flag indicates if partitioning info is
824  // discovered
825  volatile ulong
826  mts_wq_underrun_w_id; // Id of a Worker whose queue is getting empty
827  /*
828  Ongoing excessive overrun counter to correspond to number of events that
829  are being scheduled while a WQ is close to be filled up.
830  `Close' is defined as (100 - mts_worker_underrun_level) %.
831  The counter is incremented each time a WQ get filled over that level
832  and decremented when the level drops below.
833  The counter therefore describes level of saturation that Workers
834  are experiencing and is used as a parameter to compute a nap time for
835  Coordinator in order to avoid reaching WQ limits.
836  */
837  volatile long mts_wq_excess_cnt;
838  long mts_worker_underrun_level; // % of WQ size at which W is considered
839  // hungry
840  ulong mts_coordinator_basic_nap; // C sleeps to avoid WQs overrun
841  ulong opt_slave_parallel_workers; // cache for ::opt_slave_parallel_workers
842  ulong slave_parallel_workers; // the one slave session time number of workers
843  ulong
844  exit_counter; // Number of workers contributed to max updated group index
846  ulong recovery_parallel_workers; // number of workers while recovering
847  uint rli_checkpoint_seqno; // counter of groups executed after the most
848  // recent CP
849  uint checkpoint_group; // cache for ::opt_mts_checkpoint_group
850  MY_BITMAP recovery_groups; // bitmap used during recovery
852  ulong mts_recovery_group_cnt; // number of groups to execute at recovery
853  ulong mts_recovery_index; // running index of recoverable groups
855 
856  /*
857  While distibuting events basing on their properties MTS
858  Coordinator changes its mts group status.
859  Transition normally flowws to follow `=>' arrows on the diagram:
860 
861  +----------------------------+
862  V |
863  MTS_NOT_IN_GROUP => |
864  {MTS_IN_GROUP => MTS_END_GROUP --+} while (!killed) => MTS_KILLED_GROUP
865 
866  MTS_END_GROUP has `->' loop breaking link to MTS_NOT_IN_GROUP when
867  Coordinator synchronizes with Workers by demanding them to
868  complete their assignments.
869  */
870  enum {
871  /*
872  no new events were scheduled after last synchronization,
873  includes Single-Threaded-Slave case.
874  */
876 
877  MTS_IN_GROUP, /* at least one not-terminal event scheduled to a Worker */
878  MTS_END_GROUP, /* the last scheduled event is a terminal event */
879  MTS_KILLED_GROUP /* Coordinator gave up to reach MTS_END_GROUP */
881 
882  /*
883  MTS statistics:
884  */
885  ulonglong mts_events_assigned; // number of events (statements) scheduled
886  ulonglong mts_groups_assigned; // number of groups (transactions) scheduled
887  volatile ulong
888  mts_wq_overrun_cnt; // counter of all mts_wq_excess_cnt increments
889  ulong wq_size_waits_cnt; // number of times C slept due to WQ:s oversize
890  /*
891  Counter of how many times Coordinator saw Workers are filled up
892  "enough" with assignements. The enough definition depends on
893  the scheduler type.
894  */
896  std::atomic<longlong>
897  mts_total_wait_overlap; // Waiting time corresponding to above
898  /*
899  Stats to compute Coordinator waiting time for any Worker available,
900  applies solely to the Commit-clock scheduler.
901  */
903  ulong mts_wq_overfill_cnt; // counter of C waited due to a WQ queue was full
904  /*
905  Statistics (todo: replace with WL5631) applies to either Coordinator and
906  Worker. The exec time in the Coordinator case means scheduling. The read
907  time in the Worker case means getting an event out of Worker queue
908  */
911  struct timespec ts_exec[2]; // per event pre- and post- exec timestamp
912  struct timespec stats_begin; // applier's bootstrap time
913 
914  /*
915  A sorted array of the Workers' current assignement numbers to provide
916  approximate view on Workers loading.
917  The first row of the least occupied Worker is queried at assigning
918  a new partition. Is updated at checkpoint commit to the main RLI.
919  */
922  /* end of MTS statistics */
923 
924  /**
925  Storage for holding newly computed values for the last executed
926  event group coordinates while the current group of events is
927  being committed, see @c pre_commit, post_commit.
928  */
933 
934  /* Returns the number of elements in workers array/vector. */
935  inline size_t get_worker_count() {
937  return workers.size();
938  else
939  return workers_copy_pfs.size();
940  }
941 
942  /*
943  Returns a pointer to the worker instance at index n in workers
944  array/vector.
945  */
948  if (n >= workers.size()) return nullptr;
949 
950  return workers[n];
951  } else if (workers_copy_pfs.size()) {
952  if (n >= workers_copy_pfs.size()) return nullptr;
953 
954  return workers_copy_pfs[n];
955  } else
956  return nullptr;
957  }
958 
959  /**
960  The method implements updating a slave info table. It's
961  specialized differently for STS and MTS.
962  */
963  virtual bool commit_positions();
964 
965  /*Channel defined mts submode*/
967  /* MTS submode */
969 
970  /* most of allocation in the coordinator rli is there */
971  void init_workers(ulong);
972 
973  /* counterpart of the init */
974  void deinit_workers();
975 
976  /**
977  returns true if there is any gap-group of events to execute
978  at slave starting phase.
979  */
980  inline bool is_mts_recovery() const { return mts_recovery_group_cnt != 0; }
981 
986  recovery_groups_inited = false;
987  }
988  }
989 
990  /**
991  returns true if events are to be executed in parallel
992  */
993  inline bool is_parallel_exec() const {
994  bool ret = (slave_parallel_workers > 0) && !is_mts_recovery();
995 
996  DBUG_ASSERT(!ret || !workers.empty());
997 
998  return ret;
999  }
1000 
1001  /**
1002  returns true if Coordinator is scheduling events belonging to
1003  the same group and has not reached yet its terminal event.
1004  */
1005  inline bool is_mts_in_group() {
1007  }
1008 
1009  /**
1010  Check if it is time to compute MTS checkpoint.
1011 
1012  @retval true It is time to compute MTS checkpoint.
1013  @retval false It is not MTS or it is not time for computing checkpoint.
1014  */
1016  /**
1017  While a group is executed by a Worker the relay log can change.
1018  Coordinator notifies Workers about this event. Worker is supposed
1019  to commit to the recovery table with the new info.
1020  */
1022 
1023  /**
1024  While a group is executed by a Worker the relay log can change.
1025  Coordinator notifies Workers about this event. Coordinator and Workers
1026  maintain a bitmap of executed group that is reset with a new checkpoint.
1027  */
1028  void reset_notified_checkpoint(ulong count, time_t new_ts,
1029  bool update_timestamp = false);
1030 
1031  /**
1032  Called when gaps execution is ended so it is crash-safe
1033  to reset the last session Workers info.
1034  */
1035  bool mts_finalize_recovery();
1036  /*
1037  * End of MTS section ******************************************************/
1038 
1039  /* The general cleanup that slave applier may need at the end of query. */
1040  inline void cleanup_after_query() {
1042  }
1043  /* The general cleanup that slave applier may need at the end of session. */
1045  if (deferred_events) delete deferred_events;
1046  }
1047 
1048  /**
1049  Helper function to do after statement completion.
1050 
1051  This function is called from an event to complete the group by
1052  either stepping the group position, if the "statement" is not
1053  inside a transaction; or increase the event position, if the
1054  "statement" is inside a transaction.
1055 
1056  @param event_log_pos
1057  Master log position of the event. The position is recorded in the
1058  relay log info and used to produce information for <code>SHOW
1059  SLAVE STATUS</code>.
1060  */
1061  int stmt_done(my_off_t event_log_pos);
1062 
1063  /**
1064  Set the value of a replication state flag.
1065 
1066  @param flag Flag to set
1067  */
1068  void set_flag(enum_state_flag flag) { m_flags |= (1UL << flag); }
1069 
1070  /**
1071  Get the value of a replication state flag.
1072 
1073  @param flag Flag to get value of
1074 
1075  @return @c true if the flag was set, @c false otherwise.
1076  */
1077  bool get_flag(enum_state_flag flag) { return m_flags & (1UL << flag); }
1078 
1079  /**
1080  Clear the value of a replication state flag.
1081 
1082  @param flag Flag to clear
1083  */
1084  void clear_flag(enum_state_flag flag) { m_flags &= ~(1UL << flag); }
1085 
1086  private:
1087  /**
1088  Auxiliary function used by is_in_group.
1089 
1090  The execute thread is in the middle of a statement in the
1091  following cases:
1092  - User_var/Intvar/Rand events have been processed, but the
1093  corresponding Query_log_event has not been processed.
1094  - Table_map or Row events have been processed, and the last Row
1095  event did not have the STMT_END_F set.
1096 
1097  @retval true Replication thread is inside a statement.
1098  @retval false Replication thread is not inside a statement.
1099  */
1100  bool is_in_stmt() const {
1101  bool ret = (m_flags & (1UL << IN_STMT));
1102  DBUG_PRINT("info", ("is_in_stmt()=%d", ret));
1103  return ret;
1104  }
1105  /**
1106  Auxiliary function used by is_in_group.
1107 
1108  @retval true The execute thread is inside a statement or a
1109  transaction, i.e., either a BEGIN has been executed or we are in
1110  the middle of a statement.
1111  @retval false The execute thread thread is not inside a statement
1112  or a transaction.
1113  */
1114  bool is_in_trx_or_stmt() const {
1115  bool ret = is_in_stmt() || (info_thd->variables.option_bits & OPTION_BEGIN);
1116  DBUG_PRINT("info", ("is_in_trx_or_stmt()=%d", ret));
1117  return ret;
1118  }
1119 
1120  public:
1121  /**
1122  A group is defined as the entire range of events that constitute
1123  a transaction or auto-committed statement. It has one of the
1124  following forms:
1125 
1126  (Gtid)? Query(BEGIN) ... (Query(COMMIT) | Query(ROLLBACK) | Xid)
1127  (Gtid)? (Rand | User_var | Int_var)* Query(DDL)
1128 
1129  Thus, to check if the execute thread is in a group, there are
1130  two cases:
1131 
1132  - If the master generates Gtid events (5.7.5 or later, or 5.6 or
1133  later with GTID_MODE=ON), then is_in_group is the same as
1134  info_thd->owned_gtid.sidno != 0, since owned_gtid.sidno is set
1135  to non-zero by the Gtid_log_event and cleared to zero at commit
1136  or rollback.
1137 
1138  - If the master does not generate Gtid events (i.e., master is
1139  pre-5.6, or pre-5.7.5 with GTID_MODE=OFF), then is_in_group is
1140  the same as is_in_trx_or_stmt().
1141 
1142  @retval true Replication thread is inside a group.
1143  @retval false Replication thread is not inside a group.
1144  */
1145  bool is_in_group() const {
1146  bool ret = is_in_trx_or_stmt() || info_thd->owned_gtid.sidno != 0;
1147  DBUG_PRINT("info", ("is_in_group()=%d", ret));
1148  return ret;
1149  }
1150 
1151  int count_relay_log_space();
1152 
1153  /**
1154  Initialize the relay log info. This function does a set of operations
1155  on the rli object like initializing variables, loading information from
1156  repository, setting up name for relay log files and index, MTS recovery
1157  (if necessary), calculating the received GTID set for the channel and
1158  storing the updated rli object configuration into the repository.
1159 
1160  When this function is called in a change master process and the change
1161  master procedure will purge all the relay log files later, there is no
1162  reason to try to calculate the received GTID set of the channel based on
1163  existing relay log files (they will be purged). Allowing reads to existing
1164  relay log files at this point may lead to put the server in a state where
1165  it will be no possible to configure it if it was reset when encryption of
1166  replication log files was ON and the keyring plugin is not available
1167  anymore.
1168 
1169  @param skip_received_gtid_set_recovery When true, skips the received GTID
1170  set recovery.
1171 
1172  @retval 0 Success.
1173  @retval 1 Error.
1174  */
1175  int rli_init_info(bool skip_received_gtid_set_recovery = false);
1176  void end_info();
1177  int flush_info(bool force = false);
1178  int flush_current_log();
1180 
1183  }
1185  future_event_relay_log_pos = log_pos;
1186  }
1187 
1188  inline const char *get_group_master_log_name() {
1189  return group_master_log_name;
1190  }
1192  inline void set_group_master_log_name(const char *log_file_name) {
1193  strmake(group_master_log_name, log_file_name,
1194  sizeof(group_master_log_name) - 1);
1195  }
1196  inline void set_group_master_log_pos(ulonglong log_pos) {
1197  group_master_log_pos = log_pos;
1198  }
1199 
1200  inline const char *get_group_relay_log_name() { return group_relay_log_name; }
1202  inline void set_group_relay_log_name(const char *log_file_name) {
1203  strmake(group_relay_log_name, log_file_name,
1204  sizeof(group_relay_log_name) - 1);
1205  }
1206  inline void set_group_relay_log_name(const char *log_file_name, size_t len) {
1207  strmake(group_relay_log_name, log_file_name, len);
1208  }
1209  inline void set_group_relay_log_pos(ulonglong log_pos) {
1210  group_relay_log_pos = log_pos;
1211  }
1212 
1213  inline const char *get_event_relay_log_name() { return event_relay_log_name; }
1215  inline void set_event_relay_log_name(const char *log_file_name) {
1216  strmake(event_relay_log_name, log_file_name,
1217  sizeof(event_relay_log_name) - 1);
1220  }
1221 
1224  event_relay_log_number = number;
1225  }
1226 
1227  /**
1228  Given the extension number of the relay log, gets the full
1229  relay log path. Currently used in Slave_worker::retry_transaction()
1230 
1231  @param [in] number extension number of relay log
1232  @param[in, out] name The full path of the relay log (per-channel)
1233  to be read by the slave worker.
1234  */
1235  void relay_log_number_to_name(uint number, char name[FN_REFLEN + 1]);
1236  uint relay_log_name_to_number(const char *name);
1237 
1240 
1241  inline void set_event_relay_log_pos(ulonglong log_pos) {
1242  event_relay_log_pos = log_pos;
1243  }
1244  inline const char *get_rpl_log_name() {
1245  return (group_master_log_name[0] ? group_master_log_name : "FIRST");
1246  }
1247 
1248  static size_t get_number_info_rli_fields();
1249 
1250  /**
1251  Indicate that a delay starts.
1252 
1253  This does not actually sleep; it only sets the state of this
1254  Relay_log_info object to delaying so that the correct state can be
1255  reported by SHOW SLAVE STATUS and SHOW PROCESSLIST.
1256 
1257  Requires rli->data_lock.
1258 
1259  @param delay_end The time when the delay shall end.
1260  */
1261  void start_sql_delay(time_t delay_end);
1262 
1263  /* Note that this is cast to uint32 in show_slave_status(). */
1264  time_t get_sql_delay() { return sql_delay; }
1265  void set_sql_delay(time_t _sql_delay) { sql_delay = _sql_delay; }
1266  time_t get_sql_delay_end() { return sql_delay_end; }
1267 
1268  Relay_log_info(bool is_slave_recovery,
1269 #ifdef HAVE_PSI_INTERFACE
1270  PSI_mutex_key *param_key_info_run_lock,
1271  PSI_mutex_key *param_key_info_data_lock,
1272  PSI_mutex_key *param_key_info_sleep_lock,
1273  PSI_mutex_key *param_key_info_thd_lock,
1274  PSI_mutex_key *param_key_info_data_cond,
1275  PSI_mutex_key *param_key_info_start_cond,
1276  PSI_mutex_key *param_key_info_stop_cond,
1277  PSI_mutex_key *param_key_info_sleep_cond,
1278 #endif
1279  uint param_id, const char *param_channel, bool is_rli_fake);
1280  virtual ~Relay_log_info();
1281 
1282  /*
1283  Determines if a warning message on unsafe execution was
1284  already printed out to avoid clutering the error log
1285  with several warning messages.
1286  */
1288 
1289  /*
1290  'sql_thread_kill_accepted is set to true when killed status is recognized.
1291  */
1293 
1295 
1298 
1299  return row_stmt_start_timestamp;
1300  }
1301 
1303 
1305 
1308  }
1309 
1311 
1312  public:
1313  /**
1314  Delete the existing event and set a new one. This class is
1315  responsible for freeing the event, the caller should not do that.
1316 
1317  @return 1 if an error was encountered, 0 otherwise.
1318  */
1320 
1321  /**
1322  Return the current Format_description_log_event.
1323  */
1325  return rli_description_event;
1326  }
1327 
1328  /**
1329  adaptation for the slave applier to specific master versions.
1330  */
1333  ulong current_version);
1334  uchar slave_version_split[3]; // bytes of the slave server version
1335  /*
1336  relay log info repository should be updated on relay log
1337  rotate. But when the transaction is split across two relay logs,
1338  update the repository will cause unexpected results and should
1339  be postponed till the 'commit' of the transaction is executed.
1340 
1341  A flag that set to 'true' when this type of 'forced flush'(at the
1342  time of rotate relay log) is postponed due to transaction split
1343  across the relay logs.
1344  */
1346 
1348 
1350  commit_order_mngr = mngr;
1351  }
1352 
1353  /*
1354  Following set function is required to initialize the 'until_option' during
1355  MTS relay log recovery process.
1356 
1357  Ideally initialization of 'until_option' is done through
1358  rli::init_until_option. This init_until_option requires the main server
1359  thread object and it makes use of the thd->lex->mi object to initialize the
1360  'until_option'.
1361 
1362  But MTS relay log recovery process happens before the main server comes
1363  up at this time the THD object will not be available. Hence the following
1364  set function does the initialization of 'until_option'.
1365  */
1368  until_option = option;
1370  }
1371 
1374  if (until_option) {
1375  delete until_option;
1376  until_option = nullptr;
1377  }
1379  }
1380 
1382 
1383  /**
1384  Get coordinator's RLI. Especially used get the rli from
1385  a slave thread, like this: thd->rli_slave->get_c_rli();
1386  thd could be a SQL thread or a worker thread
1387  */
1388  virtual Relay_log_info *get_c_rli() { return this; }
1389 
1390  virtual const char *get_for_channel_str(bool upper_case = false) const;
1391 
1392  /**
1393  Set replication filter for the channel.
1394  */
1395  inline void set_filter(Rpl_filter *channel_filter) {
1396  rpl_filter = channel_filter;
1397  }
1398 
1399  protected:
1401 
1402  private:
1403  /*
1404  Commit order manager to order commits made by its workers. In context of
1405  Multi Source Replication each worker will be ordered by the coresponding
1406  corrdinator's order manager.
1407  */
1409 
1410  /**
1411  Delay slave SQL thread by this amount of seconds.
1412  The delay is applied per transaction and based on the immediate master's
1413  commit time. Exceptionally, if a server in the replication chain does not
1414  support the commit timestamps in Gtid_log_event, the delay is applied per
1415  event and is based on the event timestamp.
1416  This is set with CHANGE MASTER TO MASTER_DELAY=X.
1417 
1418  Guarded by data_lock. Initialized by the client thread executing
1419  START SLAVE. Written by client threads executing CHANGE MASTER TO
1420  MASTER_DELAY=X. Read by SQL thread and by client threads
1421  executing SHOW SLAVE STATUS. Note: must not be written while the
1422  slave SQL thread is running, since the SQL thread reads it without
1423  a lock when executing flush_info().
1424  */
1425  time_t sql_delay;
1426 
1427  /**
1428  During a delay, specifies the point in time when the delay ends.
1429 
1430  This is used for the SQL_Remaining_Delay column in SHOW SLAVE STATUS.
1431 
1432  Guarded by data_lock. Written by the sql thread. Read by client
1433  threads executing SHOW SLAVE STATUS.
1434  */
1436 
1438 
1439  /*
1440  Before the MASTER_DELAY parameter was added (WL#344), relay_log.info
1441  had 4 lines. Now it has 5 lines.
1442  */
1444 
1445  /*
1446  Before the WL#5599, relay_log.info had 5 lines. Now it has 6 lines.
1447  */
1449 
1450  /*
1451  Before the Id was added (BUG#2334346), relay_log.info
1452  had 6 lines. Now it has 7 lines.
1453  */
1454  static const int LINES_IN_RELAY_LOG_INFO_WITH_ID = 7;
1455 
1456  /*
1457  Add a channel in the slave relay log info
1458  */
1460 
1461  bool read_info(Rpl_info_handler *from);
1462  bool write_info(Rpl_info_handler *to);
1463 
1466 
1467  /*
1468  Runtime state for printing a note when slave is taking
1469  too long while processing a row event.
1470  */
1473 
1474  /**
1475  sets the suffix required for relay log names in multisource
1476  replication. When --relay-log option is not provided, the
1477  names of the relay log files are relaylog.0000x or
1478  relaylog-CHANNEL.00000x in the case of MSR. However, if
1479  that option is provided, then the names of the relay log
1480  files are <relay-log-option>.0000x or
1481  <relay-log-option>-CHANNEL.00000x in the case of MSR.
1482 
1483  The function adds a channel suffix (according to the channel to
1484  file name conventions and conversions) to the relay log file.
1485 
1486  @todo: truncate the log file if length exceeds.
1487 
1488  @param[in, out] buff buffer to store the complete relay log file name
1489  @param[in] buff_size size of buffer buff
1490  @param[in] base_name the base name of the relay log file
1491  */
1492  const char *add_channel_to_relay_log_name(char *buff, uint buff_size,
1493  const char *base_name);
1494 
1495  /*
1496  Applier thread InnoDB priority.
1497  When two transactions conflict inside InnoDB, the one with
1498  greater priority wins.
1499  Priority must be set before applier thread start so that all
1500  executed transactions have the same priority.
1501  */
1503 
1504  /* The object stores and handles START SLAVE UNTIL option */
1506 
1507  public:
1508  /*
1509  The boolean is set to true when the binlog (rli_fake) or slave
1510  (rli_slave) applier thread detaches any engine ha_data
1511  it has dealt with at time of XA START processing.
1512  The boolean is reset to false at the end of XA PREPARE,
1513  XA COMMIT ONE PHASE for the binlog applier, and
1514  at internal rollback of the slave applier at the same time with
1515  the engine ha_data re-attachment.
1516  */
1518  /**
1519  Reference to being applied event. The member is set at event reading
1520  and gets reset at the end of the event lifetime.
1521  See more in @c RLI_current_event_raii that provides the main
1522  interface to the member.
1523  */
1525 
1526  /**
1527  Raised when slave applies and writes to its binary log statement
1528  which is not atomic DDL and has no XID assigned. Checked at commit
1529  time to decide whether it is safe to update slave info table
1530  within the same transaction as the write to binary log or this
1531  should be deffered. The deffered scenario applies for not XIDed events
1532  in which case such update might be lost on recovery.
1533  */
1535 
1536  void set_thd_tx_priority(int priority) { thd_tx_priority = priority; }
1537 
1539 
1540  const char *get_until_log_name();
1543  return until_option != nullptr &&
1545  }
1547  return until_option != nullptr &&
1549  }
1551  return until_option != nullptr &&
1553  }
1554  /**
1555  Intialize until option object when starting slave.
1556 
1557  @param[in] thd The thread object of current session.
1558  @param[in] master_param the parameters of START SLAVE.
1559 
1560  @return int
1561  @retval 0 Succeeds to initialize until option object.
1562  @retval <> 0 A defined error number is return if any error happens.
1563  */
1564  int init_until_option(THD *thd, const LEX_MASTER_INFO *master_param);
1565 
1566  /**
1567  Detaches the engine ha_data from THD. The fact
1568  is memorized in @c is_engine_ha_detached flag.
1569 
1570  @param thd a reference to THD
1571  */
1572 
1573  void detach_engine_ha_data(THD *thd);
1574 
1575  /**
1576  Reattaches the engine ha_data to THD. The fact
1577  is memorized in @c is_engine_ha_detached flag.
1578 
1579  @param thd a reference to THD
1580  */
1581 
1582  void reattach_engine_ha_data(THD *thd);
1583  /**
1584  Drops the engine ha_data flag when it is up.
1585  The method is run at execution points of the engine ha_data
1586  re-attachment.
1587 
1588  @return true when THD has detached the engine ha_data,
1589  false otherwise
1590  */
1591 
1593  bool rc = false;
1594 
1596  rc = !(is_engine_ha_data_detached = false); // return the old value
1597 
1598  return rc;
1599  }
1600 
1601  /**
1602  Execute actions at replicated atomic DLL post rollback time.
1603  This include marking the current atomic DDL query-log-event
1604  as having processed.
1605  This measure is necessary to avoid slave info table update execution
1606  when @c pre_commit() hook is called as part of DDL's eventual
1607  implicit commit.
1608  */
1609  void post_rollback() {
1610  static_cast<Query_log_event *>(current_event)->has_ddl_committed = true;
1611  }
1612 
1613  /**
1614  The method implements a pre-commit hook to add up a new statement
1615  typically to a DDL transaction to update the slave info table.
1616  Note, in the non-transactional repository case the slave info
1617  is updated after successful commit of the main transaction.
1618 
1619  @return false as success, otherwise true
1620  */
1621  bool pre_commit() {
1622  bool rc = false;
1623 
1624  if (is_transactional()) {
1625  static_cast<Query_log_event *>(current_event)->has_ddl_committed = true;
1626  rc = commit_positions();
1627  }
1628  return rc;
1629  }
1630  /**
1631  Cleanup of any side effect that pre_commit() inflicts, including
1632  restore of the last executed group coordinates in case the current group
1633  has been destined to rollback, and signaling to possible waiters
1634  in the positive case.
1635 
1636  @param on_rollback when true the method carries out rollback action
1637  */
1638  virtual void post_commit(bool on_rollback);
1639 };
1640 
1641 bool mysql_show_relaylog_events(THD *thd);
1642 
1643 /**
1644  @param thd a reference to THD
1645  @return true if thd belongs to a Worker thread and false otherwise.
1646 */
1647 inline bool is_mts_worker(const THD *thd) {
1649 }
1650 
1651 /**
1652  Auxiliary function to check if we have a db partitioned MTS
1653  */
1655 
1656 /**
1657  Checks whether the supplied event encodes a (2pc-aware) DDL
1658  that has been already committed.
1659 
1660  @param ev A reference to Query-log-event
1661  @return true when the event is already committed transactional DDL
1662 */
1663 inline bool is_committed_ddl(Log_event *ev) {
1664  return ev->get_type_code() == binary_log::QUERY_EVENT &&
1665  /* has been already committed */
1666  static_cast<Query_log_event *>(ev)->has_ddl_committed;
1667 }
1668 
1669 /**
1670  Checks whether the transaction identified by the argument
1671  is executed by a slave applier thread is an atomic DDL
1672  not yet committed (see @c Query_log_event::has_ddl_committed).
1673  THD::is_operating_substatement_implicitly filters out intermediate
1674  commits done by non-atomic DDLs.
1675  The error-tagged atomic statements are regarded as non-atomic
1676  therefore this predicate returns negative in such case.
1677 
1678  Note that call to is_atomic_ddl() returns "approximate" outcome in
1679  this case as it misses information about type of tables used by the DDL.
1680 
1681  This can be a problem for binlogging slave, as updates to slave info
1682  which happen in the same transaction as write of binary log event
1683  without XID might be lost on recovery. To avoid this problem
1684  RLI::ddl_not_atomic flag is employed which is set to true when
1685  non-atomic DDL without XID is written to the binary log.
1686 
1687  "Approximate" outcome is always fine for non-binlogging slave as in
1688  this case commit happens using one-phase routine for which recovery
1689  is always correct.
1690 
1691  @param thd a pointer to THD describing the transaction context
1692  @return true when a slave applier thread is set to commmit being processed
1693  DDL query-log-event, otherwise returns false.
1694 */
1696  DBUG_ASSERT(thd);
1697 
1698  Relay_log_info *rli = thd->rli_slave;
1699 
1700  /* Early return is about an error in the SQL thread initialization */
1701  if (!rli) return false;
1702 
1703  return ((thd->system_thread == SYSTEM_THREAD_SLAVE_SQL ||
1705  rli->current_event)
1706  ? (rli->is_transactional() &&
1707  /* has not yet committed */
1708  (rli->current_event->get_type_code() ==
1710  !static_cast<Query_log_event *>(rli->current_event)
1711  ->has_ddl_committed) &&
1712  /* unless slave binlogger identified non-atomic */
1713  !rli->ddl_not_atomic &&
1714  /* slave info is not updated when a part of multi-DROP-TABLE
1715  commits */
1717  (is_atomic_ddl(thd, true) &&
1719  /* error-tagged atomic DDL do not update yet slave info */
1720  static_cast<Query_log_event *>(rli->current_event)
1721  ->error_code == 0)
1722  : false;
1723 }
1724 
1725 /**
1726  RAII class to control the slave applier execution context binding
1727  with a being handled event. The main object of control is Query-log-event
1728  containing DDL statement.
1729  The member RLI::current_event is set to refer to an event once it is
1730  read, e.g by next_event() and is reset to NULL at exiting a
1731  read-exec loop. Once the event is destroyed RLI::current_event must be reset
1732  or guaranteed not be accessed anymore.
1733  In the MTS execution the worker is reliably associated with an event
1734  only with the latter is not deferred. This includes Query-log-event.
1735 */
1738 
1739  public:
1741  : m_rli(rli_arg) {
1742  m_rli->current_event = ev;
1743  }
1746 };
1747 
1748 /**
1749  @class MDL_lock_guard
1750 
1751  Utility class to allow RAII pattern with `MDL_request` and `MDL_context`
1752  classes.
1753  */
1755  public:
1756  /**
1757  Constructor that initializes the object and the target `THD` object but
1758  doesn't try to acquire any lock.
1759 
1760  @param target THD object, source for the `MDL_context` to use.
1761  */
1762  MDL_lock_guard(THD *target);
1763  /**
1764  Constructor that initializes the object and the target `THD` object and tries
1765  to acquire the lock identified by `namespace_arg` with MDL type identified by
1766  `mdl_type_arg`.
1767 
1768  If the `blocking` parameter is true, it will instantly try to acquire the
1769  lock and block. If the `blocking` parameter is false, it will first test if
1770  the lock is already acquired and only try to lock if no conflicting lock is
1771  already acquired.
1772 
1773  @param target THD object, source for the `MDL_context` to use.
1774  @param namespace_arg MDL key namespace to acquire the lock from.
1775  @param mdl_type_arg MDL acquisition type
1776  @param blocking whether or not the execution should block if the lock is
1777  already acquired.
1778  */
1779  MDL_lock_guard(THD *target, MDL_key::enum_mdl_namespace namespace_arg,
1780  enum_mdl_type mdl_type_arg, bool blocking = false);
1781  /**
1782  Destructor that unlocks all acquired locks.
1783  */
1784  virtual ~MDL_lock_guard();
1785 
1786  /**
1787  Uses the target `THD` object MDL context to acquire the lock identified by
1788  `namespace_arg` with MDL type identified by `mdl_type_arg`.
1789 
1790  If the `blocking` parameter is true, it will instantly try to acquire the
1791  lock and block. If the `blocking` parameter is false, it will first test if
1792  the lock is already acquired and only try to lock if no conflicting lock is
1793  already acquired.
1794 
1795  The lock is determined to have been acquired if the `THD` object MDL context
1796  hasn't already a lock and the lock is acquired. In other words, if the MDL
1797  context already has acquired the lock, the method will return failure.
1798 
1799  @param namespace_arg MDL key namespace to acquire the lock from.
1800  @param mdl_type_arg MDL acquisition type
1801  @param blocking whether or not the execution should block if the lock is
1802  already acquired.
1803 
1804  @return false if the lock has been acquired by this method invocation and
1805  true if not.
1806  */
1807  bool lock(MDL_key::enum_mdl_namespace namespace_arg,
1808  enum_mdl_type mdl_type_arg, bool blocking = false);
1809  /**
1810  Returns whether or not the lock as been acquired within this object
1811  life-cycle.
1812 
1813  @return true if the lock has been acquired within this object life-cycle.
1814  */
1815  bool is_locked();
1816 
1817  private:
1818  /** The `THD` object holding the MDL context used for acquiring/releasing. */
1820  /** The MDL request holding the MDL ticket issued upon acquisition */
1822 };
1823 
1824 #endif /* RPL_RLI_H */
Format_description_log_event * get_rli_description_event() const
Return the current Format_description_log_event.
Definition: rpl_rli.h:1324
void set_group_relay_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1209
void set_flag(enum_state_flag flag)
Set the value of a replication state flag.
Definition: rpl_rli.h:1068
bool is_relay_log_recovery
Definition: rpl_rli.h:228
#define OPTION_BEGIN
Definition: query_options.h:74
unsigned long long int ulonglong
Definition: my_inttypes.h:74
virtual ~MDL_lock_guard()
Destructor that unlocks all acquired locks.
Definition: rpl_rli.cc:2602
std::unique_ptr< T, void(*)(T *)> unique_ptr_with_deleter
std::unique_ptr, but with a custom delete function.
Definition: map_helpers.h:118
Sid_map * get_sid_map()
Definition: rpl_rli.h:452
void clear_processing_trx()
Clears the processing_trx structure fields.
Definition: rpl_rli.h:320
Instrumentation helpers for mutexes.
uint event_relay_log_number
Definition: rpl_rli.h:393
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:93
bool is_satisfied_at_start_slave()
Check if the until option is already satisfied at coordinator starting.
Definition: rpl_slave_until_options.h:66
void set_group_relay_log_name(const char *log_file_name, size_t len)
Definition: rpl_rli.h:1206
Rpl_filter.
Definition: rpl_filter.h:211
int stmt_done(my_off_t event_log_pos)
Helper function to do after statement completion.
Definition: rpl_rli.cc:1203
unsigned char uchar
Definition: my_inttypes.h:51
Structure to hold parameters for CHANGE MASTER, START SLAVE, and STOP SLAVE.
Definition: sql_lex.h:304
ulonglong event_relay_log_pos
Definition: rpl_rli.h:394
bool is_relay_log_truncated()
Definition: rpl_rli.h:450
t pos
Definition: dbug_analyze.cc:148
ulonglong log_space_limit
Definition: rpl_rli.h:518
void clear_sql_delay()
Reset the delay.
Definition: rpl_rli.h:534
char ign_master_log_name_end[FN_REFLEN]
Definition: rpl_rli.h:586
Definition: rpl_rli.h:561
Checkable_rwlock * get_sid_lock()
Definition: rpl_rli.h:454
Definition: rpl_slave_commit_order_manager.h:37
mysql_cond_t pending_jobs_cond
Definition: rpl_rli.h:799
enum_mts_parallel_type
Definition: rpl_mts_submode.h:44
Gtid_set * gtid_set
Definition: rpl_rli.h:415
void started_processing(Gtid_log_event *gtid_log_ev_arg)
Stores the details of the transaction which has just started processing.
Definition: rpl_rli.h:290
TABLE_LIST * next_global
Definition: table.h:3028
void clear_flag(enum_state_flag flag)
Clear the value of a replication state flag.
Definition: rpl_rli.h:1084
bool workers_array_initialized
Definition: rpl_rli.h:795
void clear_mts_recovery_groups()
Definition: rpl_rli.h:982
ssize_t count
Definition: memcached.c:386
ulonglong mts_groups_assigned
Definition: rpl_rli.h:886
my_off_t get_until_log_pos()
Definition: rpl_rli.cc:2336
Until_option * until_option
Definition: rpl_rli.h:1505
Definition: rpl_mts_submode.h:52
#define base_name(A)
Definition: my_sys.h:713
void set_commit_order_manager(Commit_order_manager *mngr)
Definition: rpl_rli.h:1349
const string name("\ame\)
bool cached_charset_compare(char *charset) const
Definition: rpl_rli.cc:1193
my_off_t new_group_relay_log_pos
Definition: rpl_rli.h:932
void finish()
Sets the final information, copy processing info to last_processed and clears processing info...
Definition: rpl_gtid_misc.cc:509
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
ulong mts_recovery_group_cnt
Definition: rpl_rli.h:852
enum enum_thread_type system_thread
Definition: sql_class.h:2105
Definition: rpl_info_handler.h:55
void rewind()
Definition: rpl_utility.cc:1175
void finished_processing()
When the processing of a transaction is completed, that timestamp is recorded, the information is cop...
Definition: rpl_rli.h:307
void post_rollback()
Execute actions at replicated atomic DLL post rollback time.
Definition: rpl_rli.h:1609
Some integer typedefs for easier portability.
uint relay_log_name_to_number(const char *name)
Definition: rpl_rli.cc:2302
Definition: binlog.h:325
void deinit_workers()
The method to invoke at slave threads stop.
Definition: rpl_rli.cc:252
time_t set_row_stmt_start_timestamp()
Definition: rpl_rli.h:1296
void set_thd_tx_priority(int priority)
Definition: rpl_rli.h:1536
bool replicate_same_server_id
Definition: rpl_rli.h:216
bool long_find_row_note_printed
Definition: rpl_rli.h:1472
bool read_info(Rpl_info_handler *from)
Definition: rpl_rli.cc:1879
ulonglong max_updated_index
Definition: rpl_rli.h:845
void reattach_engine_ha_data(THD *thd)
Reattaches the engine ha_data to THD.
Definition: rpl_rli.cc:2435
struct timespec ts_exec[2]
Definition: rpl_rli.h:911
volatile long mts_wq_excess_cnt
Definition: rpl_rli.h:837
Contains the classes representing events occurring in the replication stream.
ulonglong log_space_total
Definition: rpl_rli.h:518
static const int LINES_IN_RELAY_LOG_INFO_WITH_ID
Definition: rpl_rli.h:1454
const char * str
Definition: mysql_lex_string.h:40
Checkable_rwlock * get_sid_lock() const
Return the sid_lock.
Definition: rpl_gtid.h:685
void cleanup_context(THD *, bool)
Definition: rpl_rli.cc:1250
bool is_group_master_log_pos_invalid
Definition: rpl_rli.h:510
void set_master_info(Master_info *info)
Definition: rpl_rli.cc:1787
Definition: rpl_rli.h:564
void bitmap_free(MY_BITMAP *map)
Definition: my_bitmap.cc:186
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:179
time_t last_event_start_time
Definition: rpl_rli.h:734
bool belongs_to_client()
Definition: rpl_rli.h:190
struct System_variables variables
Definition: sql_class.h:956
struct slave_job_item Slave_job_item
bool reinit_sql_thread_io_cache(const char *log, bool need_data_lock)
LEX_CSTRING table_name
Definition: table.h:725
ulonglong mts_pending_jobs_size
Definition: rpl_rli.h:802
For binlog version 4.
Definition: log_event.h:1458
void set_event_start_pos(my_off_t pos)
Definition: rpl_rli.h:1238
size_t slave_patternload_file_size
Definition: rpl_rli.h:594
char new_group_relay_log_name[FN_REFLEN]
Definition: rpl_rli.h:931
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3562
bool is_mts_in_group()
returns true if Coordinator is scheduling events belonging to the same group and has not reached yet ...
Definition: rpl_rli.h:1005
bool empty() const
Definition: prealloced_array.h:184
enum_return_status
Generic return type for many functions that can succeed or fail.
Definition: rpl_gtid.h:118
void _add_gtid(rpl_sidno sidno, rpl_gno gno)
Adds the given GTID to this Gtid_set.
Definition: rpl_gtid.h:1364
enum_state_flag
Flags for the state of the replication.
Definition: rpl_rli.h:175
void slave_close_thread_tables(THD *)
Definition: rpl_rli.cc:1382
Sid_map * get_sid_map() const
Return the Sid_map associated with this Gtid_set.
Definition: rpl_gtid.h:1734
ulong opt_slave_parallel_workers
Definition: rpl_rli.h:841
ulonglong option_bits
OPTION_xxx constants, e.g. OPTION_PROFILING.
Definition: system_variables.h:203
bool set_info_search_keys(Rpl_info_handler *to)
To search in the slave repositories, each slave info object (mi, rli or worker) should use a primary ...
Definition: rpl_rli.cc:1973
volatile ulong abort_pos_wait
Definition: rpl_rli.h:542
ulong wq_size_waits_cnt
Definition: rpl_rli.h:889
static const int LINES_IN_RELAY_LOG_INFO_WITH_WORKERS
Definition: rpl_rli.h:1448
TODO: Move this structure to libbinlogevents/include/control_events.h when we start using C++11...
Definition: rpl_gtid.h:924
Represents a bidirectional map between SID and SIDNO.
Definition: rpl_gtid.h:582
void cached_charset_invalidate()
Last charset (6 bytes) seen by slave SQL thread is cached here; it helps the thread save 3 get_charse...
Definition: rpl_rli.cc:1185
Definition: rpl_rli.h:875
std::atomic< int32 > atomic_channel_open_temp_tables
Definition: rpl_rli.h:243
bool reported_unsafe_warning
Definition: rpl_rli.h:1287
Prealloced_array< Slave_job_item, 8 > curr_group_da
Definition: rpl_rli.h:818
Mts_submode * current_mts_submode
Definition: rpl_rli.h:968
void store_transient_error(uint transient_errno_arg, const char *transient_err_message_arg, ulong trans_retries_arg)
Stores the information about the last transient error in the current transaction, namely: the error n...
Definition: rpl_gtid_misc.cc:557
bool reset_group_relay_log_pos(const char **errmsg)
Reset group_relay_log_name and group_relay_log_pos to the start of the first relay log file...
Definition: rpl_rli.cc:480
void clear_gtid_monitoring_info()
Clears the Gtid_monitoring_info fields.
Definition: rpl_rli.h:325
Definition: rpl_info_factory.h:42
~RLI_current_event_raii()
Definition: rpl_rli.h:1745
void set_group_master_log_name(const char *log_file_name)
Definition: rpl_rli.h:1192
char event_relay_log_name[FN_REFLEN]
Definition: rpl_rli.h:391
Gtid_monitoring_info * gtid_monitoring_info
Stores information on the last processed transaction or the transaction that is currently being proce...
Definition: rpl_rli.h:440
bool is_satisfied_after_dispatching_event()
check if the until option is satisfied after applied or dispatched a event.
Definition: rpl_slave_until_options.h:96
static const int LINES_IN_RELAY_LOG_INFO_WITH_CHANNEL
Definition: rpl_rli.h:1459
THD * info_thd
Definition: rpl_info.h:77
Definition: thread_type.h:36
Commit_order_manager * commit_order_mngr
Definition: rpl_rli.h:1408
volatile my_off_t group_master_log_pos
Definition: rpl_rli.h:412
Instrumentation helpers for conditions.
void notify_relay_log_change()
Invalidates cached until_log_name and event_relay_log_name comparison result.
Definition: rpl_rli.h:606
void cleanup_after_session()
Definition: rpl_rli.h:1044
Specifies that the transaction has been assigned a GTID (UUID:NUMBER).
Definition: rpl_gtid.h:3539
void add_logged_gtid(rpl_sidno sidno, rpl_gno gno)
Definition: rpl_rli.h:456
uchar slave_version_split[3]
Definition: rpl_rli.h:1334
bool sql_force_rotate_relay
Definition: rpl_rli.h:526
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
This is the abstract base class for slave start until options.
Definition: rpl_slave_until_options.h:55
time_t mts_last_online_stat
Definition: rpl_rli.h:921
Master_info * mi
Definition: rpl_rli.h:240
ulonglong mts_events_assigned
Definition: rpl_rli.h:885
bool is_satisfied_before_dispatching_event(const Log_event *ev)
check if the until option is satisfied before applying or dispatching a event.
Definition: rpl_slave_until_options.h:82
virtual void post_commit(bool on_rollback)
Cleanup of any side effect that pre_commit() inflicts, including restore of the last executed group c...
Definition: rpl_rli.cc:2497
Definition: rpl_rli.h:557
mysql_mutex_t mts_gaq_LOCK
Definition: rpl_rli.h:207
void set_group_relay_log_name(const char *log_file_name)
Definition: rpl_rli.h:1202
Definition: rpl_rli.h:253
Definition: table.h:1294
unsigned long long uint64
Definition: my_inttypes.h:69
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:49
uint sql_slave_skip_counter
a copy of active_mi->rli->slave_skip_counter, for showing in SHOW GLOBAL VARIABLES, INFORMATION_SCHEMA.GLOBAL_VARIABLES and @sql_slave_skip_counter without taking all the mutexes needed to access active_mi->rli->slave_skip_counter properly.
Definition: rpl_slave.cc:8382
bool is_processing_trx()
Definition: rpl_rli.h:312
Group Assigned Queue whose first element identifies first gap in committed sequence.
Definition: rpl_rli_pdb.h:335
bool is_mts_recovery() const
returns true if there is any gap-group of events to execute at slave starting phase.
Definition: rpl_rli.h:980
mysql_mutex_t slave_worker_hash_lock
Definition: rpl_rli.h:770
bool slave_thread
Definition: sql_class.h:2298
void retried_processing(uint transient_errno_arg, const char *transient_err_message_arg, ulong trans_retries_arg)
When a transaction is retried, the error number and message, and total number of retries are stored...
Definition: rpl_rli.h:336
bool is_locked()
Returns whether or not the lock as been acquired within this object life-cycle.
Definition: rpl_rli.cc:2609
void cleanup_after_query()
Definition: rpl_rli.h:1040
bool is_in_stmt() const
Auxiliary function used by is_in_group.
Definition: rpl_rli.h:1100
bool recovery_groups_inited
Definition: rpl_rli.h:851
long mts_worker_underrun_level
Definition: rpl_rli.h:838
ulonglong future_event_relay_log_pos
Definition: rpl_rli.h:395
virtual int set_rli_description_event(Format_description_log_event *fdle)
Delete the existing event and set a new one.
Definition: rpl_rli.cc:2025
void inc_event_relay_log_pos()
Definition: rpl_rli.h:631
Definition: rpl_info.h:42
uint32 m_flags
Definition: rpl_rli.h:1437
time_t last_master_timestamp
Definition: rpl_rli.h:528
bool mts_recovery_group_seen_begin
Definition: rpl_rli.h:854
Definition: binlog_event.h:279
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:165
ulong mts_wq_no_underrun_cnt
Definition: rpl_rli.h:895
char group_relay_log_name[FN_REFLEN]
Event group means a group of events of a transaction.
Definition: rpl_rli.h:389
Flag counter.
Definition: rpl_rli.h:180
bool pre_commit()
The method implements a pre-commit hook to add up a new statement typically to a DDL transaction to u...
Definition: rpl_rli.h:1621
#define DBUG_ASSERT(A)
Definition: my_dbug.h:183
ulong mts_recovery_index
Definition: rpl_rli.h:853
char group_master_log_name[FN_REFLEN]
Definition: rpl_rli.h:411
int flush_info(bool force=false)
Stores the file and position where the execute-slave thread are in the relay log: ...
Definition: rpl_rli.cc:1840
Definition: rpl_rli.h:878
size_t size() const
Definition: prealloced_array.h:185
char * strmake(char *dst, const char *src, size_t length)
Definition: strmake.cc:42
int wait_for_gtid_set(THD *thd, const char *gtid, double timeout, bool update_THD_status=true)
Wait for a GTID set to be executed.
Definition: rpl_rli.cc:739
Legends running throughout the module:
Definition: rpl_rli_pdb.h:72
int inc_group_relay_log_pos(ulonglong log_pos, bool need_data_lock, bool force=false)
Last executed event group coordinates are updated and optionally forcibly flushed to a repository...
Definition: rpl_rli.cc:901
time_t get_sql_delay()
Definition: rpl_rli.h:1264
structure to define some default "config_option" option settings
Definition: innodb_config.h:180
int rli_init_info(bool skip_received_gtid_set_recovery=false)
Initialize the relay log info.
Definition: rpl_rli.cc:1471
ulong mts_wq_overfill_cnt
Definition: rpl_rli.h:903
Definition: rpl_rli.h:164
It is an abstract class for until master position and until relay log position.
Definition: rpl_slave_until_options.h:130
ulong trans_retries
Definition: rpl_rli.h:576
bool is_transactional()
Definition: rpl_info.h:110
bool is_mts_worker(const THD *thd)
Definition: rpl_rli.h:1647
ulong exit_counter
Definition: rpl_rli.h:844
void assert_some_lock() const
Assert that some thread holds either the read or the write lock.
Definition: rpl_gtid.h:522
bool is_until_satisfied_after_dispatching_event()
Definition: rpl_rli.h:1550
bool write_info(Rpl_info_handler *to)
Definition: rpl_rli.cc:1982
malloc_unordered_map< std::string, unique_ptr_with_deleter< db_worker_hash_entry > > mapping_db_to_worker
Definition: rpl_rli.h:767
volatile uint32 slave_skip_counter
Definition: rpl_rli.h:541
void start_sql_delay(time_t delay_end)
Indicate that a delay starts.
Definition: rpl_rli.cc:1873
enum Relay_log_info::@84 commit_timestamps_status
the status of the commit timestamps for the relay log
mysql_mutex_t log_space_lock
Definition: rpl_rli.h:543
virtual ~Relay_log_info()
Definition: rpl_rli.cc:254
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys...
Definition: map_helpers.h:175
Slave_worker * get_worker(size_t n)
Definition: rpl_rli.h:946
uint64 original_commit_timestamp
Definition: rpl_rli.h:737
time_t sql_delay
Delay slave SQL thread by this amount of seconds.
Definition: rpl_rli.h:1425
bool is_atomic_ddl_commit_on_slave(THD *thd)
Checks whether the transaction identified by the argument is executed by a slave applier thread is an...
Definition: rpl_rli.h:1695
void set_event_relay_log_number(uint number)
Definition: rpl_rli.h:1223
int count_relay_log_space()
Definition: rpl_rli.cc:459
virtual const char * get_for_channel_str(bool upper_case=false) const
Definition: rpl_rli.cc:2310
Definition: rpl_rli.h:879
RAII class to control the slave applier execution context binding with a being handled event...
Definition: rpl_rli.h:1736
mysql_mutex_t exit_count_lock
Definition: rpl_rli.h:800
Definition: my_bitmap.h:42
bool is_group_relay_log_name_invalid(const char **errmsg)
Check if group_relay_log_name is in index file.
Definition: rpl_rli.cc:494
bool gtid_retrieved_initialized
Definition: rpl_rli.h:425
my_off_t new_group_master_log_pos
Definition: rpl_rli.h:930
TABLE_SHARE * s
Definition: table.h:1295
int get_thd_tx_priority()
Definition: rpl_rli.h:1538
TABLE * save_temporary_tables
Definition: rpl_rli.h:237
Maps table id&#39;s (integers) to table pointers.
Definition: rpl_tblmap.h:50
bool unflag_detached_engine_ha_data()
Drops the engine ha_data flag when it is up.
Definition: rpl_rli.h:1592
ulonglong get_future_event_relay_log_pos()
Definition: rpl_rli.h:1181
std::vector< Slave_worker * > workers_copy_pfs
Definition: rpl_rli.h:784
This is the abstract base class for binary log events.
Definition: log_event.h:517
ulong retried_trans
Definition: rpl_rli.h:576
volatile ulong mts_wq_overrun_cnt
Definition: rpl_rli.h:888
bool mysql_show_relaylog_events(THD *thd)
Execute a SHOW RELAYLOG EVENTS statement.
Definition: rpl_rli.cc:1426
struct timespec last_clock
Identifies the last time a checkpoint routine has been executed.
Definition: rpl_rli.h:599
bool inited_hash_workers
Definition: rpl_rli.h:768
size_t get_worker_count()
Definition: rpl_rli.h:935
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:12862
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Definition: rpl_rli.h:877
Log_event * data
Definition: rpl_rli.h:88
unsigned int len
Definition: dbug_analyze.cc:216
bool is_processing_trx_set()
Returns true if the processing_trx is set, false otherwise.
Definition: rpl_gtid_misc.cc:539
unsigned int uint
Definition: uca-dump.cc:29
void end_info()
Definition: rpl_rli.cc:1756
The replication thread is inside a statement.
Definition: rpl_rli.h:177
#define FN_REFLEN
Definition: my_io.h:82
MYSQL_BIN_LOG relay_log
Definition: rpl_rli.h:222
long long int longlong
Definition: my_inttypes.h:73
mysql_mutex_t data_lock
Definition: rpl_info.h:57
table_mapping m_table_map
Definition: rpl_rli.h:694
mysql_mutex_t mts_temp_table_LOCK
Definition: rpl_rli.h:202
void fill_coord_err_buf(loglevel level, int err_code, const char *buff_coord) const
Update the error number, message and timestamp fields.
Definition: rpl_rli.cc:524
uint relay_number
Definition: rpl_rli.h:89
time_t my_time(int)
Return current time.
Definition: my_systime.h:169
uint32_t uint32
Definition: my_inttypes.h:62
Gtid owned_gtid
The GTID of the currently owned transaction.
Definition: sql_class.h:3324
void set_future_event_relay_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1184
Gtid_monitoring_info * get_gtid_monitoring_info()
Definition: rpl_rli.h:261
Slave_worker_array workers
Definition: rpl_rli.h:762
Definition: rpl_rli.h:251
MY_BITMAP recovery_groups
Definition: rpl_rli.h:850
void set_long_find_row_note_printed()
Definition: rpl_rli.h:1304
bool m_relay_log_truncated
It will be set to true when receiver truncated relay log for some reason.
Definition: rpl_rli.h:447
Prealloced_array< db_worker_hash_entry *, 4 > curr_group_assigned_parts
Definition: rpl_rli.h:816
void start(Gtid gtid_arg, ulonglong original_ts_arg, ulonglong immediate_ts_arg, bool skipped_arg=false)
Sets the initial monitoring information.
Definition: rpl_gtid_misc.cc:473
Relay_log_info(bool is_slave_recovery, PSI_mutex_key *param_key_info_run_lock, PSI_mutex_key *param_key_info_data_lock, PSI_mutex_key *param_key_info_sleep_lock, PSI_mutex_key *param_key_info_thd_lock, PSI_mutex_key *param_key_info_data_cond, PSI_mutex_key *param_key_info_start_cond, PSI_mutex_key *param_key_info_stop_cond, PSI_mutex_key *param_key_info_sleep_cond, uint param_id, const char *param_channel, bool is_rli_fake)
Definition: rpl_rli.cc:92
bool lock(MDL_key::enum_mdl_namespace namespace_arg, enum_mdl_type mdl_type_arg, bool blocking=false)
Uses the target THD object MDL context to acquire the lock identified by namespace_arg with MDL type...
Definition: rpl_rli.cc:2583
void clear()
Clear all monitoring information.
Definition: rpl_gtid_misc.cc:454
uint tables_to_lock_count
Definition: rpl_rli.h:693
A pending metadata lock request.
Definition: mdl.h:782
const char * get_group_relay_log_name()
Definition: rpl_rli.h:1200
bool sql_thread_kill_accepted
Definition: rpl_rli.h:1292
enum Relay_log_info::@85 until_condition
Instrumentation helpers for mutexes.
mysql_cond_t slave_worker_hash_cond
Definition: rpl_rli.h:771
Definition: rpl_rli.h:255
ulong recovery_parallel_workers
Definition: rpl_rli.h:846
void reset_row_stmt_start_timestamp()
Definition: rpl_rli.h:1302
Definition: rpl_rli.h:559
Common header for many mysys elements.
Definition: rpl_rli.h:558
Commit_order_manager * get_commit_order_manager()
Definition: rpl_rli.h:1347
unsigned long long int original_commit_timestamp
Timestamp when the transaction was committed on the originating master.
Definition: control_events.h:810
bool is_mts_db_partitioned(Relay_log_info *rli)
Auxiliary function to check if we have a db partitioned MTS
Definition: rpl_rli.cc:2306
bool is_in_group() const
A group is defined as the entire range of events that constitute a transaction or auto-committed stat...
Definition: rpl_rli.h:1145
int flush_current_log()
Definition: rpl_rli.cc:1778
ulonglong get_group_relay_log_pos()
Definition: rpl_rli.h:1201
void reset_notified_relay_log_change()
While a group is executed by a Worker the relay log can change.
Definition: rpl_rli.cc:315
static const int LINES_IN_RELAY_LOG_INFO_WITH_DELAY
Definition: rpl_rli.h:1443
volatile ulong mts_wq_underrun_w_id
Definition: rpl_rli.h:826
Represents a set of GTIDs.
Definition: rpl_gtid.h:1302
#define HAVE_PSI_INTERFACE
Definition: my_psi_config.h:38
Definition of the global "loglevel" enumeration.
bool get_table_data(TABLE *table_arg, table_def **tabledef_var, TABLE **conv_table_var) const
Definition: rpl_rli.h:698
Binary log event definitions.
bool is_until_satisfied_before_dispatching_event(const Log_event *ev)
Definition: rpl_rli.h:1546
static bool update_timestamp(THD *thd, set_var *var)
Definition: sys_vars.cc:4960
bool mts_finalize_recovery()
Called when gaps execution is ended so it is crash-safe to reset the last session Workers info...
Definition: rpl_rli.cc:399
void set_event_relay_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1241
Utility class to allow RAII pattern with MDL_request and MDL_context classes.
Definition: rpl_rli.h:1754
void clear_until_option()
Definition: rpl_rli.h:1372
unsigned long my_off_t
Definition: my_inttypes.h:87
const char * add_channel_to_relay_log_name(char *buff, uint buff_size, const char *base_name)
sets the suffix required for relay log names in multisource replication.
Definition: rpl_rli.cc:1153
Relay_log_info * m_rli
Definition: rpl_rli.h:1737
bool force_flush_postponed_due_to_split_trans
Definition: rpl_rli.h:1345
void set_group_master_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1196
Stores information to monitor a transaction during the different replication stages.
Definition: rpl_gtid.h:1161
int purge_relay_logs(THD *thd, const char **errmsg, bool delete_only=false)
Purges relay logs.
Definition: rpl_rli.cc:1006
char slave_patternload_file[FN_REFLEN]
Definition: rpl_rli.h:593
std::atomic< longlong > mts_total_wait_overlap
Definition: rpl_rli.h:897
void detach_engine_ha_data(THD *thd)
Detaches the engine ha_data from THD.
Definition: rpl_rli.cc:2425
Slave_worker * last_assigned_worker
Definition: rpl_rli.h:806
int init_until_option(THD *thd, const LEX_MASTER_INFO *master_param)
Intialize until option object when starting slave.
Definition: rpl_rli.cc:2345
void set_filter(Rpl_filter *channel_filter)
Set replication filter for the channel.
Definition: rpl_rli.h:1395
mysql_cond_t log_space_cond
Definition: rpl_rli.h:544
Definition: rpl_mi.h:85
PSI_memory_key key_memory_db_worker_hash_entry
Definition: psi_memory_key.cc:111
enum Relay_log_info::@86 mts_group_status
ulonglong group_relay_log_pos
Definition: rpl_rli.h:390
bool is_time_for_mts_checkpoint()
Check if it is time to compute MTS checkpoint.
Definition: rpl_rli.cc:2563
ulong mts_slave_worker_queue_len_max
Definition: rpl_rli.h:801
const char * get_group_master_log_name()
Definition: rpl_rli.h:1188
static int flag
Definition: hp_test1.cc:39
ulong slave_parallel_workers
Definition: rpl_rli.h:842
ulonglong stats_read_time
Definition: rpl_rli.h:910
bool get_flag(enum_state_flag flag)
Get the value of a replication state flag.
Definition: rpl_rli.h:1077
bool is_operating_substatement_implicitly
Definition: sql_class.h:1927
virtual Relay_log_info * get_c_rli()
Get coordinator&#39;s RLI.
Definition: rpl_rli.h:1388
PSI_mutex_key m_key_mts_temp_table_LOCK
Definition: rpl_rli.h:196
my_off_t event_start_pos
Definition: rpl_rli.h:398
ulonglong stats_exec_time
Definition: rpl_rli.h:909
uint get_event_relay_log_number()
Definition: rpl_rli.h:1222
const Gtid_set * get_gtid_set() const
Definition: rpl_rli.h:472
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
bool is_engine_ha_data_detached
Definition: rpl_rli.h:1517
THD * m_target
The THD object holding the MDL context used for acquiring/releasing.
Definition: rpl_rli.h:1819
bool mts_wq_oversize
Definition: rpl_rli.h:804
bool is_committed_ddl(Log_event *ev)
Checks whether the supplied event encodes a (2pc-aware) DDL that has been already committed...
Definition: rpl_rli.h:1663
Definition: rpl_rli_pdb.h:515
const char * get_until_log_name()
Definition: rpl_rli.cc:2327
Format_description_log_event * rli_description_event
Definition: rpl_rli.h:1400
enum_return_status add_gtid_set(const Gtid_set *gtid_set)
Adds a GTID set to received GTID set.
Definition: rpl_rli.cc:2317
static size_t get_number_info_rli_fields()
Definition: rpl_rli.cc:1869
Slave_committed_queue * gaq
Definition: rpl_rli.h:811
Definition: rpl_rli.h:563
void reset_notified_checkpoint(ulong count, time_t new_ts, bool update_timestamp=false)
While a group is executed by a Worker the relay log can change.
Definition: rpl_rli.cc:342
void relay_log_number_to_name(uint number, char name[FN_REFLEN+1])
Given the extension number of the relay log, gets the full relay log path.
Definition: rpl_rli.cc:2289
Rpl_filter * rpl_filter
Definition: rpl_rli.h:171
ABI for instrumented mutexes.
enum_return_status ensure_sidno(rpl_sidno sidno)
Allocates space for all sidnos up to the given sidno in the array of intervals.
Definition: rpl_gtid_set.cc:132
bool ddl_not_atomic
Raised when slave applies and writes to its binary log statement which is not atomic DDL and has no X...
Definition: rpl_rli.h:1534
Common #defines and includes for file and socket I/O.
bool mts_end_group_sets_max_dbs
Definition: rpl_rli.h:823
enum_mts_parallel_type channel_mts_submode
Definition: rpl_rli.h:966
void set_sql_delay(time_t _sql_delay)
Definition: rpl_rli.h:1265
Deferred_log_events * deferred_events
Definition: rpl_rli.h:745
rpl_sidno sidno
SIDNO of this Gtid.
Definition: rpl_gtid.h:926
A Query event is written to the binary log whenever the database is modified on the master...
Definition: log_event.h:1242
void unset_long_find_row_note_printed()
Definition: rpl_rli.h:1306
Relay_log_info & operator=(const Relay_log_info &info)
void close_temporary_tables()
Definition: rpl_rli.cc:973
void set_current_event(Log_event *ev)
Definition: rpl_rli.h:1744
bool rli_fake
Definition: rpl_rli.h:423
bool is_long_find_row_note_printed()
Definition: rpl_rli.h:1310
loglevel
Definition: my_loglevel.h:32
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:53
const char * get_event_relay_log_name()
Definition: rpl_rli.h:1213
int wait_for_pos(THD *thd, String *log_name, longlong log_pos, double timeout)
Waits until the SQL thread reaches (has executed up to) the log/position or timed out...
Definition: rpl_rli.cc:560
ulonglong get_event_relay_log_pos()
Definition: rpl_rli.h:1214
time_t get_row_stmt_start_timestamp()
Definition: rpl_rli.h:1294
Prealloced_array< Slave_worker *, 4 > Slave_worker_array
Definition: rpl_rli.h:85
volatile ulong pending_jobs
Definition: rpl_rli.h:797
enum_mdl_namespace
Object namespaces.
Definition: mdl.h:383
mysql_cond_t logical_clock_cond
Definition: rpl_rli.h:208
bool is_commit_in_middle_of_statement
Definition: sql_class.h:3458
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:44
Definition: rpl_rli.h:87
bool is_atomic_ddl(THD *thd, bool using_trans_arg)
The function lists all DDL instances that are supported for crash-recovery (WL9175).
Definition: log_event.cc:3668
MDL_request m_request
The MDL request holding the MDL ticket issued upon acquisition.
Definition: rpl_rli.h:1821
void set_until_option(Until_option *option)
Definition: rpl_rli.h:1366
rpl_gno get_gno() const
Return the GNO for this GTID.
Definition: log_event.h:3719
uint rli_checkpoint_seqno
Definition: rpl_rli.h:847
enum_gtid_type get_type() const
Return the gtid type for this Gtid_log_event: this can be either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
Definition: log_event.h:3683
It is used to record the original query for the rows events in RBR.
Definition: log_event.h:3460
void notify_relay_log_truncated()
Receiver thread notifies that it truncated some data from relay log.
Definition: rpl_rli.cc:2552
char cached_charset[6]
Definition: rpl_rli.h:567
void set_event_relay_log_name(const char *log_file_name)
Definition: rpl_rli.h:1215
Log_event_type get_type_code() const
Definition: log_event.h:774
ulonglong ign_master_log_pos_end
Definition: rpl_rli.h:587
Log_event * current_event
Reference to being applied event.
Definition: rpl_rli.h:1524
int thd_tx_priority
Definition: rpl_rli.h:1502
Log info(cout, "NOTE")
A table definition from the master.
Definition: rpl_utility.h:245
Definition: table.h:2442
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:429
ulong adapt_to_master_version_updown(ulong master_version, ulong current_version)
The method compares two supplied versions and carries out down- or up- grade customization of executi...
Definition: rpl_rli.cc:2225
Extend the normal table list with a few new fields needed by the slave thread, but nowhere else...
Definition: rpl_utility.h:462
bool gtid_timestamps_warning_logged
Variable is set to true as long as original_commit_timestamp > immediate_commit_timestamp so that the...
Definition: rpl_rli.h:355
bool is_parallel_exec() const
returns true if events are to be executed in parallel
Definition: rpl_rli.h:993
my_off_t relay_pos
Definition: rpl_rli.h:90
LEX_CSTRING db
Definition: table.h:724
const char * get_rpl_log_name()
Definition: rpl_rli.h:1244
void started_processing(Gtid gtid_arg, ulonglong original_ts_arg, ulonglong immediate_ts_arg, bool skipped=false)
Stores the details of the transaction which has just started processing.
Definition: rpl_rli.h:276
void init_workers(ulong)
The method to invoke at slave threads start.
Definition: rpl_rli.cc:233
Prealloced_array< ulong, 16 > least_occupied_workers
Definition: rpl_rli.h:920
void clear_relay_log_truncated()
Applier clears the flag after it handled the situation.
Definition: rpl_rli.cc:2558
ulonglong get_group_master_log_pos()
Definition: rpl_rli.h:1191
ulonglong mts_pending_jobs_size_max
Definition: rpl_rli.h:803
MDL_lock_guard(THD *target)
Constructor that initializes the object and the target THD object but doesn&#39;t try to acquire any loc...
Definition: rpl_rli.cc:2573
char new_group_master_log_name[FN_REFLEN]
Storage for holding newly computed values for the last executed event group coordinates while the cur...
Definition: rpl_rli.h:929
bool is_in_trx_or_stmt() const
Auxiliary function used by is_in_group.
Definition: rpl_rli.h:1114
RPL_TABLE_LIST * tables_to_lock
Definition: rpl_rli.h:692
time_t get_sql_delay_end()
Definition: rpl_rli.h:1266
Definition: rpl_utility.h:474
Definition: thread_type.h:41
long long int rpl_gno
Type of GNO, the second (numeric) component of GTID.
Definition: rpl_gtid.h:99
void clear_tables_to_lock()
Definition: rpl_rli.cc:1340
struct timespec stats_begin
Definition: rpl_rli.h:912
unsigned long ulong
Definition: my_inttypes.h:48
RLI_current_event_raii(Relay_log_info *rli_arg, Log_event *ev)
Definition: rpl_rli.h:1740
uint checkpoint_group
Definition: rpl_rli.h:849
my_off_t get_event_start_pos()
Definition: rpl_rli.h:1239
time_t sql_delay_end
During a delay, specifies the point in time when the delay ends.
Definition: rpl_rli.h:1435
void clear_processing_trx()
Clear only the processing_trx monitoring info.
Definition: rpl_gtid_misc.cc:461
ulong mts_coordinator_basic_nap
Definition: rpl_rli.h:840
ulong adapt_to_master_version(Format_description_log_event *fdle)
adaptation for the slave applier to specific master versions.
Definition: rpl_rli.cc:2145
bool curr_group_isolated
Definition: rpl_rli.h:822
void notify_group_master_log_name_update()
The same as notify_group_relay_log_name_update but for group_master_log_name.
Definition: rpl_rli.h:626
unsigned long long int immediate_commit_timestamp
Timestamp when the transaction was committed on the nearest master.
Definition: control_events.h:812
bool curr_group_seen_gtid
Definition: rpl_rli.h:820
virtual bool commit_positions()
The method implements updating a slave info table.
Definition: rpl_rli.cc:2446
bool is_until_satisfied_at_start_slave()
Definition: rpl_rli.h:1542
bool ignore_log_space_limit
Definition: rpl_rli.h:519
time_t row_stmt_start_timestamp
Definition: rpl_rli.h:1471
ulonglong mts_total_wait_worker_avail
Definition: rpl_rli.h:902
bool error_on_rli_init_info
Definition: rpl_rli.h:348
bool deferred_events_collecting
Definition: rpl_rli.h:751
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
Rows_query_log_event * rows_query_ev
Definition: rpl_rli.h:696
bool curr_group_seen_begin
Definition: rpl_rli.h:821
Relay_log_info * rli_slave
Definition: sql_class.h:899
mysql_mutex_t pending_jobs_lock
Definition: rpl_rli.h:798