MySQL  8.0.18
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 "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  Set of possible return values for the member methods related to
170  `PRIVILEGE_CHECKS_USER` management.
171  */
172  enum class enum_priv_checks_status : int {
173  /** Function ended successfully */
174  SUCCESS = 0,
175  /** Value for user is anonymous (''@'...') */
177  /** Value for the username part of the user is larger than 32 characters */
179  /** Value for the hostname part of the user is larger than 255 characters */
181  /** Value for the hostname part of the user has illegal characters */
183  /**
184  Value for the username part of the user is NULL but the value for the
185  hostname is not NULL.
186  */
188  /**
189  Provided user doesn't exists.
190  */
192  /**
193  Provided user doesn't have the necesary privileges to execute the needed
194  operations.
195  */
197  /** Values provided for the internal variables are corrupted. */
199  /**
200  Provided user doesn't have `FILE` privileges during the execution of a
201  `LOAD DATA`event.
202  */
204  };
205 
206  /*
207  The per-channel filter associated with this RLI
208  */
210  /**
211  Flags for the state of the replication.
212  */
214  /** The replication thread is inside a statement */
216 
217  /** Flag counter. Should always be last */
219  };
220 
221  /*
222  The SQL thread owns one Relay_log_info, and each client that has
223  executed a BINLOG statement owns one Relay_log_info. This function
224  returns zero for the Relay_log_info object that belongs to the SQL
225  thread and nonzero for Relay_log_info objects that belong to
226  clients.
227  */
228  inline bool belongs_to_client() {
230  return !info_thd->slave_thread;
231  }
232 /* Instrumentation key for performance schema for mts_temp_table_LOCK */
233 #ifdef HAVE_PSI_INTERFACE
235 #endif
236  /*
237  Lock to protect race condition while transferring temporary table from
238  worker thread to coordinator thread and vice-versa
239  */
241  /*
242  Lock to acquire by methods that concurrently update lwm of committed
243  transactions and the min waited timestamp and its index.
244  */
247  /*
248  If true, events with the same server id should be replicated. This
249  field is set on creation of a relay log info structure by copying
250  the value of ::replicate_same_server_id and can be overridden if
251  necessary. For example of when this is done, check sql_binlog.cc,
252  where the BINLOG statement can be used to execute "raw" events.
253  */
255 
256  /*
257  Protected with internal locks.
258  Must get data_lock when resetting the logs.
259  */
261 
262  /*
263  Identifies when the recovery process is going on.
264  See sql/rpl_slave.h:init_recovery for further details.
265  */
267 
268  /* The following variables are safe to read any time */
269 
270  /*
271  When we restart slave thread we need to have access to the previously
272  created temporary tables. Modified only on init/end and by the SQL
273  thread, read only by SQL thread.
274  */
276 
277  /* parent Master_info structure */
279 
280  /* number of temporary tables open in this channel */
281  std::atomic<int32> atomic_channel_open_temp_tables{0};
282 
283  /** the status of the commit timestamps for the relay log */
284  enum {
285  /*
286  no GTID log event has been processed, so it is not known if this log
287  has commit timestamps
288  */
290  // the immediate master does not support commit timestamps
292  // the immediate master supports commit timestamps
295 
296  /**
297  @return the pointer to the Gtid_monitoring_info.
298  */
300  return gtid_monitoring_info;
301  }
302 
303  /**
304  Stores the details of the transaction which has just started processing.
305 
306  This function is called by the STS applier or MTS worker when applying a
307  Gtid.
308 
309  @param gtid_arg the gtid of the trx
310  @param original_ts_arg the original commit timestamp of the transaction
311  @param immediate_ts_arg the immediate commit timestamp of the transaction
312  @param skipped true if the transaction was gtid skipped
313  */
314  void started_processing(Gtid gtid_arg, ulonglong original_ts_arg,
315  ulonglong immediate_ts_arg, bool skipped = false) {
316  gtid_monitoring_info->start(gtid_arg, original_ts_arg, immediate_ts_arg,
317  skipped);
318  }
319 
320  /**
321  Stores the details of the transaction which has just started processing.
322 
323  This function is called by the MTS coordinator when queuing a Gtid to
324  a worker.
325 
326  @param gtid_log_ev_arg the gtid log event of the trx
327  */
328  void started_processing(Gtid_log_event *gtid_log_ev_arg) {
329  Gtid gtid = {0, 0};
330  if (gtid_log_ev_arg->get_type() == ASSIGNED_GTID) {
331  gtid = {gtid_log_ev_arg->get_sidno(true), gtid_log_ev_arg->get_gno()};
332  }
333  started_processing(gtid, gtid_log_ev_arg->original_commit_timestamp,
334  gtid_log_ev_arg->immediate_commit_timestamp);
335  }
336 
337  /**
338  When the processing of a transaction is completed, that timestamp is
339  recorded, the information is copied to last_processed_trx and the
340  information in processing_trx is cleared.
341 
342  If the transaction was "applied" but GTID-skipped, the copy will not
343  happen and the last_processed_trx will keep its current value.
344  */
346 
347  /**
348  @return True if there is a transaction being currently processed
349  */
352  }
353 
354  /**
355  Clears the processing_trx structure fields. Normally called when there is an
356  error while processing the transaction.
357  */
359 
360  /**
361  Clears the Gtid_monitoring_info fields.
362  */
364 
365  /**
366  When a transaction is retried, the error number and message, and total number
367  of retries are stored. The timestamp for this error is also set here.
368 
369  @param transient_errno_arg Transient error number.
370  @param transient_err_message_arg Transient error message.
371  @param trans_retries_arg Number of times this transaction has been
372  retried so far.
373  */
374  void retried_processing(uint transient_errno_arg,
375  const char *transient_err_message_arg,
376  ulong trans_retries_arg) {
378  transient_errno_arg, transient_err_message_arg, trans_retries_arg);
379  }
380 
381  /*
382  If on init_info() call error_on_rli_init_info is true that means
383  that previous call to init_info() terminated with an error, RESET
384  SLAVE must be executed and the problem fixed manually.
385  */
387 
388  /**
389  Variable is set to true as long as
390  original_commit_timestamp > immediate_commit_timestamp so that the
391  corresponding warning is only logged once.
392  */
394 
395  /**
396  Retrieves the username part of the `PRIVILEGE_CHECKS_USER` option of `CHANGE
397  MASTER TO` statement.
398 
399  @return a string holding the username part of the user or an empty string.
400  */
401  std::string get_privilege_checks_username() const;
402 
403  /**
404  Retrieves the host part of the `PRIVILEGE_CHECKS_USER` option of `CHANGE
405  MASTER TO` statement.
406 
407  @return a string holding the host part of the user or an empty string.
408  */
409  std::string get_privilege_checks_hostname() const;
410 
411  /**
412  Returns whether or not there is no user configured for
413  `PRIVILEGE_CHECKS_USER`.
414 
415  @return true if there is no user configured for `PRIVILEGE_CHECKS_USER` and
416  false otherwise.
417  */
418  bool is_privilege_checks_user_null() const;
419 
420  /**
421  Returns whether or not the internal data regarding `PRIVILEGE_CHECKS_USER`
422  is corrupted. This may happen, for instance, if the user tries to change the
423  Relay_log_info repository manually or after a server crash.
424 
425  @return true if the data is corrupted, false otherwise.
426  */
428 
429  /**
430  Clears the info related to the data initialized from
431  `PRIVILEGE_CHECKS_USER`.
432  */
434 
435  /**
436  Sets the flag that tells whether or not the data regarding the
437  `PRIVILEGE_CHECKS_USER` is corrupted.
438 
439  @param is_corrupted the flag value.
440  */
441  void set_privilege_checks_user_corrupted(bool is_corrupted);
442 
443  /**
444  Initializes data related to `PRIVILEGE_CHECKS_USER`, specifically the user
445  name and the user hostname.
446 
447  @param param_privilege_checks_username the username part of the user.
448  @param param_privilege_checks_hostname the hostname part of the user.
449 
450  @return a status code describing the state of the data initialization.
451  */
453  char const *param_privilege_checks_username,
454  char const *param_privilege_checks_hostname);
455 
456  /**
457  Checks the validity and integrity of the data related to
458  `PRIVILEGE_CHECKS_USER`, specifically the user name and the user
459  hostname. Also checks if the user exists.
460 
461  This method takes no parameters as it checks the values stored in the
462  internal member variables.
463 
464  @return a status code describing the state of the data initialization.
465  */
467 
468  /**
469  Checks the validity and integrity of the data related to
470  `PRIVILEGE_CHECKS_USER`, specifically the user name and the user
471  hostname. Also checks if the user exists.
472 
473  @param param_privilege_checks_username the username part of the user.
474  @param param_privilege_checks_hostname the hostname part of the user.
475 
476  @return a status code describing the state of the data initialization.
477  */
479  char const *param_privilege_checks_username,
480  char const *param_privilege_checks_hostname);
481  /**
482  Checks the existence of user provided as part of the `PRIVILEGE_CHECKS_USER`
483  option.
484 
485  @param param_privilege_checks_username the username part of the user.
486  @param param_privilege_checks_hostname the host part of the user.
487 
488  @return a status code describing the state of the data initialization.
489  */
491  char const *param_privilege_checks_username,
492  char const *param_privilege_checks_hostname);
493 
494  /**
495  Returns a printable representation of the username and hostname currently
496  being used in the applier security context or empty strings other wise.
497 
498  @return an `std::pair` containing the username and the hostname printable
499  representations.
500  */
501  std::pair<const char *, const char *>
503 
504  /**
505  Outputs the error message associated with applier thread user privilege
506  checks error `error_code`.
507 
508  The output stream to which is outputted is decided based on `to_client`
509  which, if set to `true` will output the message to the client session and if
510  `false` will output to the server log.
511 
512  @param level the message urgency level, e.g., `ERROR_LEVEL`,
513  `WARNING_LEVEL`, etc.
514  @param status_code the status code to output the associated error message
515  for.
516  @param to_client a flag indicating if the message should be sent to the
517  client session or to the server log.
518  @param channel_name name of the channel for which the error is being
519  reported.
520  @param user_name username for which the error is being reported.
521  @param host_name hostname for which the error is being reported.
522  */
523  void report_privilege_check_error(enum loglevel level,
524  enum_priv_checks_status status_code,
525  bool to_client,
526  char const *channel_name = nullptr,
527  char const *user_name = nullptr,
528  char const *host_name = nullptr) const;
529 
530  /**
531  Initializes the security context associated with the `PRIVILEGE_CHECKS_USER`
532  user that is to be used by the provided THD object.
533 
534  @return a status code describing the state of the data initialization.
535  */
537  /**
538  Initializes the security context associated with the `PRIVILEGE_CHECKS_USER`
539  user that is to be used by the applier thread.
540 
541  @return a status code describing the state of the data initialization.
542  */
544 
545  /*
546  Let's call a group (of events) :
547  - a transaction
548  or
549  - an autocommiting query + its associated events (INSERT_ID,
550  TIMESTAMP...)
551  We need these rli coordinates :
552  - relay log name and position of the beginning of the group we currently are
553  executing. Needed to know where we have to restart when replication has
554  stopped in the middle of a group (which has been rolled back by the slave).
555  - relay log name and position just after the event we have just
556  executed. This event is part of the current group.
557  Formerly we only had the immediately above coordinates, plus a 'pending'
558  variable, but this dealt wrong with the case of a transaction starting on a
559  relay log and finishing (commiting) on another relay log. Case which can
560  happen when, for example, the relay log gets rotated because of
561  max_binlog_size.
562  */
563  protected:
564  /**
565  Event group means a group of events of a transaction. group_relay_log_name
566  and group_relay_log_pos record the place before where all event groups
567  are applied. When slave starts, it resume to apply events from
568  group_relay_log_pos. They will be initialized to the begin of the first
569  relay log file if it is a new slave(including SLAVE RESET). Then,
570  group_relay_log_pos is advanced after each transaction is applied
571  successfully in single thread slave. For MTS, group_relay_log_pos
572  is updated by mts checkpoint mechanism. group_relay_log_pos and
573  group_relay_log_name are stored into relay_log_info file/table
574  periodically. When server startup, they are loaded from relay log info
575  file/table.
576  */
580  /* The suffix number of relay log name */
584 
585  /* current event's start position in relay log */
587  /*
588  Original log name and position of the group we're currently executing
589  (whose coordinates are group_relay_log_name/pos in the relay log)
590  in the master's binlog. These concern the *group*, because in the master's
591  binlog the log_pos that comes with each event is the position of the
592  beginning of the group.
593 
594  Note: group_master_log_name, group_master_log_pos must only be
595  written from the thread owning the Relay_log_info (SQL thread if
596  !belongs_to_client(); client thread executing BINLOG statement if
597  belongs_to_client()).
598  */
601 
602  private:
604  /*
605  Identifies when this object belongs to the SQL thread and was not
606  created for a client thread or some other purpose including
607  Slave_worker instance initializations. Ends up serving the same
608  purpose as the belongs_to_client method, but its value is set
609  earlier on in the class constructor.
610  */
611  bool rli_fake;
612  /* Flag that ensures the retrieved GTID set is initialized only once. */
614 
615  /**
616  Stores information on the last processed transaction or the transaction
617  that is currently being processed.
618 
619  STS:
620  - timestamps of the currently applying/last applied transaction
621 
622  MTS:
623  - coordinator thread: timestamps of the currently scheduling/last scheduled
624  transaction in a worker's queue
625  - worker thread: timestamps of the currently applying/last applied
626  transaction
627  */
629 
630  /**
631  It will be set to true when receiver truncated relay log for some reason.
632  The truncated data may already be read by applier. So applier need to check
633  it each time the binlog_end_pos is updated.
634  */
635  bool m_relay_log_truncated = false;
636 
637  /**
638  The user name part of the user passed on to `PRIVILEGE_CHECKS_USER`.
639  */
641 
642  /**
643  The host name part of the user passed on to `PRIVILEGE_CHECKS_USER`.
644  */
646 
647  /**
648  Tells whether or not the internal data regarding `PRIVILEGE_CHECKS_USER` is
649  corrupted. This may happen if the user tries to change the Relay_log_info
650  repository by hand.
651  */
653 
654  public:
656 
658 
660 
661  void add_logged_gtid(rpl_sidno sidno, rpl_gno gno) {
663  DBUG_ASSERT(sidno <= get_sid_map()->get_max_sidno());
664  gtid_set->ensure_sidno(sidno);
665  gtid_set->_add_gtid(sidno, gno);
666  }
667 
668  /**
669  Adds a GTID set to received GTID set.
670 
671  @param gtid_set the gtid_set to add
672 
673  @return RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.
674  */
676 
677  const Gtid_set *get_gtid_set() const { return gtid_set; }
678 
679  bool reinit_sql_thread_io_cache(const char *log, bool need_data_lock);
680 
681  /**
682  Check if group_relay_log_name is in index file.
683 
684  @param [out] errmsg An error message is returned if error happens.
685 
686  @retval false It is valid.
687  @retval true It is invalid. In this case, *errmsg is set to point to
688  the error message.
689 */
690  bool is_group_relay_log_name_invalid(const char **errmsg);
691  /**
692  Reset group_relay_log_name and group_relay_log_pos to the start of the
693  first relay log file. The caller must hold data_lock.
694 
695  @param[out] errmsg An error message is set into it if error happens.
696 
697  @retval false Success
698  @retval true Error
699  */
700  bool reset_group_relay_log_pos(const char **errmsg);
701  /*
702  Update the error number, message and timestamp fields. This function is
703  different from va_report() as va_report() also logs the error message in the
704  log apart from updating the error fields.
705  */
706  void fill_coord_err_buf(loglevel level, int err_code,
707  const char *buff_coord) const;
708 
709  /*
710  Flag that the group_master_log_pos is invalid. This may occur
711  (for example) after CHANGE MASTER TO RELAY_LOG_POS. This will
712  be unset after the first event has been executed and the
713  group_master_log_pos is valid again.
714  */
716 
717  /*
718  Handling of the relay_log_space_limit optional constraint.
719  ignore_log_space_limit is used to resolve a deadlock between I/O and SQL
720  threads, the SQL thread sets it to unblock the I/O thread and make it
721  temporarily forget about the constraint.
722  */
725 
726  /*
727  Used by the SQL thread to instructs the IO thread to rotate
728  the logs when the SQL thread needs to purge to release some
729  disk space.
730  */
732 
734 
735  /**
736  Reset the delay.
737  This is used by RESET SLAVE to clear the delay.
738  */
739  void clear_sql_delay() { sql_delay = 0; }
740 
741  /*
742  Needed for problems when slave stops and we want to restart it
743  skipping one or more events in the master log that have caused
744  errors, and have been manually applied by DBA already.
745  */
747  volatile ulong abort_pos_wait; /* Incremented on change master */
750 
751  /*
752  Condition and its parameters from START SLAVE UNTIL clause.
753 
754  UNTIL condition is tested with is_until_satisfied() method that is
755  called by exec_relay_log_event(). is_until_satisfied() caches the result
756  of the comparison of log names because log names don't change very often;
757  this cache is invalidated by parts of code which change log names with
758  notify_*_log_name_updated() methods. (They need to be called only if SQL
759  thread is running).
760  */
761  enum {
770  } until_condition;
771 
772  char cached_charset[6];
773 
774  /*
775  trans_retries varies between 0 to slave_transaction_retries and counts how
776  many times the slave has retried the present transaction; gets reset to 0
777  when the transaction finally succeeds. retried_trans is a cumulative
778  counter: how many times the slave has retried a transaction (any) since
779  slave started.
780  */
782 
783  /*
784  If the end of the hot relay log is made of master's events ignored by the
785  slave I/O thread, these two keep track of the coords (in the master's
786  binlog) of the last of these events seen by the slave I/O thread. If not,
787  ign_master_log_name_end[0] == 0.
788  As they are like a Rotate event read/written from/to the relay log, they
789  are both protected by rli->relay_log.LOCK_binlog_end_pos.
790  */
793 
794  /*
795  Indentifies where the SQL Thread should create temporary files for the
796  LOAD DATA INFILE. This is used for security reasons.
797  */
800 
801  /**
802  Identifies the last time a checkpoint routine has been executed.
803  */
804  struct timespec last_clock;
805 
806  /**
807  Invalidates cached until_log_name and event_relay_log_name comparison
808  result. Should be called after switch to next relay log if
809  there chances that sql_thread is running.
810  */
811  inline void notify_relay_log_change() {
813  dynamic_cast<Until_position *>(until_option)->notify_log_name_change();
814  }
815 
816  /**
817  Receiver thread notifies that it truncated some data from relay log.
818  data_lock will be acquired, so the caller should not hold data_lock.
819  */
821  /**
822  Applier clears the flag after it handled the situation. The caller must
823  hold data_lock.
824  */
826 
827  /**
828  The same as @c notify_group_relay_log_name_update but for
829  @c group_master_log_name.
830  */
833  dynamic_cast<Until_position *>(until_option)->notify_log_name_change();
834  }
835 
836  inline void inc_event_relay_log_pos() {
838  }
839 
840  /**
841  Last executed event group coordinates are updated and optionally
842  forcibly flushed to a repository.
843  @param log_pos a value of the executed position to update to
844  @param need_data_lock whether data_lock should be acquired
845  @param force the value is passed to eventual flush_info()
846  */
847  int inc_group_relay_log_pos(ulonglong log_pos, bool need_data_lock,
848  bool force = false);
849 
850  int wait_for_pos(THD *thd, String *log_name, longlong log_pos,
851  double timeout);
852  /**
853  Wait for a GTID set to be executed.
854 
855  @param thd The thread for status changes and kill status
856  @param gtid A char array with a GTID set
857  @param timeout Number of seconds to wait before timing out
858  @param update_THD_status Shall the method update the THD stage
859 
860  @retval 0 The set is already executed
861  @retval -1 There was a timeout waiting for the set
862  @retval -2 There was an issue while waiting.
863  */
864  int wait_for_gtid_set(THD *thd, const char *gtid, double timeout,
865  bool update_THD_status = true);
866  /**
867  Wait for a GTID set to be executed.
868 
869  @param thd The thread for status changes and kill status
870  @param gtid A String with a GTID set
871  @param timeout Number of seconds to wait before timing out
872  @param update_THD_status Shall the method update the THD stage
873 
874  @retval 0 The set is already executed
875  @retval -1 There was a timeout waiting for the set
876  @retval -2 There was an issue while waiting.
877  */
878  int wait_for_gtid_set(THD *thd, String *gtid, double timeout,
879  bool update_THD_status = true);
880  /**
881  Wait for a GTID set to be executed.
882 
883  @param thd The thread for status changes and kill status
884  @param wait_gtid_set A GTID_set object
885  @param timeout Number of seconds to wait before timing out
886  @param update_THD_status Shall the method update the THD stage
887 
888  @retval 0 The set is already executed
889  @retval -1 There was a timeout waiting for the set
890  @retval -2 There was an issue while waiting.
891  */
892  int wait_for_gtid_set(THD *thd, const Gtid_set *wait_gtid_set, double timeout,
893  bool update_THD_status = true);
894 
895  void close_temporary_tables();
896 
897  RPL_TABLE_LIST *tables_to_lock; /* RBR: Tables to lock */
898  uint tables_to_lock_count; /* RBR: Count of tables to lock */
899  table_mapping m_table_map; /* RBR: Mapping table-id to table */
900  /* RBR: Record Rows_query log event */
902 
903  bool get_table_data(TABLE *table_arg, table_def **tabledef_var,
904  TABLE **conv_table_var) const {
905  DBUG_ASSERT(tabledef_var && conv_table_var);
906  for (TABLE_LIST *ptr = tables_to_lock; ptr != nullptr;
907  ptr = ptr->next_global)
908  if (ptr->table == table_arg) {
909  *tabledef_var = &static_cast<RPL_TABLE_LIST *>(ptr)->m_tabledef;
910  *conv_table_var = static_cast<RPL_TABLE_LIST *>(ptr)->m_conv_table;
911  DBUG_PRINT("debug", ("Fetching table data for table %s.%s:"
912  " tabledef: %p, conv_table: %p",
913  table_arg->s->db.str, table_arg->s->table_name.str,
914  *tabledef_var, *conv_table_var));
915  return true;
916  }
917  return false;
918  }
919 
920  /**
921  Last charset (6 bytes) seen by slave SQL thread is cached here; it helps
922  the thread save 3 @c get_charset() per @c Query_log_event if the charset is
923  not changing from event to event (common situation). When the 6 bytes are
924  equal to 0 is used to mean "cache is invalidated".
925  */
927  bool cached_charset_compare(char *charset) const;
928 
929  void cleanup_context(THD *, bool);
931  void clear_tables_to_lock();
932  int purge_relay_logs(THD *thd, const char **errmsg, bool delete_only = false);
933 
934  /*
935  Used to defer stopping the SQL thread to give it a chance
936  to finish up the current group of events.
937  The timestamp is set and reset in @c sql_slave_killed().
938  */
940 
941  /* The original master commit timestamp in microseconds since epoch */
943 
944  /*
945  A container to hold on Intvar-, Rand-, Uservar- log-events in case
946  the slave is configured with table filtering rules.
947  The withhold events are executed when their parent Query destiny is
948  determined for execution as well.
949  */
951 
952  /*
953  State of the container: true stands for IRU events gathering,
954  false does for execution, either deferred or direct.
955  */
957 
958  /*****************************************************************************
959  WL#5569 MTS
960 
961  legends:
962  C - Coordinator;
963  W - Worker;
964  WQ - Worker Queue containing event assignments
965  */
966  // number's is determined by global slave_parallel_workers
968 
969  // To map a database to a worker
970  malloc_unordered_map<std::string,
973  bool inited_hash_workers; // flag to check if mapping_db_to_worker is inited
974 
975  mysql_mutex_t slave_worker_hash_lock; // for mapping_db_to_worker
976  mysql_cond_t slave_worker_hash_cond; // for mapping_db_to_worker
977 
978  /*
979  For the purpose of reporting the worker status in performance schema table,
980  we need to preserve the workers array after worker thread was killed. So, we
981  copy this array into the below vector which is used for reporting
982  until next init_workers(). Note that we only copy those attributes that
983  would be useful in reporting worker status. We only use a few attributes in
984  this object as of now but still save the whole object. The idea is
985  to be future proof. We will extend performance schema tables in future
986  and then we would use a good number of attributes from this object.
987  */
988 
989  std::vector<Slave_worker *> workers_copy_pfs;
990 
991  /*
992  This flag is turned ON when the workers array is initialized.
993  Before destroying the workers array we check this flag to make sure
994  we are not destroying an unitilized array. For the purpose of reporting the
995  worker status in performance schema table, we need to preserve the workers
996  array after worker thread was killed. So, we copy this array into
997  workers_copy_pfs array which is used for reporting until next
998  init_workers().
999  */
1001 
1005  mysql_mutex_t exit_count_lock; // mutex of worker exit count
1007  ulonglong mts_pending_jobs_size; // actual mem usage by WQ:s
1008  ulonglong mts_pending_jobs_size_max; // max of WQ:s size forcing C to wait
1009  bool mts_wq_oversize; // C raises flag to wait some memory's released
1010  Slave_worker
1011  *last_assigned_worker; // is set to a Worker at assigning a group
1012  /*
1013  master-binlog ordered queue of Slave_job_group descriptors of groups
1014  that are under processing. The queue size is @c checkpoint_group.
1015  */
1017  /*
1018  Container for references of involved partitions for the current event group
1019  */
1020  // CGAP dynarray holds id:s of partitions of the Current being executed Group
1022  // deferred array to hold partition-info-free events
1024 
1025  bool curr_group_seen_gtid; // current group started with Gtid-event or not
1026  bool curr_group_seen_begin; // current group started with B-event or not
1027  bool curr_group_isolated; // current group requires execution in isolation
1028  bool mts_end_group_sets_max_dbs; // flag indicates if partitioning info is
1029  // discovered
1030  volatile ulong
1031  mts_wq_underrun_w_id; // Id of a Worker whose queue is getting empty
1032  /*
1033  Ongoing excessive overrun counter to correspond to number of events that
1034  are being scheduled while a WQ is close to be filled up.
1035  `Close' is defined as (100 - mts_worker_underrun_level) %.
1036  The counter is incremented each time a WQ get filled over that level
1037  and decremented when the level drops below.
1038  The counter therefore describes level of saturation that Workers
1039  are experiencing and is used as a parameter to compute a nap time for
1040  Coordinator in order to avoid reaching WQ limits.
1041  */
1042  volatile long mts_wq_excess_cnt;
1043  long mts_worker_underrun_level; // % of WQ size at which W is considered
1044  // hungry
1045  ulong mts_coordinator_basic_nap; // C sleeps to avoid WQs overrun
1046  ulong opt_slave_parallel_workers; // cache for ::opt_slave_parallel_workers
1047  ulong slave_parallel_workers; // the one slave session time number of workers
1048  ulong
1049  exit_counter; // Number of workers contributed to max updated group index
1051  ulong recovery_parallel_workers; // number of workers while recovering
1052  uint rli_checkpoint_seqno; // counter of groups executed after the most
1053  // recent CP
1054  uint checkpoint_group; // cache for ::opt_mts_checkpoint_group
1055  MY_BITMAP recovery_groups; // bitmap used during recovery
1057  ulong mts_recovery_group_cnt; // number of groups to execute at recovery
1058  ulong mts_recovery_index; // running index of recoverable groups
1060 
1061  /*
1062  While distibuting events basing on their properties MTS
1063  Coordinator changes its mts group status.
1064  Transition normally flowws to follow `=>' arrows on the diagram:
1065 
1066  +----------------------------+
1067  V |
1068  MTS_NOT_IN_GROUP => |
1069  {MTS_IN_GROUP => MTS_END_GROUP --+} while (!killed) => MTS_KILLED_GROUP
1070 
1071  MTS_END_GROUP has `->' loop breaking link to MTS_NOT_IN_GROUP when
1072  Coordinator synchronizes with Workers by demanding them to
1073  complete their assignments.
1074  */
1075  enum {
1076  /*
1077  no new events were scheduled after last synchronization,
1078  includes Single-Threaded-Slave case.
1079  */
1081 
1082  MTS_IN_GROUP, /* at least one not-terminal event scheduled to a Worker */
1083  MTS_END_GROUP, /* the last scheduled event is a terminal event */
1084  MTS_KILLED_GROUP /* Coordinator gave up to reach MTS_END_GROUP */
1085  } mts_group_status;
1086 
1087  /*
1088  MTS statistics:
1089  */
1090  ulonglong mts_events_assigned; // number of events (statements) scheduled
1091  ulonglong mts_groups_assigned; // number of groups (transactions) scheduled
1092  volatile ulong
1093  mts_wq_overrun_cnt; // counter of all mts_wq_excess_cnt increments
1094  ulong wq_size_waits_cnt; // number of times C slept due to WQ:s oversize
1095  /*
1096  Counter of how many times Coordinator saw Workers are filled up
1097  "enough" with assignements. The enough definition depends on
1098  the scheduler type.
1099  */
1101  std::atomic<longlong>
1102  mts_total_wait_overlap; // Waiting time corresponding to above
1103  /*
1104  Stats to compute Coordinator waiting time for any Worker available,
1105  applies solely to the Commit-clock scheduler.
1106  */
1108  ulong mts_wq_overfill_cnt; // counter of C waited due to a WQ queue was full
1109  /*
1110  Statistics (todo: replace with WL5631) applies to either Coordinator and
1111  Worker. The exec time in the Coordinator case means scheduling. The read
1112  time in the Worker case means getting an event out of Worker queue
1113  */
1116  struct timespec ts_exec[2]; // per event pre- and post- exec timestamp
1117  struct timespec stats_begin; // applier's bootstrap time
1118 
1119  /*
1120  A sorted array of the Workers' current assignement numbers to provide
1121  approximate view on Workers loading.
1122  The first row of the least occupied Worker is queried at assigning
1123  a new partition. Is updated at checkpoint commit to the main RLI.
1124  */
1127  /* end of MTS statistics */
1128 
1129  /**
1130  Storage for holding newly computed values for the last executed
1131  event group coordinates while the current group of events is
1132  being committed, see @c pre_commit, post_commit.
1133  */
1138 
1139  /* Returns the number of elements in workers array/vector. */
1140  inline size_t get_worker_count() {
1142  return workers.size();
1143  else
1144  return workers_copy_pfs.size();
1145  }
1146 
1147  /*
1148  Returns a pointer to the worker instance at index n in workers
1149  array/vector.
1150  */
1153  if (n >= workers.size()) return nullptr;
1154 
1155  return workers[n];
1156  } else if (workers_copy_pfs.size()) {
1157  if (n >= workers_copy_pfs.size()) return nullptr;
1158 
1159  return workers_copy_pfs[n];
1160  } else
1161  return nullptr;
1162  }
1163 
1164  /**
1165  The method implements updating a slave info table. It's
1166  specialized differently for STS and MTS.
1167  */
1168  virtual bool commit_positions();
1169 
1170  /*Channel defined mts submode*/
1172  /* MTS submode */
1174 
1175  /* most of allocation in the coordinator rli is there */
1176  void init_workers(ulong);
1177 
1178  /* counterpart of the init */
1179  void deinit_workers();
1180 
1181  /**
1182  returns true if there is any gap-group of events to execute
1183  at slave starting phase.
1184  */
1185  inline bool is_mts_recovery() const { return mts_recovery_group_cnt != 0; }
1186 
1188  if (recovery_groups_inited) {
1191  recovery_groups_inited = false;
1192  }
1193  }
1194 
1195  /**
1196  returns true if events are to be executed in parallel
1197  */
1198  inline bool is_parallel_exec() const {
1199  bool ret = (slave_parallel_workers > 0) && !is_mts_recovery();
1200 
1201  DBUG_ASSERT(!ret || !workers.empty());
1202 
1203  return ret;
1204  }
1205 
1206  /**
1207  returns true if Coordinator is scheduling events belonging to
1208  the same group and has not reached yet its terminal event.
1209  */
1210  inline bool is_mts_in_group() {
1212  }
1213 
1214  /**
1215  Check if it is time to compute MTS checkpoint.
1216 
1217  @retval true It is time to compute MTS checkpoint.
1218  @retval false It is not MTS or it is not time for computing checkpoint.
1219  */
1221  /**
1222  While a group is executed by a Worker the relay log can change.
1223  Coordinator notifies Workers about this event. Worker is supposed
1224  to commit to the recovery table with the new info.
1225  */
1227 
1228  /**
1229  While a group is executed by a Worker the relay log can change.
1230  Coordinator notifies Workers about this event. Coordinator and Workers
1231  maintain a bitmap of executed group that is reset with a new checkpoint.
1232  */
1233  void reset_notified_checkpoint(ulong count, time_t new_ts,
1234  bool update_timestamp = false);
1235 
1236  /**
1237  Called when gaps execution is ended so it is crash-safe
1238  to reset the last session Workers info.
1239  */
1240  bool mts_finalize_recovery();
1241  /*
1242  * End of MTS section ******************************************************/
1243 
1244  /* The general cleanup that slave applier may need at the end of query. */
1245  inline void cleanup_after_query() {
1247  }
1248  /* The general cleanup that slave applier may need at the end of session. */
1250  if (deferred_events) delete deferred_events;
1251  }
1252 
1253  /**
1254  Helper function to do after statement completion.
1255 
1256  This function is called from an event to complete the group by
1257  either stepping the group position, if the "statement" is not
1258  inside a transaction; or increase the event position, if the
1259  "statement" is inside a transaction.
1260 
1261  @param event_log_pos
1262  Master log position of the event. The position is recorded in the
1263  relay log info and used to produce information for <code>SHOW
1264  SLAVE STATUS</code>.
1265  */
1266  int stmt_done(my_off_t event_log_pos);
1267 
1268  /**
1269  Set the value of a replication state flag.
1270 
1271  @param flag Flag to set
1272  */
1273  void set_flag(enum_state_flag flag) { m_flags |= (1UL << flag); }
1274 
1275  /**
1276  Get the value of a replication state flag.
1277 
1278  @param flag Flag to get value of
1279 
1280  @return @c true if the flag was set, @c false otherwise.
1281  */
1282  bool get_flag(enum_state_flag flag) { return m_flags & (1UL << flag); }
1283 
1284  /**
1285  Clear the value of a replication state flag.
1286 
1287  @param flag Flag to clear
1288  */
1289  void clear_flag(enum_state_flag flag) { m_flags &= ~(1UL << flag); }
1290 
1291  private:
1292  /**
1293  Auxiliary function used by is_in_group.
1294 
1295  The execute thread is in the middle of a statement in the
1296  following cases:
1297  - User_var/Intvar/Rand events have been processed, but the
1298  corresponding Query_log_event has not been processed.
1299  - Table_map or Row events have been processed, and the last Row
1300  event did not have the STMT_END_F set.
1301 
1302  @retval true Replication thread is inside a statement.
1303  @retval false Replication thread is not inside a statement.
1304  */
1305  bool is_in_stmt() const {
1306  bool ret = (m_flags & (1UL << IN_STMT));
1307  DBUG_PRINT("info", ("is_in_stmt()=%d", ret));
1308  return ret;
1309  }
1310  /**
1311  Auxiliary function used by is_in_group.
1312 
1313  @retval true The execute thread is inside a statement or a
1314  transaction, i.e., either a BEGIN has been executed or we are in
1315  the middle of a statement.
1316  @retval false The execute thread thread is not inside a statement
1317  or a transaction.
1318  */
1319  bool is_in_trx_or_stmt() const {
1320  bool ret = is_in_stmt() || (info_thd->variables.option_bits & OPTION_BEGIN);
1321  DBUG_PRINT("info", ("is_in_trx_or_stmt()=%d", ret));
1322  return ret;
1323  }
1324 
1325  public:
1326  /**
1327  A group is defined as the entire range of events that constitute
1328  a transaction or auto-committed statement. It has one of the
1329  following forms:
1330 
1331  (Gtid)? Query(BEGIN) ... (Query(COMMIT) | Query(ROLLBACK) | Xid)
1332  (Gtid)? (Rand | User_var | Int_var)* Query(DDL)
1333 
1334  Thus, to check if the execute thread is in a group, there are
1335  two cases:
1336 
1337  - If the master generates Gtid events (5.7.5 or later, or 5.6 or
1338  later with GTID_MODE=ON), then is_in_group is the same as
1339  info_thd->owned_gtid.sidno != 0, since owned_gtid.sidno is set
1340  to non-zero by the Gtid_log_event and cleared to zero at commit
1341  or rollback.
1342 
1343  - If the master does not generate Gtid events (i.e., master is
1344  pre-5.6, or pre-5.7.5 with GTID_MODE=OFF), then is_in_group is
1345  the same as is_in_trx_or_stmt().
1346 
1347  @retval true Replication thread is inside a group.
1348  @retval false Replication thread is not inside a group.
1349  */
1350  bool is_in_group() const {
1351  bool ret = is_in_trx_or_stmt() || info_thd->owned_gtid.sidno != 0;
1352  DBUG_PRINT("info", ("is_in_group()=%d", ret));
1353  return ret;
1354  }
1355 
1356  int count_relay_log_space();
1357 
1358  /**
1359  Initialize the relay log info. This function does a set of operations
1360  on the rli object like initializing variables, loading information from
1361  repository, setting up name for relay log files and index, MTS recovery
1362  (if necessary), calculating the received GTID set for the channel and
1363  storing the updated rli object configuration into the repository.
1364 
1365  When this function is called in a change master process and the change
1366  master procedure will purge all the relay log files later, there is no
1367  reason to try to calculate the received GTID set of the channel based on
1368  existing relay log files (they will be purged). Allowing reads to existing
1369  relay log files at this point may lead to put the server in a state where
1370  it will be no possible to configure it if it was reset when encryption of
1371  replication log files was ON and the keyring plugin is not available
1372  anymore.
1373 
1374  @param skip_received_gtid_set_recovery When true, skips the received GTID
1375  set recovery.
1376 
1377  @retval 0 Success.
1378  @retval 1 Error.
1379  */
1380  int rli_init_info(bool skip_received_gtid_set_recovery = false);
1381  void end_info();
1382  int flush_info(bool force = false);
1383  int flush_current_log();
1385 
1388  }
1390  future_event_relay_log_pos = log_pos;
1391  }
1392 
1393  inline const char *get_group_master_log_name() {
1394  return group_master_log_name;
1395  }
1397  inline void set_group_master_log_name(const char *log_file_name) {
1398  strmake(group_master_log_name, log_file_name,
1399  sizeof(group_master_log_name) - 1);
1400  }
1401  inline void set_group_master_log_pos(ulonglong log_pos) {
1402  group_master_log_pos = log_pos;
1403  }
1404 
1405  inline const char *get_group_relay_log_name() { return group_relay_log_name; }
1407  inline void set_group_relay_log_name(const char *log_file_name) {
1408  strmake(group_relay_log_name, log_file_name,
1409  sizeof(group_relay_log_name) - 1);
1410  }
1411  inline void set_group_relay_log_name(const char *log_file_name, size_t len) {
1412  strmake(group_relay_log_name, log_file_name, len);
1413  }
1414  inline void set_group_relay_log_pos(ulonglong log_pos) {
1415  group_relay_log_pos = log_pos;
1416  }
1417 
1418  inline const char *get_event_relay_log_name() { return event_relay_log_name; }
1420  inline void set_event_relay_log_name(const char *log_file_name) {
1421  strmake(event_relay_log_name, log_file_name,
1422  sizeof(event_relay_log_name) - 1);
1425  }
1426 
1429  event_relay_log_number = number;
1430  }
1431 
1432  /**
1433  Given the extension number of the relay log, gets the full
1434  relay log path. Currently used in Slave_worker::retry_transaction()
1435 
1436  @param [in] number extension number of relay log
1437  @param[in, out] name The full path of the relay log (per-channel)
1438  to be read by the slave worker.
1439  */
1440  void relay_log_number_to_name(uint number, char name[FN_REFLEN + 1]);
1441  uint relay_log_name_to_number(const char *name);
1442 
1445 
1446  inline void set_event_relay_log_pos(ulonglong log_pos) {
1447  event_relay_log_pos = log_pos;
1448  }
1449  inline const char *get_rpl_log_name() {
1450  return (group_master_log_name[0] ? group_master_log_name : "FIRST");
1451  }
1452 
1453  static size_t get_number_info_rli_fields();
1454 
1455  /**
1456  Sets bits for columns that are allowed to be `NULL`.
1457 
1458  @param nullable_fields the bitmap to hold the nullable fields.
1459  */
1460  static void set_nullable_fields(MY_BITMAP *nullable_fields);
1461 
1462  /**
1463  Indicate that a delay starts.
1464 
1465  This does not actually sleep; it only sets the state of this
1466  Relay_log_info object to delaying so that the correct state can be
1467  reported by SHOW SLAVE STATUS and SHOW PROCESSLIST.
1468 
1469  Requires rli->data_lock.
1470 
1471  @param delay_end The time when the delay shall end.
1472  */
1473  void start_sql_delay(time_t delay_end);
1474 
1475  /* Note that this is cast to uint32 in show_slave_status(). */
1476  time_t get_sql_delay() { return sql_delay; }
1477  void set_sql_delay(time_t _sql_delay) { sql_delay = _sql_delay; }
1478  time_t get_sql_delay_end() { return sql_delay_end; }
1479 
1480  Relay_log_info(bool is_slave_recovery,
1481 #ifdef HAVE_PSI_INTERFACE
1482  PSI_mutex_key *param_key_info_run_lock,
1483  PSI_mutex_key *param_key_info_data_lock,
1484  PSI_mutex_key *param_key_info_sleep_lock,
1485  PSI_mutex_key *param_key_info_thd_lock,
1486  PSI_mutex_key *param_key_info_data_cond,
1487  PSI_mutex_key *param_key_info_start_cond,
1488  PSI_mutex_key *param_key_info_stop_cond,
1489  PSI_mutex_key *param_key_info_sleep_cond,
1490 #endif
1491  uint param_id, const char *param_channel, bool is_rli_fake);
1492  virtual ~Relay_log_info();
1493 
1494  /*
1495  Determines if a warning message on unsafe execution was
1496  already printed out to avoid clutering the error log
1497  with several warning messages.
1498  */
1500 
1501  /*
1502  'sql_thread_kill_accepted is set to true when killed status is recognized.
1503  */
1505 
1507 
1510 
1511  return row_stmt_start_timestamp;
1512  }
1513 
1515 
1517 
1520  }
1521 
1523 
1524  public:
1525  /**
1526  Delete the existing event and set a new one. This class is
1527  responsible for freeing the event, the caller should not do that.
1528 
1529  @return 1 if an error was encountered, 0 otherwise.
1530  */
1532 
1533  /**
1534  Return the current Format_description_log_event.
1535  */
1537  return rli_description_event;
1538  }
1539 
1540  /**
1541  adaptation for the slave applier to specific master versions.
1542  */
1545  ulong current_version);
1546  uchar slave_version_split[3]; // bytes of the slave server version
1547  /*
1548  relay log info repository should be updated on relay log
1549  rotate. But when the transaction is split across two relay logs,
1550  update the repository will cause unexpected results and should
1551  be postponed till the 'commit' of the transaction is executed.
1552 
1553  A flag that set to 'true' when this type of 'forced flush'(at the
1554  time of rotate relay log) is postponed due to transaction split
1555  across the relay logs.
1556  */
1558 
1560 
1562  commit_order_mngr = mngr;
1563  }
1564 
1565  /*
1566  Following set function is required to initialize the 'until_option' during
1567  MTS relay log recovery process.
1568 
1569  Ideally initialization of 'until_option' is done through
1570  rli::init_until_option. This init_until_option requires the main server
1571  thread object and it makes use of the thd->lex->mi object to initialize the
1572  'until_option'.
1573 
1574  But MTS relay log recovery process happens before the main server comes
1575  up at this time the THD object will not be available. Hence the following
1576  set function does the initialization of 'until_option'.
1577  */
1580  until_option = option;
1582  }
1583 
1586  if (until_option) {
1587  delete until_option;
1588  until_option = nullptr;
1589  }
1591  }
1592 
1594 
1595  /**
1596  Get coordinator's RLI. Especially used get the rli from
1597  a slave thread, like this: thd->rli_slave->get_c_rli();
1598  thd could be a SQL thread or a worker thread
1599  */
1600  virtual Relay_log_info *get_c_rli() { return this; }
1601 
1602  virtual const char *get_for_channel_str(bool upper_case = false) const;
1603 
1604  /**
1605  Set replication filter for the channel.
1606  */
1607  inline void set_filter(Rpl_filter *channel_filter) {
1608  rpl_filter = channel_filter;
1609  }
1610 
1611  protected:
1613 
1614  private:
1615  /*
1616  Commit order manager to order commits made by its workers. In context of
1617  Multi Source Replication each worker will be ordered by the coresponding
1618  corrdinator's order manager.
1619  */
1621 
1622  /**
1623  Delay slave SQL thread by this amount of seconds.
1624  The delay is applied per transaction and based on the immediate master's
1625  commit time. Exceptionally, if a server in the replication chain does not
1626  support the commit timestamps in Gtid_log_event, the delay is applied per
1627  event and is based on the event timestamp.
1628  This is set with CHANGE MASTER TO MASTER_DELAY=X.
1629 
1630  Guarded by data_lock. Initialized by the client thread executing
1631  START SLAVE. Written by client threads executing CHANGE MASTER TO
1632  MASTER_DELAY=X. Read by SQL thread and by client threads
1633  executing SHOW SLAVE STATUS. Note: must not be written while the
1634  slave SQL thread is running, since the SQL thread reads it without
1635  a lock when executing flush_info().
1636  */
1637  time_t sql_delay;
1638 
1639  /**
1640  During a delay, specifies the point in time when the delay ends.
1641 
1642  This is used for the SQL_Remaining_Delay column in SHOW SLAVE STATUS.
1643 
1644  Guarded by data_lock. Written by the sql thread. Read by client
1645  threads executing SHOW SLAVE STATUS.
1646  */
1648 
1650 
1651  /*
1652  Before the MASTER_DELAY parameter was added (WL#344), relay_log.info
1653  had 4 lines. Now it has 5 lines.
1654  */
1656 
1657  /*
1658  Before the WL#5599, relay_log.info had 5 lines. Now it has 6 lines.
1659  */
1661 
1662  /*
1663  Before the Id was added (BUG#2334346), relay_log.info
1664  had 6 lines. Now it has 7 lines.
1665  */
1666  static const int LINES_IN_RELAY_LOG_INFO_WITH_ID = 7;
1667 
1668  /*
1669  Add a channel in the slave relay log info
1670  */
1672 
1673  /*
1674  Represents line number in relay_log.info to save PRIVILEGE_CHECKS_USERNAME.
1675  It is username part of PRIVILEGES_CHECKS_USER column in
1676  performance_schema.replication_applier_configuration.
1677  */
1679 
1680  /*
1681  Maximum length of PRIVILEGE_CHECKS_USERNAME.
1682  */
1683  static const int PRIV_CHECKS_USERNAME_LENGTH = 32;
1684 
1685  /*
1686  Represents line number in relay_log.info to save PRIVILEGE_CHECKS_HOSTNAME.
1687  It is hostname part of PRIVILEGES_CHECKS_USER column in
1688  performance_schema.replication_applier_configuration.
1689  */
1691 
1692  /*
1693  Maximum length of PRIVILEGE_CHECKS_USERNAME.
1694  */
1695  static const int PRIV_CHECKS_HOSTNAME_LENGTH = 255;
1696 
1697  /*
1698  Total lines in relay_log.info.
1699  This has to be updated every time a member is added or removed.
1700  */
1703 
1704  bool read_info(Rpl_info_handler *from);
1705  bool write_info(Rpl_info_handler *to);
1706 
1709 
1710  /*
1711  Runtime state for printing a note when slave is taking
1712  too long while processing a row event.
1713  */
1716 
1717  /**
1718  sets the suffix required for relay log names in multisource
1719  replication. When --relay-log option is not provided, the
1720  names of the relay log files are relaylog.0000x or
1721  relaylog-CHANNEL.00000x in the case of MSR. However, if
1722  that option is provided, then the names of the relay log
1723  files are <relay-log-option>.0000x or
1724  <relay-log-option>-CHANNEL.00000x in the case of MSR.
1725 
1726  The function adds a channel suffix (according to the channel to
1727  file name conventions and conversions) to the relay log file.
1728 
1729  @todo: truncate the log file if length exceeds.
1730 
1731  @param[in, out] buff buffer to store the complete relay log file name
1732  @param[in] buff_size size of buffer buff
1733  @param[in] base_name the base name of the relay log file
1734  */
1735  const char *add_channel_to_relay_log_name(char *buff, uint buff_size,
1736  const char *base_name);
1737 
1738  /*
1739  Applier thread InnoDB priority.
1740  When two transactions conflict inside InnoDB, the one with
1741  greater priority wins.
1742  Priority must be set before applier thread start so that all
1743  executed transactions have the same priority.
1744  */
1746 
1747  /* The object stores and handles START SLAVE UNTIL option */
1749 
1750  public:
1751  /*
1752  The boolean is set to true when the binlog (rli_fake) or slave
1753  (rli_slave) applier thread detaches any engine ha_data
1754  it has dealt with at time of XA START processing.
1755  The boolean is reset to false at the end of XA PREPARE,
1756  XA COMMIT ONE PHASE for the binlog applier, and
1757  at internal rollback of the slave applier at the same time with
1758  the engine ha_data re-attachment.
1759  */
1761  /**
1762  Reference to being applied event. The member is set at event reading
1763  and gets reset at the end of the event lifetime.
1764  See more in @c RLI_current_event_raii that provides the main
1765  interface to the member.
1766  */
1768 
1769  /**
1770  Raised when slave applies and writes to its binary log statement
1771  which is not atomic DDL and has no XID assigned. Checked at commit
1772  time to decide whether it is safe to update slave info table
1773  within the same transaction as the write to binary log or this
1774  should be deffered. The deffered scenario applies for not XIDed events
1775  in which case such update might be lost on recovery.
1776  */
1778 
1779  void set_thd_tx_priority(int priority) { thd_tx_priority = priority; }
1780 
1782 
1783  const char *get_until_log_name();
1786  return until_option != nullptr &&
1788  }
1790  return until_option != nullptr &&
1792  }
1794  return until_option != nullptr &&
1796  }
1797  /**
1798  Intialize until option object when starting slave.
1799 
1800  @param[in] thd The thread object of current session.
1801  @param[in] master_param the parameters of START SLAVE.
1802 
1803  @return int
1804  @retval 0 Succeeds to initialize until option object.
1805  @retval <> 0 A defined error number is return if any error happens.
1806  */
1807  int init_until_option(THD *thd, const LEX_MASTER_INFO *master_param);
1808 
1809  /**
1810  Detaches the engine ha_data from THD. The fact
1811  is memorized in @c is_engine_ha_detached flag.
1812 
1813  @param thd a reference to THD
1814  */
1815 
1816  void detach_engine_ha_data(THD *thd);
1817 
1818  /**
1819  Reattaches the engine ha_data to THD. The fact
1820  is memorized in @c is_engine_ha_detached flag.
1821 
1822  @param thd a reference to THD
1823  */
1824 
1825  void reattach_engine_ha_data(THD *thd);
1826  /**
1827  Drops the engine ha_data flag when it is up.
1828  The method is run at execution points of the engine ha_data
1829  re-attachment.
1830 
1831  @return true when THD has detached the engine ha_data,
1832  false otherwise
1833  */
1834 
1836  bool rc = false;
1837 
1839  rc = !(is_engine_ha_data_detached = false); // return the old value
1840 
1841  return rc;
1842  }
1843 
1844  /**
1845  Execute actions at replicated atomic DLL post rollback time.
1846  This include marking the current atomic DDL query-log-event
1847  as having processed.
1848  This measure is necessary to avoid slave info table update execution
1849  when @c pre_commit() hook is called as part of DDL's eventual
1850  implicit commit.
1851  */
1852  void post_rollback() {
1853  static_cast<Query_log_event *>(current_event)->has_ddl_committed = true;
1854  }
1855 
1856  /**
1857  The method implements a pre-commit hook to add up a new statement
1858  typically to a DDL transaction to update the slave info table.
1859  Note, in the non-transactional repository case the slave info
1860  is updated after successful commit of the main transaction.
1861 
1862  @return false as success, otherwise true
1863  */
1864  bool pre_commit() {
1865  bool rc = false;
1866 
1867  if (is_transactional()) {
1868  static_cast<Query_log_event *>(current_event)->has_ddl_committed = true;
1869  rc = commit_positions();
1870  }
1871  return rc;
1872  }
1873  /**
1874  Cleanup of any side effect that pre_commit() inflicts, including
1875  restore of the last executed group coordinates in case the current group
1876  has been destined to rollback, and signaling to possible waiters
1877  in the positive case.
1878 
1879  @param on_rollback when true the method carries out rollback action
1880  */
1881  virtual void post_commit(bool on_rollback);
1882 };
1883 
1884 /**
1885  Negation operator for `enum_priv_checks_status`, to facilitate validation
1886  against `SUCCESS`. To test for error status, use the `!!` idiom.
1887 
1888  @param status the status code to check against `SUCCESS`
1889 
1890  @return true if the status is `SUCCESS` and false otherwise.
1891  */
1893 
1894 bool mysql_show_relaylog_events(THD *thd);
1895 
1896 /**
1897  @param thd a reference to THD
1898  @return true if thd belongs to a Worker thread and false otherwise.
1899 */
1900 inline bool is_mts_worker(const THD *thd) {
1902 }
1903 
1904 /**
1905  Auxiliary function to check if we have a db partitioned MTS
1906  */
1908 
1909 /**
1910  Checks whether the supplied event encodes a (2pc-aware) DDL
1911  that has been already committed.
1912 
1913  @param ev A reference to Query-log-event
1914  @return true when the event is already committed transactional DDL
1915 */
1916 inline bool is_committed_ddl(Log_event *ev) {
1917  return ev->get_type_code() == binary_log::QUERY_EVENT &&
1918  /* has been already committed */
1919  static_cast<Query_log_event *>(ev)->has_ddl_committed;
1920 }
1921 
1922 /**
1923  Checks whether the transaction identified by the argument
1924  is executed by a slave applier thread is an atomic DDL
1925  not yet committed (see @c Query_log_event::has_ddl_committed).
1926  THD::is_operating_substatement_implicitly filters out intermediate
1927  commits done by non-atomic DDLs.
1928  The error-tagged atomic statements are regarded as non-atomic
1929  therefore this predicate returns negative in such case.
1930 
1931  Note that call to is_atomic_ddl() returns "approximate" outcome in
1932  this case as it misses information about type of tables used by the DDL.
1933 
1934  This can be a problem for binlogging slave, as updates to slave info
1935  which happen in the same transaction as write of binary log event
1936  without XID might be lost on recovery. To avoid this problem
1937  RLI::ddl_not_atomic flag is employed which is set to true when
1938  non-atomic DDL without XID is written to the binary log.
1939 
1940  "Approximate" outcome is always fine for non-binlogging slave as in
1941  this case commit happens using one-phase routine for which recovery
1942  is always correct.
1943 
1944  @param thd a pointer to THD describing the transaction context
1945  @return true when a slave applier thread is set to commmit being processed
1946  DDL query-log-event, otherwise returns false.
1947 */
1949  DBUG_ASSERT(thd);
1950 
1951  Relay_log_info *rli = thd->rli_slave;
1952 
1953  /* Early return is about an error in the SQL thread initialization */
1954  if (!rli) return false;
1955 
1956  return ((thd->system_thread == SYSTEM_THREAD_SLAVE_SQL ||
1958  rli->current_event)
1959  ? (rli->is_transactional() &&
1960  /* has not yet committed */
1961  (rli->current_event->get_type_code() ==
1963  !static_cast<Query_log_event *>(rli->current_event)
1964  ->has_ddl_committed) &&
1965  /* unless slave binlogger identified non-atomic */
1966  !rli->ddl_not_atomic &&
1967  /* slave info is not updated when a part of multi-DROP-TABLE
1968  commits */
1970  (is_atomic_ddl(thd, true) &&
1972  /* error-tagged atomic DDL do not update yet slave info */
1973  static_cast<Query_log_event *>(rli->current_event)
1974  ->error_code == 0)
1975  : false;
1976 }
1977 
1978 /**
1979  RAII class to control the slave applier execution context binding
1980  with a being handled event. The main object of control is Query-log-event
1981  containing DDL statement.
1982  The member RLI::current_event is set to refer to an event once it is
1983  read, e.g by next_event() and is reset to NULL at exiting a
1984  read-exec loop. Once the event is destroyed RLI::current_event must be reset
1985  or guaranteed not be accessed anymore.
1986  In the MTS execution the worker is reliably associated with an event
1987  only with the latter is not deferred. This includes Query-log-event.
1988 */
1991 
1992  public:
1994  : m_rli(rli_arg) {
1995  m_rli->current_event = ev;
1996  }
1999 };
2000 
2001 /**
2002  @class MDL_lock_guard
2003 
2004  Utility class to allow RAII pattern with `MDL_request` and `MDL_context`
2005  classes.
2006  */
2008  public:
2009  /**
2010  Constructor that initializes the object and the target `THD` object but
2011  doesn't try to acquire any lock.
2012 
2013  @param target THD object, source for the `MDL_context` to use.
2014  */
2015  MDL_lock_guard(THD *target);
2016  /**
2017  Constructor that initializes the object and the target `THD` object and tries
2018  to acquire the lock identified by `namespace_arg` with MDL type identified by
2019  `mdl_type_arg`.
2020 
2021  If the `blocking` parameter is true, it will instantly try to acquire the
2022  lock and block. If the `blocking` parameter is false, it will first test if
2023  the lock is already acquired and only try to lock if no conflicting lock is
2024  already acquired.
2025 
2026  @param target THD object, source for the `MDL_context` to use.
2027  @param namespace_arg MDL key namespace to acquire the lock from.
2028  @param mdl_type_arg MDL acquisition type
2029  @param blocking whether or not the execution should block if the lock is
2030  already acquired.
2031  */
2032  MDL_lock_guard(THD *target, MDL_key::enum_mdl_namespace namespace_arg,
2033  enum_mdl_type mdl_type_arg, bool blocking = false);
2034  /**
2035  Destructor that unlocks all acquired locks.
2036  */
2037  virtual ~MDL_lock_guard();
2038 
2039  /**
2040  Uses the target `THD` object MDL context to acquire the lock identified by
2041  `namespace_arg` with MDL type identified by `mdl_type_arg`.
2042 
2043  If the `blocking` parameter is true, it will instantly try to acquire the
2044  lock and block. If the `blocking` parameter is false, it will first test if
2045  the lock is already acquired and only try to lock if no conflicting lock is
2046  already acquired.
2047 
2048  The lock is determined to have been acquired if the `THD` object MDL context
2049  hasn't already a lock and the lock is acquired. In other words, if the MDL
2050  context already has acquired the lock, the method will return failure.
2051 
2052  @param namespace_arg MDL key namespace to acquire the lock from.
2053  @param mdl_type_arg MDL acquisition type
2054  @param blocking whether or not the execution should block if the lock is
2055  already acquired.
2056 
2057  @return false if the lock has been acquired by this method invocation and
2058  true if not.
2059  */
2060  bool lock(MDL_key::enum_mdl_namespace namespace_arg,
2061  enum_mdl_type mdl_type_arg, bool blocking = false);
2062  /**
2063  Returns whether or not the lock as been acquired within this object
2064  life-cycle.
2065 
2066  @return true if the lock has been acquired within this object life-cycle.
2067  */
2068  bool is_locked();
2069 
2070  private:
2071  /** The `THD` object holding the MDL context used for acquiring/releasing. */
2073  /** The MDL request holding the MDL ticket issued upon acquisition */
2075 };
2076 
2077 /**
2078  @class Applier_security_context_guard
2079 
2080  Utility class to allow RAII pattern with `Security_context` class.
2081 
2082  At initiliazation, if the `THD` main security context isn't already the
2083  appropriate one, it copies the `Relay_log_info::info_thd::security_context`
2084  and replaces it with the one initialized with the `PRIVILEGE_CHECK_USER` user.
2085  At deinitialization, it copies the backed up security context.
2086 
2087  It also deals with the case where no privilege checks are required, meaning,
2088  `PRIVILEGE_CHECKS_USER` is `NULL`.
2089 
2090  Usage examples:
2091 
2092  (1)
2093  @code
2094  Applier_security_context_guard security_context{rli, thd};
2095  if (!security_context.has_access({SUPER_ACL})) {
2096  return ER_NO_ACCESS;
2097  }
2098  @endcode
2099 
2100  (4)
2101  @code
2102  Applier_security_context_guard security_context{rli, thd};
2103  if (!security_context.has_access(
2104  {{CREATE_ACL | INSERT_ACL | UPDATE_ACL, table},
2105  {SELECT_ACL, table}})) {
2106  return ER_NO_ACCESS;
2107  }
2108  @endcode
2109  */
2110 
2112  public:
2113  /**
2114  If needed, backs up the current `thd` security context and replaces it with
2115  a security context for `PRIVILEGE_CHECKS_USER` user.
2116 
2117  @param rli the `Relay_log_info` object that holds the
2118  `PRIVILEGE_CHECKS_USER` info.
2119  @param thd the `THD` for which initialize the security context.
2120  */
2121  Applier_security_context_guard(Relay_log_info const *rli, THD const *thd);
2122  /**
2123  Destructor that restores the backed up security context, if needed.
2124  */
2126 
2127  //--> Deleted constructors and methods to remove default move/copy semantics
2129  delete;
2132  const Applier_security_context_guard &) = delete;
2134  delete;
2135  //<--
2136 
2137  /**
2138  Returns whether or not privilege checks may be skipped within the current
2139  context.
2140 
2141  @return true if privilege checks may be skipped and false otherwise.
2142  */
2143  bool skip_priv_checks() const;
2144  /**
2145  Checks if the `PRIVILEGE_CHECKS_USER` user has access to the privilieges
2146  passed on by `extra_privileges` parameter as well as to the privileges
2147  passed on at initilization time.
2148 
2149  This particular method checks those privileges agains a given table and
2150  against that table's columns - the ones that are used or changed in the
2151  event.
2152 
2153  @param extra_privileges set of privileges to check, additionally to those
2154  passed on at initialization. It's a list of
2155  (privilege, TABLE*, Rows_log_event*) tuples.
2156 
2157  @return true if the privileges are included in the security context and
2158  false, otherwise.
2159  */
2160  bool has_access(
2161  std::vector<std::tuple<ulong, TABLE const *, Rows_log_event *>>
2162  &extra_privileges) const;
2163  /**
2164  Checks if the `PRIVILEGE_CHECKS_USER` user has access to the privilieges
2165  passed on by `extra_privileges` parameter as well as to the privileges
2166  passed on at initilization time.
2167 
2168  @param extra_privileges set of privileges to check, additionally to those
2169  passed on at initialization. It's a list of
2170  privileges to be checked against any database.
2171 
2172  @return true if the privileges are included in the security context and
2173  false, otherwise.
2174  */
2175  bool has_access(std::initializer_list<std::string> extra_privileges) const;
2176 
2177  /**
2178  Checks if the `PRIVILEGE_CHECKS_USER` user has access to the privilieges
2179  passed on by `extra_privileges` parameter as well as to the privileges
2180  passed on at initilization time.
2181 
2182  @param extra_privileges set of privileges to check, additionally to those
2183  passed on at initialization. It's a list of
2184  privileges to be checked against any database.
2185 
2186  @return true if the privileges are included in the security context and
2187  false, otherwise.
2188  */
2189  bool has_access(std::initializer_list<ulong> extra_privileges) const;
2190 
2191  /**
2192  Returns the username for the user for which the security context was
2193  initialized.
2194 
2195  If `PRIVILEGE_CHECKS_USER` was configured for the target `Relay_log_info`
2196  object, that one is returned.
2197 
2198  Otherwise, the username associated with the `Security_context` initialized
2199  for `Relay_log_info::info_thd` will be returned.
2200 
2201  @return an `std::string` holding the username for the active security
2202  context.
2203  */
2204  std::string get_username() const;
2205  /**
2206  Returns the hostname for the user for which the security context was
2207  initialized.
2208 
2209  If `PRIVILEGE_CHECKS_USER` was configured for the target `Relay_log_info`
2210  object, that one is returned.
2211 
2212  Otherwise, the hostname associated with the `Security_context` initialized
2213  for `Relay_log_info::info_thd` will be returned.
2214 
2215  @return an `std::string` holding the hostname for the active security
2216  context.
2217  */
2218  std::string get_hostname() const;
2219 
2220  private:
2221  /**
2222  The `Relay_log_info` object holding the info required to initialize the
2223  context.
2224  */
2226  /**
2227  The `THD` object for which the security context will be initialized.
2228  */
2229  THD const *m_thd;
2230  /** Applier security context based on `PRIVILEGE_CHECK_USER` user */
2232  /** Currently in use security context */
2234  /** Backed up security context */
2236  /** Flag that states if privilege check should be skipped */
2238  /** Flag that states if there is a logged user */
2240 
2241  void extract_columns_to_check(TABLE const *table, Rows_log_event *event,
2242  std::vector<std::string> &columns) const;
2243 };
2244 
2245 #endif /* RPL_RLI_H */
Format_description_log_event * get_rli_description_event() const
Return the current Format_description_log_event.
Definition: rpl_rli.h:1536
void set_group_relay_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1414
void set_flag(enum_state_flag flag)
Set the value of a replication state flag.
Definition: rpl_rli.h:1273
bool skip_priv_checks() const
Returns whether or not privilege checks may be skipped within the current context.
Definition: rpl_rli.cc:3080
bool is_relay_log_recovery
Definition: rpl_rli.h:266
#define OPTION_BEGIN
Definition: query_options.h:74
unsigned long long int ulonglong
Definition: my_inttypes.h:55
virtual ~MDL_lock_guard()
Destructor that unlocks all acquired locks.
Definition: rpl_rli.cc:3012
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:657
void clear_processing_trx()
Clears the processing_trx structure fields.
Definition: rpl_rli.h:358
Instrumentation helpers for mutexes.
uint event_relay_log_number
Definition: rpl_rli.h:581
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:1411
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:1210
unsigned char uchar
Definition: my_inttypes.h:51
Structure to hold parameters for CHANGE MASTER, START SLAVE, and STOP SLAVE.
Definition: sql_lex.h:306
ulonglong event_relay_log_pos
Definition: rpl_rli.h:582
bool is_relay_log_truncated()
Definition: rpl_rli.h:655
ulonglong log_space_limit
Definition: rpl_rli.h:723
void clear_sql_delay()
Reset the delay.
Definition: rpl_rli.h:739
void clear_privilege_checks_user()
Clears the info related to the data initialized from PRIVILEGE_CHECKS_USER.
Definition: rpl_rli.cc:2681
char ign_master_log_name_end[FN_REFLEN]
Definition: rpl_rli.h:791
std::string get_hostname() const
Returns the hostname for the user for which the security context was initialized. ...
Definition: rpl_rli.cc:3148
void extract_columns_to_check(TABLE const *table, Rows_log_event *event, std::vector< std::string > &columns) const
Definition: rpl_rli.cc:3154
Checkable_rwlock * get_sid_lock()
Definition: rpl_rli.h:659
Definition: rpl_slave_commit_order_manager.h:37
Security_context * m_previous
Backed up security context.
Definition: rpl_rli.h:2235
mysql_cond_t pending_jobs_cond
Definition: rpl_rli.h:1004
enum_mts_parallel_type
Definition: rpl_mts_submode.h:44
Gtid_set * gtid_set
Definition: rpl_rli.h:603
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:328
TABLE_LIST * next_global
Definition: table.h:3106
void clear_flag(enum_state_flag flag)
Clear the value of a replication state flag.
Definition: rpl_rli.h:1289
bool workers_array_initialized
Definition: rpl_rli.h:1000
static const int LINES_IN_RELAY_LOG_INFO_WITH_PRIV_CHECKS_USERNAME
Definition: rpl_rli.h:1678
enum Relay_log_info::@97 until_condition
void clear_mts_recovery_groups()
Definition: rpl_rli.h:1187
ssize_t count
Definition: memcached.c:386
ulonglong mts_groups_assigned
Definition: rpl_rli.h:1091
my_off_t get_until_log_pos()
Definition: rpl_rli.cc:2421
Until_option * until_option
Definition: rpl_rli.h:1748
Definition: rpl_mts_submode.h:52
bool is_transactional() const
Definition: rpl_info.h:110
#define base_name(A)
Definition: my_sys.h:714
void set_commit_order_manager(Commit_order_manager *mngr)
Definition: rpl_rli.h:1561
const string name("\ame\)
std::pair< const char *, const char * > print_applier_security_context_user_host() const
Returns a printable representation of the username and hostname currently being used in the applier s...
Definition: rpl_rli.cc:2801
static const int MAXIMUM_LINES_IN_RELAY_LOG_INFO_FILE
Definition: rpl_rli.h:1701
Relay_log_info const * m_target
The Relay_log_info object holding the info required to initialize the context.
Definition: rpl_rli.h:2225
bool cached_charset_compare(char *charset) const
Definition: rpl_rli.cc:1200
my_off_t new_group_relay_log_pos
Definition: rpl_rli.h:1137
std::vector< T, ut_allocator< T > > vector
Specialization of vector which uses ut_allocator.
Definition: ut0new.h:1281
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:1057
enum enum_thread_type system_thread
Definition: sql_class.h:2119
Definition: rpl_info_handler.h:56
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:345
Include file for Sun RPC to compile out of the box.
void post_rollback()
Execute actions at replicated atomic DLL post rollback time.
Definition: rpl_rli.h:1852
Some integer typedefs for easier portability.
uint relay_log_name_to_number(const char *name)
Definition: rpl_rli.cc:2387
Definition: binlog.h:325
Definition: rpl_rli.h:1084
void deinit_workers()
The method to invoke at slave threads stop.
Definition: rpl_rli.cc:264
time_t set_row_stmt_start_timestamp()
Definition: rpl_rli.h:1508
void set_thd_tx_priority(int priority)
Definition: rpl_rli.h:1779
std::string m_privilege_checks_username
The user name part of the user passed on to PRIVILEGE_CHECKS_USER.
Definition: rpl_rli.h:640
bool replicate_same_server_id
Definition: rpl_rli.h:254
bool long_find_row_note_printed
Definition: rpl_rli.h:1715
bool read_info(Rpl_info_handler *from)
Definition: rpl_rli.cc:1889
ulonglong max_updated_index
Definition: rpl_rli.h:1050
void reattach_engine_ha_data(THD *thd)
Reattaches the engine ha_data to THD.
Definition: rpl_rli.cc:2520
struct timespec ts_exec[2]
Definition: rpl_rli.h:1116
volatile long mts_wq_excess_cnt
Definition: rpl_rli.h:1042
Contains the classes representing events occurring in the replication stream.
ulonglong log_space_total
Definition: rpl_rli.h:723
static const int LINES_IN_RELAY_LOG_INFO_WITH_ID
Definition: rpl_rli.h:1666
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:1257
bool is_group_master_log_pos_invalid
Definition: rpl_rli.h:715
void set_master_info(Master_info *info)
Definition: rpl_rli.cc:1789
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:939
bool belongs_to_client()
Definition: rpl_rli.h:228
struct System_variables variables
Definition: sql_class.h:957
struct slave_job_item Slave_job_item
bool reinit_sql_thread_io_cache(const char *log, bool need_data_lock)
Value for the username part of the user is NULL but the value for the hostname is not NULL...
LEX_CSTRING table_name
Definition: table.h:732
ulonglong mts_pending_jobs_size
Definition: rpl_rli.h:1007
For binlog version 4.
Definition: log_event.h:1458
void set_event_start_pos(my_off_t pos)
Definition: rpl_rli.h:1443
size_t slave_patternload_file_size
Definition: rpl_rli.h:799
char new_group_relay_log_name[FN_REFLEN]
Definition: rpl_rli.h:1136
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3556
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:1210
Provided user doesn&#39;t have FILE privileges during the execution of a LOAD DATAevent.
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
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:53
enum_state_flag
Flags for the state of the replication.
Definition: rpl_rli.h:213
Definition: rpl_rli.h:764
bool m_privilege_checks_user_corrupted
Tells whether or not the internal data regarding PRIVILEGE_CHECKS_USER is corrupted.
Definition: rpl_rli.h:652
void slave_close_thread_tables(THD *)
Definition: rpl_rli.cc:1387
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:1046
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:2035
volatile ulong abort_pos_wait
Definition: rpl_rli.h:747
enum_priv_checks_status initialize_applier_security_context()
Initializes the security context associated with the PRIVILEGE_CHECKS_USER user that is to be used by...
Definition: rpl_rli.cc:2978
ulong wq_size_waits_cnt
Definition: rpl_rli.h:1094
static const int LINES_IN_RELAY_LOG_INFO_WITH_WORKERS
Definition: rpl_rli.h:1660
TODO: Move this structure to libbinlogevents/include/control_events.h when we start using C++11...
Definition: rpl_gtid.h:924
std::string get_privilege_checks_username() const
Retrieves the username part of the PRIVILEGE_CHECKS_USER option of CHANGE MASTER TO statement...
Definition: rpl_rli.cc:2662
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:1193
std::atomic< int32 > atomic_channel_open_temp_tables
Definition: rpl_rli.h:281
bool reported_unsafe_warning
Definition: rpl_rli.h:1499
Prealloced_array< Slave_job_item, 8 > curr_group_da
Definition: rpl_rli.h:1023
Mts_submode * current_mts_submode
Definition: rpl_rli.h:1173
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:491
void clear_gtid_monitoring_info()
Clears the Gtid_monitoring_info fields.
Definition: rpl_rli.h:363
Definition: rpl_info_factory.h:43
~RLI_current_event_raii()
Definition: rpl_rli.h:1998
void set_group_master_log_name(const char *log_file_name)
Definition: rpl_rli.h:1397
char event_relay_log_name[FN_REFLEN]
Definition: rpl_rli.h:579
Definition: rpl_rli.h:291
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:628
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:1671
THD * info_thd
Definition: rpl_info.h:77
Definition: thread_type.h:36
std::string get_username() const
Returns the username for the user for which the security context was initialized. ...
Definition: rpl_rli.cc:3142
Commit_order_manager * commit_order_mngr
Definition: rpl_rli.h:1620
volatile my_off_t group_master_log_pos
Definition: rpl_rli.h:600
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:811
void cleanup_after_session()
Definition: rpl_rli.h:1249
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:661
uchar slave_version_split[3]
Definition: rpl_rli.h:1546
bool sql_force_rotate_relay
Definition: rpl_rli.h:731
Security_context m_applier_security_ctx
Applier security context based on PRIVILEGE_CHECK_USER user.
Definition: rpl_rli.h:2231
enum_priv_checks_status set_privilege_checks_user(char const *param_privilege_checks_username, char const *param_privilege_checks_hostname)
Initializes data related to PRIVILEGE_CHECKS_USER, specifically the user name and the user hostname...
Definition: rpl_rli.cc:2694
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:161
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:1126
Master_info * mi
Definition: rpl_rli.h:278
ulonglong mts_events_assigned
Definition: rpl_rli.h:1090
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:2582
mysql_mutex_t mts_gaq_LOCK
Definition: rpl_rli.h:245
void set_group_relay_log_name(const char *log_file_name)
Definition: rpl_rli.h:1407
Definition: table.h:1301
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:8408
bool is_processing_trx()
Definition: rpl_rli.h:350
Group Assigned Queue whose first element identifies first gap in committed sequence.
Definition: rpl_rli_pdb.h:335
bool is_privilege_checks_user_corrupted() const
Returns whether or not the internal data regarding PRIVILEGE_CHECKS_USER is corrupted.
Definition: rpl_rli.cc:2677
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:1185
Definition: rpl_rli.h:1082
mysql_mutex_t slave_worker_hash_lock
Definition: rpl_rli.h:975
bool slave_thread
Definition: sql_class.h:2312
static void set_nullable_fields(MY_BITMAP *nullable_fields)
Sets bits for columns that are allowed to be NULL.
Definition: rpl_rli.cc:1875
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:374
bool is_locked()
Returns whether or not the lock as been acquired within this object life-cycle.
Definition: rpl_rli.cc:3019
void cleanup_after_query()
Definition: rpl_rli.h:1245
bool is_in_stmt() const
Auxiliary function used by is_in_group.
Definition: rpl_rli.h:1305
bool recovery_groups_inited
Definition: rpl_rli.h:1056
long mts_worker_underrun_level
Definition: rpl_rli.h:1043
ulonglong future_event_relay_log_pos
Definition: rpl_rli.h:583
virtual int set_rli_description_event(Format_description_log_event *fdle)
Delete the existing event and set a new one.
Definition: rpl_rli.cc:2110
void inc_event_relay_log_pos()
Definition: rpl_rli.h:836
Definition: rpl_info.h:42
Value for the hostname part of the user is larger than 255 characters.
uint32 m_flags
Definition: rpl_rli.h:1649
time_t last_master_timestamp
Definition: rpl_rli.h:733
bool mts_recovery_group_seen_begin
Definition: rpl_rli.h:1059
Definition: binlog_event.h:279
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
ulong mts_wq_no_underrun_cnt
Definition: rpl_rli.h:1100
char group_relay_log_name[FN_REFLEN]
Event group means a group of events of a transaction.
Definition: rpl_rli.h:577
Flag counter.
Definition: rpl_rli.h:218
Value for the username part of the user is larger than 32 characters.
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:1864
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
ulong mts_recovery_index
Definition: rpl_rli.h:1058
char group_master_log_name[FN_REFLEN]
Definition: rpl_rli.h:599
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:1842
bool m_logged_in_acl_user
Flag that states if there is a logged user.
Definition: rpl_rli.h:2239
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:750
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:910
time_t get_sql_delay()
Definition: rpl_rli.h:1476
structure to define some default "config_option" option settings
Definition: innodb_config.h:180
bool operator!(Relay_log_info::enum_priv_checks_status status)
Negation operator for enum_priv_checks_status, to facilitate validation against SUCCESS.
Definition: rpl_rli.cc:2658
int rli_init_info(bool skip_received_gtid_set_recovery=false)
Initialize the relay log info.
Definition: rpl_rli.cc:1475
ulong mts_wq_overfill_cnt
Definition: rpl_rli.h:1108
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:781
bool is_mts_worker(const THD *thd)
Definition: rpl_rli.h:1900
char * pos
Definition: do_ctype.cc:76
ulong exit_counter
Definition: rpl_rli.h:1049
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:1793
bool write_info(Rpl_info_handler *to)
Definition: rpl_rli.cc:2043
malloc_unordered_map< std::string, unique_ptr_with_deleter< db_worker_hash_entry > > mapping_db_to_worker
Definition: rpl_rli.h:972
volatile uint32 slave_skip_counter
Definition: rpl_rli.h:746
void start_sql_delay(time_t delay_end)
Indicate that a delay starts.
Definition: rpl_rli.cc:1883
mysql_mutex_t log_space_lock
Definition: rpl_rli.h:748
virtual ~Relay_log_info()
Definition: rpl_rli.cc:266
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:1151
uint64 original_commit_timestamp
Definition: rpl_rli.h:942
time_t sql_delay
Delay slave SQL thread by this amount of seconds.
Definition: rpl_rli.h:1637
virtual ~Applier_security_context_guard()
Destructor that restores the backed up security context, if needed.
Definition: rpl_rli.cc:3072
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:1948
void set_event_relay_log_number(uint number)
Definition: rpl_rli.h:1428
Definition: rpl_rli.h:1080
int count_relay_log_space()
Definition: rpl_rli.cc:470
virtual const char * get_for_channel_str(bool upper_case=false) const
Definition: rpl_rli.cc:2395
RAII class to control the slave applier execution context binding with a being handled event...
Definition: rpl_rli.h:1989
mysql_mutex_t exit_count_lock
Definition: rpl_rli.h:1005
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:505
bool gtid_retrieved_initialized
Definition: rpl_rli.h:613
my_off_t new_group_master_log_pos
Definition: rpl_rli.h:1135
TABLE_SHARE * s
Definition: table.h:1302
int get_thd_tx_priority()
Definition: rpl_rli.h:1781
TABLE * save_temporary_tables
Definition: rpl_rli.h:275
Maps table id&#39;s (integers) to table pointers.
Definition: rpl_tblmap.h:50
Value for the hostname part of the user has illegal characters.
bool unflag_detached_engine_ha_data()
Drops the engine ha_data flag when it is up.
Definition: rpl_rli.h:1835
ulonglong get_future_event_relay_log_pos()
Definition: rpl_rli.h:1386
std::vector< Slave_worker * > workers_copy_pfs
Definition: rpl_rli.h:989
This is the abstract base class for binary log events.
Definition: log_event.h:517
ulong retried_trans
Definition: rpl_rli.h:781
volatile ulong mts_wq_overrun_cnt
Definition: rpl_rli.h:1093
std::string m_privilege_checks_hostname
The host name part of the user passed on to PRIVILEGE_CHECKS_USER.
Definition: rpl_rli.h:645
Definition: rpl_rli.h:769
bool mysql_show_relaylog_events(THD *thd)
Execute a SHOW RELAYLOG EVENTS statement.
Definition: rpl_rli.cc:1430
struct timespec last_clock
Identifies the last time a checkpoint routine has been executed.
Definition: rpl_rli.h:804
Provided user doesn&#39;t have the necesary privileges to execute the needed operations.
Common base class for all row-containing log events.
Definition: log_event.h:2538
Definition: rpl_rli.h:289
Applier_security_context_guard & operator=(const Applier_security_context_guard &)=delete
bool inited_hash_workers
Definition: rpl_rli.h:973
size_t get_worker_count()
Definition: rpl_rli.h:1140
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:12927
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Log_event * data
Definition: rpl_rli.h:88
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:1760
The replication thread is inside a statement.
Definition: rpl_rli.h:215
#define FN_REFLEN
Definition: my_io.h:82
MYSQL_BIN_LOG relay_log
Definition: rpl_rli.h:260
Utility class to allow RAII pattern with Security_context class.
Definition: rpl_rli.h:2111
long long int longlong
Definition: my_inttypes.h:54
mysql_mutex_t data_lock
Definition: rpl_info.h:57
table_mapping m_table_map
Definition: rpl_rli.h:899
mysql_mutex_t mts_temp_table_LOCK
Definition: rpl_rli.h:240
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:535
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:66
Gtid owned_gtid
The GTID of the currently owned transaction.
Definition: sql_class.h:3319
void set_future_event_relay_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1389
Gtid_monitoring_info * get_gtid_monitoring_info()
Definition: rpl_rli.h:299
Slave_worker_array workers
Definition: rpl_rli.h:967
enum_priv_checks_status check_applier_acl_user(char const *param_privilege_checks_username, char const *param_privilege_checks_hostname)
Checks the existence of user provided as part of the PRIVILEGE_CHECKS_USER option.
Definition: rpl_rli.cc:2775
MY_BITMAP recovery_groups
Definition: rpl_rli.h:1055
void set_long_find_row_note_printed()
Definition: rpl_rli.h:1516
bool m_relay_log_truncated
It will be set to true when receiver truncated relay log for some reason.
Definition: rpl_rli.h:635
Prealloced_array< db_worker_hash_entry *, 4 > curr_group_assigned_parts
Definition: rpl_rli.h:1021
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:102
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:2993
void clear()
Clear all monitoring information.
Definition: rpl_gtid_misc.cc:454
uint tables_to_lock_count
Definition: rpl_rli.h:898
A pending metadata lock request.
Definition: mdl.h:782
Value for user is anonymous (&#39;&#39;@&#39;...&#39;)
const char * get_group_relay_log_name()
Definition: rpl_rli.h:1405
Definition: rpl_rli.h:768
Definition: rpl_rli.h:763
bool sql_thread_kill_accepted
Definition: rpl_rli.h:1504
Instrumentation helpers for mutexes.
mysql_cond_t slave_worker_hash_cond
Definition: rpl_rli.h:976
ulong recovery_parallel_workers
Definition: rpl_rli.h:1051
void reset_row_stmt_start_timestamp()
Definition: rpl_rli.h:1514
Common header for many mysys elements.
Commit_order_manager * get_commit_order_manager()
Definition: rpl_rli.h:1559
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:2391
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:1350
int flush_current_log()
Definition: rpl_rli.cc:1780
ulonglong get_group_relay_log_pos()
Definition: rpl_rli.h:1406
void reset_notified_relay_log_change()
While a group is executed by a Worker the relay log can change.
Definition: rpl_rli.cc:326
static const int LINES_IN_RELAY_LOG_INFO_WITH_DELAY
Definition: rpl_rli.h:1655
volatile ulong mts_wq_underrun_w_id
Definition: rpl_rli.h:1031
Represents a set of GTIDs.
Definition: rpl_gtid.h:1302
#define HAVE_PSI_INTERFACE
Definition: my_psi_config.h:38
int n
Definition: xcom_base.c:425
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:903
Binary log event definitions.
THD const * m_thd
The THD object for which the security context will be initialized.
Definition: rpl_rli.h:2229
bool is_until_satisfied_before_dispatching_event(const Log_event *ev)
Definition: rpl_rli.h:1789
static bool update_timestamp(THD *thd, set_var *var)
Definition: sys_vars.cc:4984
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:410
void set_event_relay_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1446
Utility class to allow RAII pattern with MDL_request and MDL_context classes.
Definition: rpl_rli.h:2007
void clear_until_option()
Definition: rpl_rli.h:1584
unsigned long my_off_t
Definition: my_inttypes.h:77
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:1161
Relay_log_info * m_rli
Definition: rpl_rli.h:1990
bool force_flush_postponed_due_to_split_trans
Definition: rpl_rli.h:1557
void set_group_master_log_pos(ulonglong log_pos)
Definition: rpl_rli.h:1401
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:1014
char slave_patternload_file[FN_REFLEN]
Definition: rpl_rli.h:798
std::atomic< longlong > mts_total_wait_overlap
Definition: rpl_rli.h:1102
void detach_engine_ha_data(THD *thd)
Detaches the engine ha_data from THD.
Definition: rpl_rli.cc:2510
Slave_worker * last_assigned_worker
Definition: rpl_rli.h:1011
int init_until_option(THD *thd, const LEX_MASTER_INFO *master_param)
Intialize until option object when starting slave.
Definition: rpl_rli.cc:2430
void set_filter(Rpl_filter *channel_filter)
Set replication filter for the channel.
Definition: rpl_rli.h:1607
mysql_cond_t log_space_cond
Definition: rpl_rli.h:749
Definition: rpl_mi.h:86
PSI_memory_key key_memory_db_worker_hash_entry
Definition: psi_memory_key.cc:111
Definition: rpl_rli.h:766
ulonglong group_relay_log_pos
Definition: rpl_rli.h:578
bool is_time_for_mts_checkpoint()
Check if it is time to compute MTS checkpoint.
Definition: rpl_rli.cc:2648
ulong mts_slave_worker_queue_len_max
Definition: rpl_rli.h:1006
const char * get_group_master_log_name()
Definition: rpl_rli.h:1393
static int flag
Definition: hp_test1.cc:39
ulong slave_parallel_workers
Definition: rpl_rli.h:1047
ulonglong stats_read_time
Definition: rpl_rli.h:1115
bool get_flag(enum_state_flag flag)
Get the value of a replication state flag.
Definition: rpl_rli.h:1282
bool is_operating_substatement_implicitly
Definition: sql_class.h:1941
virtual Relay_log_info * get_c_rli()
Get coordinator&#39;s RLI.
Definition: rpl_rli.h:1600
PSI_mutex_key m_key_mts_temp_table_LOCK
Definition: rpl_rli.h:234
Definition: rpl_rli.h:293
my_off_t event_start_pos
Definition: rpl_rli.h:586
ulonglong stats_exec_time
Definition: rpl_rli.h:1114
uint get_event_relay_log_number()
Definition: rpl_rli.h:1427
const Gtid_set * get_gtid_set() const
Definition: rpl_rli.h:677
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
bool is_engine_ha_data_detached
Definition: rpl_rli.h:1760
THD * m_target
The THD object holding the MDL context used for acquiring/releasing.
Definition: rpl_rli.h:2072
bool mts_wq_oversize
Definition: rpl_rli.h:1009
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:1916
Definition: rpl_rli_pdb.h:515
const char * get_until_log_name()
Definition: rpl_rli.cc:2412
Format_description_log_event * rli_description_event
Definition: rpl_rli.h:1612
enum_return_status add_gtid_set(const Gtid_set *gtid_set)
Adds a GTID set to received GTID set.
Definition: rpl_rli.cc:2402
static size_t get_number_info_rli_fields()
Definition: rpl_rli.cc:1871
Slave_committed_queue * gaq
Definition: rpl_rli.h:1016
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:353
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:2374
Rpl_filter * rpl_filter
Definition: rpl_rli.h:209
ABI for instrumented mutexes.
void report_privilege_check_error(enum loglevel level, enum_priv_checks_status status_code, bool to_client, char const *channel_name=nullptr, char const *user_name=nullptr, char const *host_name=nullptr) const
Outputs the error message associated with applier thread user privilege checks error error_code...
Definition: rpl_rli.cc:2819
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:131
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:1777
Common #defines and includes for file and socket I/O.
bool mts_end_group_sets_max_dbs
Definition: rpl_rli.h:1028
enum_mts_parallel_type channel_mts_submode
Definition: rpl_rli.h:1171
enum Relay_log_info::@98 mts_group_status
void set_sql_delay(time_t _sql_delay)
Definition: rpl_rli.h:1477
Deferred_log_events * deferred_events
Definition: rpl_rli.h:950
enum_priv_checks_status
Set of possible return values for the member methods related to PRIVILEGE_CHECKS_USER management...
Definition: rpl_rli.h:172
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:1518
Relay_log_info & operator=(const Relay_log_info &info)
void close_temporary_tables()
Definition: rpl_rli.cc:982
void set_current_event(Log_event *ev)
Definition: rpl_rli.h:1997
bool rli_fake
Definition: rpl_rli.h:611
bool is_long_find_row_note_printed()
Definition: rpl_rli.h:1522
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:1418
Definition: rpl_rli.h:762
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:571
enum_priv_checks_status check_privilege_checks_user()
Checks the validity and integrity of the data related to PRIVILEGE_CHECKS_USER, specifically the user...
Definition: rpl_rli.cc:2724
static const int LINES_IN_RELAY_LOG_INFO_WITH_PRIV_CHECKS_HOSTNAME
Definition: rpl_rli.h:1690
ulonglong get_event_relay_log_pos()
Definition: rpl_rli.h:1419
time_t get_row_stmt_start_timestamp()
Definition: rpl_rli.h:1506
Prealloced_array< Slave_worker *, 4 > Slave_worker_array
Definition: rpl_rli.h:85
volatile ulong pending_jobs
Definition: rpl_rli.h:1002
enum_mdl_namespace
Object namespaces.
Definition: mdl.h:383
mysql_cond_t logical_clock_cond
Definition: rpl_rli.h:246
static const int PRIV_CHECKS_HOSTNAME_LENGTH
Definition: rpl_rli.h:1695
bool is_commit_in_middle_of_statement
Definition: sql_class.h:3453
#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:3679
MDL_request m_request
The MDL request holding the MDL ticket issued upon acquisition.
Definition: rpl_rli.h:2074
void set_until_option(Until_option *option)
Definition: rpl_rli.h:1578
rpl_gno get_gno() const
Return the GNO for this GTID.
Definition: log_event.h:3713
uint rli_checkpoint_seqno
Definition: rpl_rli.h:1052
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:3677
It is used to record the original query for the rows events in RBR.
Definition: log_event.h:3454
void notify_relay_log_truncated()
Receiver thread notifies that it truncated some data from relay log.
Definition: rpl_rli.cc:2637
char cached_charset[6]
Definition: rpl_rli.h:772
void set_event_relay_log_name(const char *log_file_name)
Definition: rpl_rli.h:1420
Log_event_type get_type_code() const
Definition: log_event.h:774
ulonglong ign_master_log_pos_end
Definition: rpl_rli.h:792
bool is_privilege_checks_user_null() const
Returns whether or not there is no user configured for PRIVILEGE_CHECKS_USER.
Definition: rpl_rli.cc:2670
static STATUS status
Definition: mysql.cc:193
Log_event * current_event
Reference to being applied event.
Definition: rpl_rli.h:1767
int thd_tx_priority
Definition: rpl_rli.h:1745
Security_context * m_current
Currently in use security context.
Definition: rpl_rli.h:2233
Log info(cout, "NOTE")
A table definition from the master.
Definition: rpl_utility.h:245
static const int PRIV_CHECKS_USERNAME_LENGTH
Definition: rpl_rli.h:1683
Definition: table.h:2468
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:2310
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:393
Applier_security_context_guard(Relay_log_info const *rli, THD const *thd)
If needed, backs up the current thd security context and replaces it with a security context for PRIV...
Definition: rpl_rli.cc:3021
bool is_parallel_exec() const
returns true if events are to be executed in parallel
Definition: rpl_rli.h:1198
my_off_t relay_pos
Definition: rpl_rli.h:90
LEX_CSTRING db
Definition: table.h:731
const char * get_rpl_log_name()
Definition: rpl_rli.h:1449
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:314
void set_privilege_checks_user_corrupted(bool is_corrupted)
Sets the flag that tells whether or not the data regarding the PRIVILEGE_CHECKS_USER is corrupted...
Definition: rpl_rli.cc:2688
void init_workers(ulong)
The method to invoke at slave threads start.
Definition: rpl_rli.cc:245
Prealloced_array< ulong, 16 > least_occupied_workers
Definition: rpl_rli.h:1125
void clear_relay_log_truncated()
Applier clears the flag after it handled the situation.
Definition: rpl_rli.cc:2643
enum Relay_log_info::@96 commit_timestamps_status
the status of the commit timestamps for the relay log
ulonglong get_group_master_log_pos()
Definition: rpl_rli.h:1396
ulonglong mts_pending_jobs_size_max
Definition: rpl_rli.h:1008
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:2983
enum_priv_checks_status initialize_security_context(THD *thd)
Initializes the security context associated with the PRIVILEGE_CHECKS_USER user that is to be used by...
Definition: rpl_rli.cc:2942
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:1134
bool is_in_trx_or_stmt() const
Auxiliary function used by is_in_group.
Definition: rpl_rli.h:1319
RPL_TABLE_LIST * tables_to_lock
Definition: rpl_rli.h:897
time_t get_sql_delay_end()
Definition: rpl_rli.h:1478
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:1346
struct timespec stats_begin
Definition: rpl_rli.h:1117
unsigned long ulong
Definition: my_inttypes.h:48
RLI_current_event_raii(Relay_log_info *rli_arg, Log_event *ev)
Definition: rpl_rli.h:1993
uint64_t uint64
Definition: my_inttypes.h:68
uint checkpoint_group
Definition: rpl_rli.h:1054
my_off_t get_event_start_pos()
Definition: rpl_rli.h:1444
time_t sql_delay_end
During a delay, specifies the point in time when the delay ends.
Definition: rpl_rli.h:1647
Values provided for the internal variables are corrupted.
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:1045
ulong adapt_to_master_version(Format_description_log_event *fdle)
adaptation for the slave applier to specific master versions.
Definition: rpl_rli.cc:2230
bool curr_group_isolated
Definition: rpl_rli.h:1027
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:831
bool m_privilege_checks_none
Flag that states if privilege check should be skipped.
Definition: rpl_rli.h:2237
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:1025
std::string get_privilege_checks_hostname() const
Retrieves the host part of the PRIVILEGE_CHECKS_USER option of CHANGE MASTER TO statement.
Definition: rpl_rli.cc:2666
virtual bool commit_positions()
The method implements updating a slave info table.
Definition: rpl_rli.cc:2531
bool is_until_satisfied_at_start_slave()
Definition: rpl_rli.h:1785
bool has_access(std::vector< std::tuple< ulong, TABLE const *, Rows_log_event *>> &extra_privileges) const
Checks if the PRIVILEGE_CHECKS_USER user has access to the privilieges passed on by extra_privileges ...
Definition: rpl_rli.cc:3108
bool ignore_log_space_limit
Definition: rpl_rli.h:724
time_t row_stmt_start_timestamp
Definition: rpl_rli.h:1714
ulonglong mts_total_wait_worker_avail
Definition: rpl_rli.h:1107
bool error_on_rli_init_info
Definition: rpl_rli.h:386
bool deferred_events_collecting
Definition: rpl_rli.h:956
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
Rows_query_log_event * rows_query_ev
Definition: rpl_rli.h:901
bool curr_group_seen_begin
Definition: rpl_rli.h:1026
Relay_log_info * rli_slave
Definition: sql_class.h:900
mysql_mutex_t pending_jobs_lock
Definition: rpl_rli.h:1003
Definition: rpl_rli.h:1083