MySQL  8.0.27
Source Code Documentation
binlog.h
Go to the documentation of this file.
1 #ifndef BINLOG_H_INCLUDED
2 /* Copyright (c) 2010, 2021, Oracle and/or its affiliates.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation. The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 
24 #define BINLOG_H_INCLUDED
25 
26 #include <string.h>
27 #include <sys/types.h>
28 #include <time.h>
29 #include <atomic>
30 #include <utility>
31 
32 #include "libbinlogevents/include/binlog_event.h" // enum_binlog_checksum_alg
33 #include "m_string.h" // llstr
34 #include "my_dbug.h"
35 #include "my_inttypes.h"
36 #include "my_io.h"
37 #include "my_sharedlib.h"
38 #include "my_sys.h"
44 #include "mysql/psi/mysql_cond.h"
45 #include "mysql/psi/mysql_mutex.h"
47 #include "mysql_com.h" // Item_result
49 #include "sql/rpl_trx_tracking.h"
50 #include "sql/tc_log.h" // TC_LOG
51 #include "sql/transaction_info.h" // Transaction_ctx
52 #include "thr_mutex.h"
53 
56 class Gtid_set;
57 class Ha_trx_info;
58 class Incident_log_event;
59 class Log_event;
60 class Master_info;
61 class Relay_log_info;
62 class Rows_log_event;
63 class Sid_map;
64 class THD;
66 class binlog_cache_data;
67 class user_var_entry;
69 
70 struct Gtid;
71 
72 typedef int64 query_id_t;
73 
74 /*
75  Maximum unique log filename extension.
76  Note: setting to 0x7FFFFFFF due to atol windows
77  overflow/truncate.
78  */
79 #define MAX_LOG_UNIQUE_FN_EXT 0x7FFFFFFF
80 
81 /*
82  Maximum allowed unique log filename extension for
83  RESET MASTER TO command - 2 Billion
84  */
85 #define MAX_ALLOWED_FN_EXT_RESET_MASTER 2000000000
86 
89  char *value;
90  ulong length;
94 };
95 
96 /* log info errors */
97 #define LOG_INFO_EOF -1
98 #define LOG_INFO_IO -2
99 #define LOG_INFO_INVALID -3
100 #define LOG_INFO_SEEK -4
101 #define LOG_INFO_MEM -6
102 #define LOG_INFO_FATAL -7
103 #define LOG_INFO_IN_USE -8
104 #define LOG_INFO_EMFILE -9
105 
106 /* bitmap to MYSQL_BIN_LOG::close() */
107 #define LOG_CLOSE_INDEX 1
108 #define LOG_CLOSE_TO_BE_OPENED 2
109 #define LOG_CLOSE_STOP_EVENT 4
110 
111 /*
112  Note that we destroy the lock mutex in the destructor here.
113  This means that object instances cannot be destroyed/go out of scope
114  until we have reset thd->current_linfo to NULL;
115  */
116 struct LOG_INFO {
120  bool fatal; // if the purge happens to give us a negative offset
121  int entry_index; // used in purge_logs(), calculatd in find_log_pos().
124  : index_file_offset(0),
126  pos(0),
127  fatal(false),
128  entry_index(0),
130  memset(log_file_name, 0, FN_REFLEN);
131  }
132 };
133 
134 /*
135  TODO use mmap instead of IO_CACHE for binlog
136  (mmap+fsync is two times faster than write+fsync)
137 */
138 class MYSQL_BIN_LOG : public TC_LOG {
139  public:
140  class Binlog_ofile;
141 
142  private:
144 
145  /* LOCK_log is inited by init_pthread_objects() */
147  char *name;
149  char db[NAME_LEN + 1];
152 
153  /** Instrumentation key to use for file io in @c log_file */
155  /** The instrumentation key to use for @ LOCK_log. */
157  /** The instrumentation key to use for @ LOCK_index. */
159  /** The instrumentation key to use for @ LOCK_binlog_end_pos. */
161  /** The PFS instrumentation key for @ LOCK_commit_queue. */
163  /** The PFS instrumentation key for @ LOCK_done. */
165  /** The PFS instrumentation key for @ LOCK_flush_queue. */
167  /** The PFS instrumentation key for @ LOCK_sync_queue. */
169  /** The PFS instrumentation key for @ COND_done. */
171  /** The PFS instrumentation key for @ COND_flush_queue. */
173  /** The instrumentation key to use for @ LOCK_commit. */
175  /** The instrumentation key to use for @ LOCK_sync. */
177  /** The instrumentation key to use for @ LOCK_xids. */
179  /** The instrumentation key to use for @ update_cond. */
181  /** The instrumentation key to use for @ prep_xids_cond. */
183  /** The instrumentation key to use for opening the log file. */
185  /** The instrumentation key to use for opening the log index file. */
187  /** The instrumentation key to use for opening a log cache file. */
189  /** The instrumentation key to use for opening a log index cache file. */
191 
192  /* POSIX thread objects are inited by init_pthread_objects() */
199 
200  std::atomic<my_off_t> atomic_binlog_end_pos;
204  /*
205  crash_safe_index_file is temp file used for guaranteeing
206  index file crash safe when master server restarts.
207  */
210  /*
211  purge_file is a temp file used in purge_logs so that the index file
212  can be updated before deleting files from disk, yielding better crash
213  recovery. It is created on demand the first time purge_logs is called
214  and then reused for subsequent calls. It is cleaned up in cleanup().
215  */
218  /*
219  The max size before rotation (usable only if log_type == LOG_BIN: binary
220  logs and relay logs).
221  For a binlog, max_size should be max_binlog_size.
222  For a relay log, it should be max_relay_log_size if this is non-zero,
223  max_binlog_size otherwise.
224  max_size is set in init(), and dynamically changed (when one does SET
225  GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
226  fix_max_relay_log_size).
227  */
228  ulong max_size;
229 
230  // current file sequence number for load data infile binary logging
232 
233  /* pointer to the sync period variable, for binlog this will be
234  sync_binlog_period, for relay log this will be
235  sync_relay_log_period
236  */
239 
241  std::atomic<int32> m_atomic_prep_xids{0};
242 
243  /**
244  Increment the prepared XID counter.
245  */
246  void inc_prep_xids(THD *thd);
247 
248  /**
249  Decrement the prepared XID counter.
250 
251  Signal m_prep_xids_cond if the counter reaches zero.
252  */
253  void dec_prep_xids(THD *thd);
254 
256 
257  inline uint get_sync_period() { return *sync_period_ptr; }
258 
259  public:
260  /*
261  This is used to start writing to a new log file. The difference from
262  new_file() is locking. new_file_without_locking() does not acquire
263  LOCK_log.
264  */
266  Format_description_log_event *extra_description_event);
267 
268  private:
269  int new_file_impl(bool need_lock,
270  Format_description_log_event *extra_description_event);
271 
272  bool open(PSI_file_key log_file_key, const char *log_name,
273  const char *new_name, uint32 new_index_number);
274  bool init_and_set_log_file_name(const char *log_name, const char *new_name,
275  uint32 new_index_number);
276  int generate_new_name(char *new_name, const char *log_name,
277  uint32 new_index_number = 0);
278 
279  public:
280  const char *generate_name(const char *log_name, const char *suffix,
281  char *buff);
282  bool is_open() { return atomic_log_state != LOG_CLOSED; }
283 
284  /* This is relay log */
286 
287  uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
288  /*
289  Holds the last seen in Relay-Log FD's checksum alg value.
290  The initial value comes from the slave's local FD that heads
291  the very first Relay-Log file. In the following the value may change
292  with each received master's FD_m.
293  Besides to be used in verification events that IO thread receives
294  (except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd),
295  the value specifies if/how to compute checksum for slave's local events
296  and the first fake Rotate (R_f^1) coming from the master.
297  R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
298 
299  Legends for the checksum related comments:
300 
301  FD - Format-Description event,
302  R - Rotate event
303  R_f - the fake Rotate event
304  E - an arbirary event
305 
306  The underscore indexes for any event
307  `_s' indicates the event is generated by Slave
308  `_m' - by Master
309 
310  Two special underscore indexes of FD:
311  FD_q - Format Description event for queuing (relay-logging)
312  FD_e - Format Description event for executing (relay-logging)
313 
314  Upper indexes:
315  E^n - n:th event is a sequence
316 
317  RL - Relay Log
318  (A) - checksum algorithm descriptor value
319  FD.(A) - the value of (A) in FD
320  */
322 
323  MYSQL_BIN_LOG(uint *sync_period, bool relay_log = false);
324  ~MYSQL_BIN_LOG() override;
325 
327  PSI_mutex_key key_LOCK_index, PSI_mutex_key key_LOCK_commit,
328  PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_done,
329  PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_log,
330  PSI_mutex_key key_LOCK_binlog_end_pos, PSI_mutex_key key_LOCK_sync,
331  PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_xids,
332  PSI_cond_key key_COND_done, PSI_cond_key key_COND_flush_queue,
333  PSI_cond_key key_update_cond, PSI_cond_key key_prep_xids_cond,
334  PSI_file_key key_file_log, PSI_file_key key_file_log_index,
335  PSI_file_key key_file_log_cache, PSI_file_key key_file_log_index_cache) {
336  m_key_COND_done = key_COND_done;
337  m_key_COND_flush_queue = key_COND_flush_queue;
338 
339  m_key_LOCK_commit_queue = key_LOCK_commit_queue;
340  m_key_LOCK_done = key_LOCK_done;
341  m_key_LOCK_flush_queue = key_LOCK_flush_queue;
342  m_key_LOCK_sync_queue = key_LOCK_sync_queue;
343 
344  m_key_LOCK_index = key_LOCK_index;
345  m_key_LOCK_log = key_LOCK_log;
346  m_key_LOCK_binlog_end_pos = key_LOCK_binlog_end_pos;
347  m_key_LOCK_commit = key_LOCK_commit;
348  m_key_LOCK_sync = key_LOCK_sync;
349  m_key_LOCK_xids = key_LOCK_xids;
350  m_key_update_cond = key_update_cond;
351  m_key_prep_xids_cond = key_prep_xids_cond;
352  m_key_file_log = key_file_log;
353  m_key_file_log_index = key_file_log_index;
354  m_key_file_log_cache = key_file_log_cache;
355  m_key_file_log_index_cache = key_file_log_index_cache;
356  }
357 
358  public:
359  /** Manage the MTS dependency tracking */
361 
362  /**
363  Find the oldest binary log referenced by the index file
364 
365  @param[out] binlog_file_name the file name of oldest log found
366  @param[out] errmsg the error message outputted, which is left untouched
367  if the function returns false
368  @return false on success, true on error.
369  */
370  bool find_first_log(std::string &binlog_file_name, std::string &errmsg);
371 
372  /**
373  Find the oldest binary log that contains any GTID that
374  is not in the given gtid set.
375 
376  @param[out] binlog_file_name the file name of oldest binary log found
377  @param[in] gtid_set the given gtid set
378  @param[out] first_gtid the first GTID information from the binary log
379  file returned at binlog_file_name
380  @param[out] errmsg the error message outputted, which is left untouched
381  if the function returns false
382  @return false on success, true on error.
383  */
384  bool find_first_log_not_in_gtid_set(char *binlog_file_name,
385  const Gtid_set *gtid_set,
386  Gtid *first_gtid, std::string &errmsg);
387 
388  /**
389  Reads the set of all GTIDs in the binary/relay log, and the set
390  of all lost GTIDs in the binary log, and stores each set in
391  respective argument.
392 
393  @param gtid_set Will be filled with all GTIDs in this binary/relay
394  log.
395  @param lost_groups Will be filled with all GTIDs in the
396  Previous_gtids_log_event of the first binary log that has a
397  Previous_gtids_log_event. This is requested to binary logs but not
398  to relay logs.
399  @param verify_checksum If true, checksums will be checked.
400  @param need_lock If true, LOCK_log, LOCK_index, and
401  global_sid_lock->wrlock are acquired; otherwise they are asserted
402  to be taken already.
403  @param [out] trx_parser This will be used to return the actual
404  relaylog transaction parser state because of the possibility
405  of partial transactions.
406  @param [out] partial_trx If a transaction was left incomplete
407  on the relaylog, its GTID information should be returned to be
408  used in the case of the rest of the transaction be added to the
409  relaylog.
410  @param is_server_starting True if the server is starting.
411  @return false on success, true on error.
412  */
413  bool init_gtid_sets(Gtid_set *gtid_set, Gtid_set *lost_groups,
414  bool verify_checksum, bool need_lock,
415  Transaction_boundary_parser *trx_parser,
416  Gtid_monitoring_info *partial_trx,
417  bool is_server_starting = false);
418 
419  void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param) {
420  assert(is_relay_log);
421  previous_gtid_set_relaylog = previous_gtid_set_param;
422  }
423  /**
424  If the thread owns a GTID, this function generates an empty
425  transaction and releases ownership of the GTID.
426 
427  - If the binary log is disabled for this thread, the GTID is
428  inserted directly into the mysql.gtid_executed table and the
429  GTID is included in @@global.gtid_executed. (This only happens
430  for DDL, since DML will save the GTID into table and release
431  ownership inside ha_commit_trans.)
432 
433  - If the binary log is enabled for this thread, an empty
434  transaction consisting of GTID, BEGIN, COMMIT is written to the
435  binary log, the GTID is included in @@global.gtid_executed, and
436  the GTID is added to the mysql.gtid_executed table on the next
437  binlog rotation.
438 
439  This function must be called by any committing statement (COMMIT,
440  implicitly committing statements, or Xid_log_event), after the
441  statement has completed execution, regardless of whether the
442  statement updated the database.
443 
444  This logic ensures that an empty transaction is generated for the
445  following cases:
446 
447  - Explicit empty transaction:
448  SET GTID_NEXT = 'UUID:NUMBER'; BEGIN; COMMIT;
449 
450  - Transaction or DDL that gets completely filtered out in the
451  slave thread.
452 
453  @param thd The committing thread
454 
455  @retval 0 Success
456  @retval nonzero Error
457  */
458  int gtid_end_transaction(THD *thd);
459  /**
460  Re-encrypt previous existent binary/relay logs as below.
461  Starting from the next to last entry on the index file, iterating
462  down to the first one:
463  - If the file is encrypted, re-encrypt it. Otherwise, skip it.
464  - If failed to open the file, report an error.
465 
466  @retval False Success
467  @retval True Error
468  */
469  bool reencrypt_logs();
470 
471  private:
472  std::atomic<enum_log_state> atomic_log_state{LOG_CLOSED};
473 
474  /* The previous gtid set in relay log. */
476 
477  int open(const char *opt_name) override { return open_binlog(opt_name); }
478 
479  /**
480  Enter a stage of the ordered commit procedure.
481 
482  Entering is stage is done by:
483 
484  - Atomically entering a queue of THD objects (which is just one for
485  the first phase).
486 
487  - If the queue was empty, the thread is the leader for that stage
488  and it should process the entire queue for that stage.
489 
490  - If the queue was not empty, the thread is a follower and can go
491  waiting for the commit to finish.
492 
493  The function will lock the stage mutex if the calling thread was designated
494  leader for the phase.
495 
496  @param[in] thd Session structure
497  @param[in] stage The stage to enter
498  @param[in] queue Thread queue for the stage
499  @param[in] leave_mutex Mutex that will be released when changing stage
500  @param[in] enter_mutex Mutex that will be taken when changing stage
501 
502  @retval true In case this thread did not become leader, the function
503  returns true *after* the leader has completed the commit
504  on its behalf, so the thread should continue doing the
505  thread-local processing after the commit
506  (i.e. call finish_commit).
507 
508  @retval false The thread is the leader for the stage and should do
509  the processing.
510  */
512  mysql_mutex_t *leave_mutex, mysql_mutex_t *enter_mutex);
513  std::pair<int, my_off_t> flush_thread_caches(THD *thd);
514  int flush_cache_to_file(my_off_t *flush_end_pos);
515  int finish_commit(THD *thd);
516  std::pair<bool, bool> sync_binlog_file(bool force);
518  void process_after_commit_stage_queue(THD *thd, THD *first);
519 
520  /**
521  Set thread variables used while flushing a transaction.
522 
523  @param[in] thd thread whose variables need to be set
524  @param[in] all This is @c true if this is a real transaction commit, and
525  @c false otherwise.
526  @param[in] skip_commit
527  This is @c true if the call to @c ha_commit_low should
528  be skipped (it is handled by the caller somehow) and @c
529  false otherwise (the normal case).
530  */
531  void init_thd_variables(THD *thd, bool all, bool skip_commit);
532 
533  /**
534  Fetch and empty BINLOG_FLUSH_STAGE and COMMIT_ORDER_FLUSH_STAGE flush queues
535  and flush transactions to the disk, and unblock threads executing slave
536  preserve commit order.
537 
538  @param[in] check_and_skip_flush_logs
539  if false then flush prepared records of transactions to the log
540  of storage engine.
541  if true then flush prepared records of transactions to the log
542  of storage engine only if COMMIT_ORDER_FLUSH_STAGE queue is
543  non-empty.
544 
545  @return Pointer to the first session of the BINLOG_FLUSH_STAGE stage queue.
546  */
548  const bool check_and_skip_flush_logs = false);
549 
550  /**
551  Execute the flush stage.
552 
553  @param[out] total_bytes_var Pointer to variable that will be set to total
554  number of bytes flushed, or NULL.
555 
556  @param[out] rotate_var Pointer to variable that will be set to true if
557  binlog rotation should be performed after releasing
558  locks. If rotate is not necessary, the variable will
559  not be touched.
560 
561  @param[out] out_queue_var Pointer to the sessions queue in flush stage.
562 
563  @return Error code on error, zero on success
564  */
565  int process_flush_stage_queue(my_off_t *total_bytes_var, bool *rotate_var,
566  THD **out_queue_var);
567 
568  /**
569  Flush and commit the transaction.
570 
571  This will execute an ordered flush and commit of all outstanding
572  transactions and is the main function for the binary log group
573  commit logic. The function performs the ordered commit in four stages.
574 
575  Pre-condition: transactions should have called ha_prepare_low, using
576  HA_IGNORE_DURABILITY, before entering here.
577 
578  Stage#0 implements replica-preserve-commit-order for applier threads that
579  write the binary log. i.e. it forces threads to enter the queue in the
580  correct commit order.
581 
582  The stage#1 flushes the caches to the binary log and under
583  LOCK_log and marks all threads that were flushed as not pending.
584 
585  The stage#2 syncs the binary log for all transactions in the group.
586 
587  The stage#3 executes under LOCK_commit and commits all transactions in
588  order.
589 
590  There are three queues of THD objects: one for each stage.
591  The Commit_order_manager maintains it own queue and its own order for the
592  commit. So Stage#0 doesn't maintain separate StageID.
593 
594  When a transaction enters a stage, it adds itself to a queue. If the queue
595  was empty so that this becomes the first transaction in the queue, the
596  thread is the *leader* of the queue. Otherwise it is a *follower*. The
597  leader will do all work for all threads in the queue, and the followers
598  will wait until the last stage is finished.
599 
600  Stage 0 (SLAVE COMMIT ORDER):
601  1. If replica-preserve-commit-order and is slave applier worker thread, then
602  waits until its turn to commit i.e. till it is on the top of the queue.
603  2. When it reaches top of the queue, it signals next worker in the commit
604  order queue to awake.
605 
606  Stage 1 (FLUSH):
607  1. Sync the engines (ha_flush_logs), since they prepared using non-durable
608  settings (HA_IGNORE_DURABILITY).
609  2. Generate GTIDs for all transactions in the queue.
610  3. Write the session caches for all transactions in the queue to the binary
611  log.
612  4. Increment the counter of prepared XIDs.
613 
614  Stage 2 (SYNC):
615  1. If it is time to sync, based on the sync_binlog option, sync the binlog.
616  2. If sync_binlog==1, signal dump threads that they can read up to the
617  position after the last transaction in the queue
618 
619  Stage 3 (COMMIT):
620  This is performed by each thread separately, if binlog_order_commits=0.
621  Otherwise by the leader does it for all threads.
622  1. Call the after_sync hook.
623  2. update the max_committed counter in the dependency_tracker
624  3. call ha_commit_low
625  4. Call the after_commit hook
626  5. Update gtids
627  6. Decrement the counter of prepared transactions
628 
629  If the binary log needs to be rotated, it is done after this. During
630  rotation, it takes a lock that prevents new commit groups from executing the
631  flush stage, and waits until the counter of prepared transactions becomes 0,
632  before it creates the new file.
633 
634  @param[in] thd Session to commit transaction for
635  @param[in] all This is @c true if this is a real transaction commit, and
636  @c false otherwise.
637  @param[in] skip_commit
638  This is @c true if the call to @c ha_commit_low should
639  be skipped and @c false otherwise (the normal case).
640  */
641  int ordered_commit(THD *thd, bool all, bool skip_commit = false);
642  void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log,
643  const char *message);
645  class Binlog_event_writer *writer);
647 
648  public:
649  int open_binlog(const char *opt_name);
650  void close() override;
651  enum_result commit(THD *thd, bool all) override;
652  int rollback(THD *thd, bool all) override;
653  bool truncate_relaylog_file(Master_info *mi, my_off_t valid_pos);
654  int prepare(THD *thd, bool all) override;
655 #if defined(MYSQL_SERVER)
656 
657  void update_thd_next_event_pos(THD *thd);
659  bool is_transactional);
660 
661 #endif /* defined(MYSQL_SERVER) */
664  void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock);
665  void set_max_size(ulong max_size_arg);
666  void signal_update() {
667  DBUG_TRACE;
669  return;
670  }
671 
672  void update_binlog_end_pos(bool need_lock = true);
673  void update_binlog_end_pos(const char *file, my_off_t pos);
674 
675  int wait_for_update(const struct timespec *timeout);
676 
677  public:
678  void init_pthread_objects();
679  void cleanup();
680  /**
681  Create a new binary log.
682  @param log_name Name of binlog
683  @param new_name Name of binlog, too. todo: what's the difference
684  between new_name and log_name?
685  @param max_size_arg The size at which this binlog will be rotated.
686  @param null_created_arg If false, and a Format_description_log_event
687  is written, then the Format_description_log_event will have the
688  timestamp 0. Otherwise, it the timestamp will be the time when the
689  event was written to the log.
690  @param need_lock_index If true, LOCK_index is acquired; otherwise
691  LOCK_index must be taken by the caller.
692  @param need_sid_lock If true, the read lock on global_sid_lock
693  will be acquired. Otherwise, the caller must hold the read lock
694  on global_sid_lock.
695  @param extra_description_event The master's FDE to be written by the I/O
696  thread while creating a new relay log file. This should be NULL for
697  binary log files.
698  @param new_index_number The binary log file index number to start from
699  after the RESET MASTER TO command is called.
700  */
701  bool open_binlog(const char *log_name, const char *new_name,
702  ulong max_size_arg, bool null_created_arg,
703  bool need_lock_index, bool need_sid_lock,
704  Format_description_log_event *extra_description_event,
705  uint32 new_index_number = 0);
706  bool open_index_file(const char *index_file_name_arg, const char *log_name,
707  bool need_lock_index);
708  /* Use this to start writing a new log file */
709  int new_file(Format_description_log_event *extra_description_event);
710 
711  bool write_event(Log_event *event_info);
712  bool write_cache(THD *thd, class binlog_cache_data *cache_data,
713  class Binlog_event_writer *writer);
714  /**
715  Assign automatic generated GTIDs for all commit group threads in the flush
716  stage having gtid_next.type == AUTOMATIC_GTID.
717 
718  @param first_seen The first thread seen entering the flush stage.
719  @return Returns false if succeeds, otherwise true is returned.
720  */
721  bool assign_automatic_gtids_to_flush_group(THD *first_seen);
722  bool write_transaction(THD *thd, binlog_cache_data *cache_data,
723  Binlog_event_writer *writer);
724 
725  /**
726  Write a dml into statement cache and then flush it into binlog. It writes
727  Gtid_log_event and BEGIN, COMMIT automatically.
728 
729  It is aimed to handle cases of "background" logging where a statement is
730  logged indirectly, like "TRUNCATE TABLE a_memory_table". So don't use it on
731  any normal statement.
732 
733  @param[in] thd the THD object of current thread.
734  @param[in] stmt the DML statement.
735  @param[in] stmt_len the length of the DML statement.
736  @param[in] sql_command the type of SQL command.
737 
738  @return Returns false if succeeds, otherwise true is returned.
739  */
740  bool write_stmt_directly(THD *thd, const char *stmt, size_t stmt_len,
741  enum enum_sql_command sql_command);
742 
743  void report_cache_write_error(THD *thd, bool is_transactional);
744  bool check_write_error(const THD *thd);
745  bool write_incident(THD *thd, bool need_lock_log, const char *err_msg,
746  bool do_flush_and_sync = true);
747  bool write_incident(Incident_log_event *ev, THD *thd, bool need_lock_log,
748  const char *err_msg, bool do_flush_and_sync = true);
752  void start_union_events(THD *thd, query_id_t query_id_param);
753  void stop_union_events(THD *thd);
754  bool is_query_in_union(THD *thd, query_id_t query_id_param);
755 
756  bool write_buffer(const char *buf, uint len, Master_info *mi);
757  bool write_event(Log_event *ev, Master_info *mi);
758 
759  private:
761 
762  public:
763  void make_log_name(char *buf, const char *log_ident);
764  bool is_active(const char *log_file_name);
765  int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads);
766  int rotate(bool force_rotate, bool *check_purge);
767  void purge();
768  int rotate_and_purge(THD *thd, bool force_rotate);
769 
770  bool flush();
771  /**
772  Flush binlog cache and synchronize to disk.
773 
774  This function flushes events in binlog cache to binary log file,
775  it will do synchronizing according to the setting of system
776  variable 'sync_binlog'. If file is synchronized, @c synced will
777  be set to 1, otherwise 0.
778 
779  @param[in] force if true, ignores the 'sync_binlog' and synchronizes the
780  file.
781 
782  @retval 0 Success
783  @retval other Failure
784  */
785  bool flush_and_sync(const bool force = false);
786  int purge_logs(const char *to_log, bool included, bool need_lock_index,
787  bool need_update_threads, ulonglong *decrease_log_space,
788  bool auto_purge);
789  int purge_logs_before_date(time_t purge_time, bool auto_purge);
790  int set_crash_safe_index_file_name(const char *base_file_name);
793  int add_log_to_index(uchar *log_file_name, size_t name_len,
794  bool need_lock_index);
795  int move_crash_safe_index_file_to_index_file(bool need_lock_index);
796  int set_purge_index_file_name(const char *base_file_name);
797  int open_purge_index_file(bool destroy);
800  int sync_purge_index_file();
801  int register_purge_index_entry(const char *entry);
802  int register_create_index_entry(const char *entry);
803  int purge_index_entry(THD *thd, ulonglong *decrease_log_space,
804  bool need_lock_index);
805  bool reset_logs(THD *thd, bool delete_only = false);
806  void close(uint exiting, bool need_lock_log, bool need_lock_index);
807 
808  // iterating through the log index file
809  int find_log_pos(LOG_INFO *linfo, const char *log_name, bool need_lock_index);
810  int find_next_log(LOG_INFO *linfo, bool need_lock_index);
811  int find_next_relay_log(char log_name[FN_REFLEN + 1]);
812  int get_current_log(LOG_INFO *linfo, bool need_lock_log = true);
813  int raw_get_current_log(LOG_INFO *linfo);
814  uint next_file_id();
815  /**
816  Retrieves the contents of the index file associated with this log object
817  into an `std::list<std::string>` object. The order held by the index file is
818  kept.
819 
820  @param need_lock_index whether or not the lock over the index file should be
821  acquired inside the function.
822 
823  @return a pair: a function status code; a list of `std::string` objects with
824  the content of the log index file.
825  */
826  std::pair<int, std::list<std::string>> get_log_index(
827  bool need_lock_index = true);
828  inline char *get_index_fname() { return index_file_name; }
829  inline char *get_log_fname() { return log_file_name; }
830  const char *get_name() const { return name; }
831  inline mysql_mutex_t *get_log_lock() { return &LOCK_log; }
833  inline mysql_cond_t *get_log_cond() { return &update_cond; }
835 
838  inline IO_CACHE *get_index_file() { return &index_file; }
839 
840  /**
841  Function to report the missing GTIDs.
842 
843  This function logs the missing transactions on master to its error log
844  as a warning. If the missing GTIDs are too long to print in a message,
845  it suggests the steps to extract the missing transactions.
846 
847  This function also informs slave about the GTID set sent by the slave,
848  transactions missing on the master and few suggestions to recover from
849  the error. This message shall be wrapped by
850  ER_MASTER_FATAL_ERROR_READING_BINLOG on slave and will be logged as an
851  error.
852 
853  This function will be called from mysql_binlog_send() function.
854 
855  @param slave_executed_gtid_set GTID set executed by slave
856  @param errmsg Pointer to the error message
857  */
858  void report_missing_purged_gtids(const Gtid_set *slave_executed_gtid_set,
859  std::string &errmsg);
860 
861  /**
862  Function to report the missing GTIDs.
863 
864  This function logs the missing transactions on master to its error log
865  as a warning. If the missing GTIDs are too long to print in a message,
866  it suggests the steps to extract the missing transactions.
867 
868  This function also informs slave about the GTID set sent by the slave,
869  transactions missing on the master and few suggestions to recover from
870  the error. This message shall be wrapped by
871  ER_MASTER_FATAL_ERROR_READING_BINLOG on slave and will be logged as an
872  error.
873 
874  This function will be called from find_first_log_not_in_gtid_set()
875  function.
876 
877  @param previous_gtid_set Previous GTID set found
878  @param slave_executed_gtid_set GTID set executed by slave
879  @param errmsg Pointer to the error message
880  */
881  void report_missing_gtids(const Gtid_set *previous_gtid_set,
882  const Gtid_set *slave_executed_gtid_set,
883  std::string &errmsg);
885  /*
886  It is called by the threads (e.g. dump thread, applier thread) which want
887  to read hot log without LOCK_log protection.
888  */
891  return atomic_binlog_end_pos;
892  }
896 
897  /**
898  Deep copy global_sid_map and gtid_executed.
899  Both operations are done under LOCK_commit and global_sid_lock
900  protection.
901 
902  @param[out] sid_map The Sid_map to which global_sid_map will
903  be copied.
904  @param[out] gtid_set The Gtid_set to which gtid_executed will
905  be copied.
906 
907  @return the operation status
908  @retval 0 OK
909  @retval !=0 Error
910  */
911  int get_gtid_executed(Sid_map *sid_map, Gtid_set *gtid_set);
912 
913  /*
914  True while rotating binlog, which is caused by logging Incident_log_event.
915  */
917 };
918 
923 };
924 
926 
927 /**
928  Check if the the transaction is empty.
929 
930  @param thd The client thread that executed the current statement.
931 
932  @retval true No changes found in any storage engine
933  @retval false Otherwise.
934 
935 **/
936 bool is_transaction_empty(THD *thd);
937 /**
938  Check if the transaction has no rw flag set for any of the storage engines.
939 
940  @param thd The client thread that executed the current statement.
941  @param trx_scope The transaction scope to look into.
942 
943  @retval the number of engines which have actual changes.
944  */
946 
947 /**
948  Check if at least one of transacaction and statement binlog caches contains
949  an empty transaction, other one is empty or contains an empty transaction,
950  which has two binlog events "BEGIN" and "COMMIT".
951 
952  @param thd The client thread that executed the current statement.
953 
954  @retval true At least one of transacaction and statement binlog caches
955  contains an empty transaction, other one is empty or
956  contains an empty transaction.
957  @retval false Otherwise.
958 */
960 bool trans_has_updated_trans_table(const THD *thd);
962 bool ending_trans(THD *thd, const bool all);
963 bool ending_single_stmt_trans(THD *thd, const bool all);
964 bool trans_cannot_safely_rollback(const THD *thd);
965 bool stmt_cannot_safely_rollback(const THD *thd);
966 
968 
969 bool purge_master_logs(THD *thd, const char *to_log);
970 bool purge_master_logs_before_date(THD *thd, time_t purge_time);
972 bool mysql_show_binlog_events(THD *thd);
973 void check_binlog_cache_size(THD *thd);
975 bool binlog_enabled();
976 void register_binlog_handler(THD *thd, bool trx);
977 int query_error_code(const THD *thd, bool not_killed);
978 
979 extern const char *log_bin_index;
980 extern const char *log_bin_basename;
981 extern bool opt_binlog_order_commits;
982 extern ulong rpl_read_size;
983 /**
984  Turns a relative log binary log path into a full path, based on the
985  opt_bin_logname or opt_relay_logname. Also trims the cr-lf at the
986  end of the full_path before return to avoid any server startup
987  problem on windows.
988 
989  @param from The log name we want to make into an absolute path.
990  @param to The buffer where to put the results of the
991  normalization.
992  @param is_relay_log Switch that makes is used inside to choose which
993  option (opt_bin_logname or opt_relay_logname) to
994  use when calculating the base path.
995 
996  @returns true if a problem occurs, false otherwise.
997  */
998 
999 bool normalize_binlog_name(char *to, const char *from, bool is_relay_log);
1000 
1001 #endif /* BINLOG_H_INCLUDED */
int64 query_id_t
Definition: binlog.h:70
MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log
Contains the classes representing events occurring in the replication stream.
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:172
Auxiliary class to copy serialized events to the binary log and correct some of the fields that are n...
Definition: binlog.cc:1234
StageID
Constants for queues for different stages.
Definition: rpl_commit_stage_manager.h:165
For binlog version 4.
Definition: log_event.h:1613
Stores information to monitor a transaction during the different replication stages.
Definition: rpl_gtid.h:1291
Represents a set of GTIDs.
Definition: rpl_gtid.h:1435
Either statement transaction or normal transaction - related thread-specific storage engine data.
Definition: transaction_info.h:406
Class representing an incident, an occurance out of the ordinary, that happened on the master.
Definition: log_event.h:3501
This is the abstract base class for binary log events.
Definition: log_event.h:659
Logical binlog file which wraps and hides the detail of lower layer storage implementation.
Definition: binlog.cc:250
Definition: binlog.h:138
mysql_cond_t m_prep_xids_cond
Definition: binlog.h:240
mysql_mutex_t LOCK_binlog_end_pos
Definition: binlog.h:196
std::atomic< my_off_t > atomic_binlog_end_pos
Definition: binlog.h:200
void unlock_binlog_end_pos()
Definition: binlog.h:895
PSI_mutex_key m_key_LOCK_xids
The instrumentation key to use for @ LOCK_xids.
Definition: binlog.h:178
mysql_mutex_t LOCK_commit
Definition: binlog.h:194
char db[NAME_LEN+1]
Definition: binlog.h:149
void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param)
Definition: binlog.h:419
IO_CACHE crash_safe_index_file
Definition: binlog.h:208
void reset_bytes_written()
Definition: binlog.h:663
void lock_binlog_end_pos()
Definition: binlog.h:894
enum_log_state
Definition: binlog.h:143
@ LOG_OPENED
Definition: binlog.h:143
@ LOG_CLOSED
Definition: binlog.h:143
@ LOG_TO_BE_OPENED
Definition: binlog.h:143
mysql_mutex_t LOCK_index
Definition: binlog.h:193
PSI_mutex_key m_key_COND_done
The PFS instrumentation key for @ COND_done.
Definition: binlog.h:170
mysql_mutex_t LOCK_sync
Definition: binlog.h:195
PSI_mutex_key m_key_LOCK_commit_queue
The PFS instrumentation key for @ LOCK_commit_queue.
Definition: binlog.h:162
bool write_event_to_binlog_and_flush(Log_event *ev)
void set_psi_keys(PSI_mutex_key key_LOCK_index, PSI_mutex_key key_LOCK_commit, PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_done, PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_log, PSI_mutex_key key_LOCK_binlog_end_pos, PSI_mutex_key key_LOCK_sync, PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_xids, PSI_cond_key key_COND_done, PSI_cond_key key_COND_flush_queue, PSI_cond_key key_update_cond, PSI_cond_key key_prep_xids_cond, PSI_file_key key_file_log, PSI_file_key key_file_log_index, PSI_file_key key_file_log_cache, PSI_file_key key_file_log_index_cache)
Definition: binlog.h:326
int open(const char *opt_name) override
Initialize and open the coordinator log.
Definition: binlog.h:477
IO_CACHE purge_index_file
Definition: binlog.h:216
PSI_cond_key m_key_prep_xids_cond
The instrumentation key to use for @ prep_xids_cond.
Definition: binlog.h:182
my_off_t get_binlog_end_pos() const
Definition: binlog.h:889
void lock_index()
Definition: binlog.h:836
PSI_mutex_key m_key_LOCK_flush_queue
The PFS instrumentation key for @ LOCK_flush_queue.
Definition: binlog.h:166
int32 get_prep_xids()
Definition: binlog.h:255
std::atomic< enum_log_state > atomic_log_state
Definition: binlog.h:472
Gtid_set * previous_gtid_set_relaylog
Definition: binlog.h:475
PSI_cond_key m_key_update_cond
The instrumentation key to use for @ update_cond.
Definition: binlog.h:180
const char * get_name() const
Definition: binlog.h:830
bool write_error
Definition: binlog.h:150
uint * sync_period_ptr
Definition: binlog.h:237
PSI_mutex_key m_key_LOCK_done
The PFS instrumentation key for @ LOCK_done.
Definition: binlog.h:164
std::atomic< int32 > m_atomic_prep_xids
Definition: binlog.h:241
Binlog_ofile * m_binlog_file
Definition: binlog.h:151
PSI_mutex_key m_key_LOCK_sync
The instrumentation key to use for @ LOCK_sync.
Definition: binlog.h:176
mysql_mutex_t * get_binlog_end_pos_lock()
Definition: binlog.h:893
void add_bytes_written(ulonglong inc)
Definition: binlog.h:662
bool inited
Definition: binlog.h:150
bool is_open()
Definition: binlog.h:282
PSI_file_key m_key_file_log_index_cache
The instrumentation key to use for opening a log index cache file.
Definition: binlog.h:190
mysql_mutex_t * get_log_lock()
Definition: binlog.h:831
PSI_mutex_key m_key_LOCK_binlog_end_pos
The instrumentation key to use for @ LOCK_binlog_end_pos.
Definition: binlog.h:160
char index_file_name[FN_REFLEN]
Definition: binlog.h:203
IO_CACHE * get_index_file()
Definition: binlog.h:838
mysql_mutex_t LOCK_log
Definition: binlog.h:146
ulong max_size
Definition: binlog.h:228
bool is_relay_log
Definition: binlog.h:285
PSI_mutex_key m_key_LOCK_index
The instrumentation key to use for @ LOCK_index.
Definition: binlog.h:158
uint get_sync_period()
Definition: binlog.h:257
mysql_cond_t * get_log_cond()
Definition: binlog.h:833
PSI_mutex_key m_key_LOCK_log
The instrumentation key to use for @ LOCK_log.
Definition: binlog.h:156
mysql_mutex_t * get_commit_lock()
Definition: binlog.h:832
PSI_mutex_key m_key_COND_flush_queue
The PFS instrumentation key for @ COND_flush_queue.
Definition: binlog.h:172
uint file_id
Definition: binlog.h:231
ulonglong bytes_written
Definition: binlog.h:201
binary_log::enum_binlog_checksum_alg relay_log_checksum_alg
Definition: binlog.h:321
mysql_cond_t update_cond
Definition: binlog.h:198
PSI_mutex_key m_key_LOCK_commit
The instrumentation key to use for @ LOCK_commit.
Definition: binlog.h:174
void unlock_index()
Definition: binlog.h:837
PSI_file_key m_key_file_log
The instrumentation key to use for opening the log file.
Definition: binlog.h:184
PSI_mutex_key m_key_LOCK_sync_queue
The PFS instrumentation key for @ LOCK_sync_queue.
Definition: binlog.h:168
char * get_log_fname()
Definition: binlog.h:829
char purge_index_file_name[FN_REFLEN]
Definition: binlog.h:217
Transaction_dependency_tracker m_dependency_tracker
Manage the MTS dependency tracking.
Definition: binlog.h:360
IO_CACHE index_file
Definition: binlog.h:202
char * get_index_fname()
Definition: binlog.h:828
mysql_mutex_t LOCK_xids
Definition: binlog.h:197
PSI_file_key m_key_file_log_cache
The instrumentation key to use for opening a log cache file.
Definition: binlog.h:188
Binlog_ofile * get_binlog_file()
Definition: binlog.h:834
uint sync_counter
Definition: binlog.h:238
PSI_file_key m_log_file_key
Instrumentation key to use for file io in log_file.
Definition: binlog.h:154
bool is_rotating_caused_by_incident
Definition: binlog.h:916
char * name
Definition: binlog.h:147
char log_file_name[FN_REFLEN]
Definition: binlog.h:148
void signal_update()
Definition: binlog.h:666
uint8 checksum_alg_reset
Definition: binlog.h:287
char crash_safe_index_file_name[FN_REFLEN]
Definition: binlog.h:209
static const int MAX_RETRIES_FOR_DELETE_RENAME_FAILURE
Definition: binlog.h:884
PSI_file_key m_key_file_log_index
The instrumentation key to use for opening the log index file.
Definition: binlog.h:186
Definition: rpl_mi.h:86
Definition: rpl_rli.h:200
Common base class for all row-containing log events.
Definition: log_event.h:2698
Represents a bidirectional map between SID and SIDNO.
Definition: rpl_gtid.h:705
Transaction Coordinator Log.
Definition: tc_log.h:54
enum_result
Definition: tc_log.h:70
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
This is the base class for verifying transaction boundaries.
Definition: trx_boundary_parser.h:47
enum_trx_scope
Definition: transaction_info.h:53
Dependency tracker is a container singleton that dispatches between the three methods associated with...
Definition: rpl_trx_tracking.h:216
Caches for non-transactional and transactional data before writing it to the binary log.
Definition: binlog.cc:563
Definition: item_func.h:3007
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:49
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:56
DBUG_TRACE
Definition: do_ctype.cc:46
char * pos
Definition: do_ctype.cc:76
void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock)
Definition: binlog.cc:7655
int wait_for_update(const struct timespec *timeout)
Wait until we get a signal that the binary log has been updated.
Definition: binlog.cc:7543
bool mysql_show_binlog_events(THD *thd)
Execute a SHOW BINLOG EVENTS statement.
Definition: binlog.cc:3400
bool stmt_cannot_safely_rollback(const THD *thd)
This function checks if current statement cannot be rollded back safely.
Definition: binlog.cc:3077
bool normalize_binlog_name(char *to, const char *from, bool is_relay_log)
Turns a relative log binary log path into a full path, based on the opt_bin_logname or opt_relay_logn...
Definition: binlog.cc:191
std::pair< int, std::list< std::string > > get_log_index(bool need_lock_index=true)
Retrieves the contents of the index file associated with this log object into an std::list<std::strin...
Definition: binlog.cc:5480
int close_purge_index_file()
Definition: binlog.cc:5992
void set_max_size(ulong max_size_arg)
Definition: binlog.cc:7674
ulong rpl_read_size
Definition: binlog.cc:169
int flush_cache_to_file(my_off_t *flush_end_pos)
Flush the I/O cache to file.
Definition: binlog.cc:8493
void report_cache_write_error(THD *thd, bool is_transactional)
Definition: binlog.cc:5276
bool is_transaction_empty(THD *thd)
Check if the the transaction is empty.
Definition: binlog.cc:2966
int log_loaded_block(IO_CACHE *file)
Load data's io cache specific hook to be executed before a chunk of data is being read into the cache...
Definition: binlog.cc:3197
bool trans_cannot_safely_rollback(const THD *thd)
This function checks if a transaction cannot be rolled back safely.
Definition: binlog.cc:3064
bool purge_master_logs(THD *thd, const char *to_log)
Execute a PURGE BINARY LOGS TO <log> command.
Definition: binlog.cc:3092
THD * fetch_and_process_flush_stage_queue(const bool check_and_skip_flush_logs=false)
Fetch and empty BINLOG_FLUSH_STAGE and COMMIT_ORDER_FLUSH_STAGE flush queues and flush transactions t...
Definition: binlog.cc:8259
int rotate(bool force_rotate, bool *check_purge)
The method executes rotation when LOCK_log is already acquired by the caller.
Definition: binlog.cc:7049
void update_thd_next_event_pos(THD *thd)
Definition: binlog.cc:6823
int find_log_pos(LOG_INFO *linfo, const char *log_name, bool need_lock_index)
Find the position in the log-index-file for the given log name.
Definition: binlog.cc:5325
bool trans_has_updated_trans_table(const THD *thd)
This function checks if a transactional table was updated by the current transaction.
Definition: binlog.cc:3005
void close() override
This is called on shutdown, after ha_panic.
Definition: binlog.cc:7869
int new_file_without_locking(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6384
void report_missing_purged_gtids(const Gtid_set *slave_executed_gtid_set, std::string &errmsg)
Function to report the missing GTIDs.
Definition: binlog.cc:9142
uint next_file_id()
Definition: binlog.cc:7146
void cleanup()
Definition: binlog.cc:3449
int process_flush_stage_queue(my_off_t *total_bytes_var, bool *rotate_var, THD **out_queue_var)
Execute the flush stage.
Definition: binlog.cc:8301
bool do_write_cache(Binlog_cache_storage *cache, class Binlog_event_writer *writer)
Write the contents of the given IO_CACHE to the binary log.
Definition: binlog.cc:7194
int rollback(THD *thd, bool all) override
Write a rollback record of the transaction to the binary log.
Definition: binlog.cc:2441
void init_pthread_objects()
Definition: binlog.cc:3472
bool purge_master_logs_before_date(THD *thd, time_t purge_time)
Execute a PURGE BINARY LOGS BEFORE <date> command.
Definition: binlog.cc:3117
bool reencrypt_logs()
Re-encrypt previous existent binary/relay logs as below.
Definition: binlog.cc:1752
const char * log_bin_index
Definition: binlog.cc:165
int open_binlog(const char *opt_name)
Definition: binlog.cc:7698
~MYSQL_BIN_LOG() override
Definition: binlog.cc:3445
bool binlog_enabled()
Check whether binlog_hton has valid slot and enabled.
Definition: binlog.cc:1186
bool is_empty_transaction_in_binlog_cache(const THD *thd)
Check if at least one of transacaction and statement binlog caches contains an empty transaction,...
Definition: binlog.cc:2986
int register_purge_index_entry(const char *entry)
Definition: binlog.cc:6023
int sync_purge_index_file()
Definition: binlog.cc:6012
int gtid_end_transaction(THD *thd)
If the thread owns a GTID, this function generates an empty transaction and releases ownership of the...
Definition: binlog.cc:1631
int set_purge_index_file_name(const char *base_file_name)
Definition: binlog.cc:5957
void process_commit_stage_queue(THD *thd, THD *queue)
Commit a sequence of sessions.
Definition: binlog.cc:8356
void register_binlog_handler(THD *thd, bool trx)
Definition: binlog.cc:9340
bool open(PSI_file_key log_file_key, const char *log_name, const char *new_name, uint32 new_index_number)
Open the logfile and init IO_CACHE.
Definition: binlog.cc:3696
bool write_buffer(const char *buf, uint len, Master_info *mi)
Definition: binlog.cc:6764
int open_purge_index_file(bool destroy)
Definition: binlog.cc:5969
int set_crash_safe_index_file_name(const char *base_file_name)
Set the name of crash safe index file.
Definition: binlog.cc:5685
const char * log_bin_basename
Definition: binlog.cc:166
int purge_logs(const char *to_log, bool included, bool need_lock_index, bool need_update_threads, ulonglong *decrease_log_space, bool auto_purge)
Remove all logs before the given log from disk and from the index file.
Definition: binlog.cc:5838
bool write_transaction(THD *thd, binlog_cache_data *cache_data, Binlog_event_writer *writer)
Write the Gtid_log_event to the binary log (prior to writing the statement or transaction cache).
Definition: binlog.cc:1475
bool truncate_relaylog_file(Master_info *mi, my_off_t valid_pos)
Truncate the active relay log file in the specified position.
Definition: binlog.cc:7830
void check_binlog_cache_size(THD *thd)
Checks if the BINLOG_CACHE_SIZE's value is greater than MAX_BINLOG_CACHE_SIZE.
Definition: binlog.cc:1147
bool write_event_to_binlog_and_sync(Log_event *ev)
Definition: binlog.cc:7430
void check_binlog_stmt_cache_size(THD *thd)
Checks if the BINLOG_STMT_CACHE_SIZE's value is greater than MAX_BINLOG_STMT_CACHE_SIZE.
Definition: binlog.cc:1167
std::pair< bool, bool > sync_binlog_file(bool force)
Call fsync() to sync the file to disk.
Definition: binlog.cc:8506
int find_next_relay_log(char log_name[FN_REFLEN+1])
Find the relay log name following the given name from relay log index file.
Definition: binlog.cc:5459
int generate_new_name(char *new_name, const char *log_name, uint32 new_index_number=0)
Definition: binlog.cc:3631
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event *event, bool is_transactional)
Definition: binlog.cc:6839
int finish_commit(THD *thd)
Helper function executed when leaving ordered_commit.
Definition: binlog.cc:8548
bool write_stmt_directly(THD *thd, const char *stmt, size_t stmt_len, enum enum_sql_command sql_command)
Write a dml into statement cache and then flush it into binlog.
Definition: binlog.cc:7356
bool ending_single_stmt_trans(THD *thd, const bool all)
This function checks if a single statement transaction is about to commit or not.
Definition: binlog.cc:3053
int raw_get_current_log(LOG_INFO *linfo)
Definition: binlog.cc:5249
int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads)
Remove logs from index file.
Definition: binlog.cc:5776
enum_result commit(THD *thd, bool all) override
Commit the transaction in the transaction coordinator.
Definition: binlog.cc:7934
bool check_write_error(const THD *thd)
Definition: binlog.cc:5257
int get_gtid_executed(Sid_map *sid_map, Gtid_set *gtid_set)
Deep copy global_sid_map and gtid_executed.
Definition: binlog.cc:7154
int find_next_log(LOG_INFO *linfo, bool need_lock_index)
Find the position in the log-index-file for the given log name.
Definition: binlog.cc:5413
void make_log_name(char *buf, const char *log_ident)
Create a new log file name.
Definition: binlog.cc:6325
bool change_stage(THD *thd, Commit_stage_manager::StageID stage, THD *queue, mysql_mutex_t *leave_mutex, mysql_mutex_t *enter_mutex)
Enter a stage of the ordered commit procedure.
Definition: binlog.cc:8462
bool find_first_log(std::string &binlog_file_name, std::string &errmsg)
Find the oldest binary log referenced by the index file.
Definition: binlog.cc:4339
bool write_cache(THD *thd, class binlog_cache_data *cache_data, class Binlog_event_writer *writer)
Write the contents of the statement or transaction cache to the binary log.
Definition: binlog.cc:7468
bool write_event(Log_event *event_info)
Write an event to the binary log cache.
Definition: binlog.cc:6882
void update_binlog_end_pos(bool need_lock=true)
Definition: binlog.cc:9265
int rotate_and_purge(THD *thd, bool force_rotate)
Execute a FLUSH LOGS statement.
Definition: binlog.cc:7114
int get_current_log(LOG_INFO *linfo, bool need_lock_log=true)
Definition: binlog.cc:5241
bool is_query_in_union(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6814
int new_file_impl(bool need_lock, Format_description_log_event *extra_description_event)
Start writing to a new log file or reopen the old file.
Definition: binlog.cc:6404
bool write_event_to_binlog(Log_event *ev)
Definition: binlog.cc:7409
bool reset_logs(THD *thd, bool delete_only=false)
Removes files, as part of a RESET MASTER or RESET SLAVE statement, by deleting all logs referred to i...
Definition: binlog.cc:5523
bool is_active(const char *log_file_name)
Check if we are writing/reading to the given log file.
Definition: binlog.cc:6336
bool ending_trans(THD *thd, const bool all)
This function checks if a transaction, either a multi-statement or a single statement transaction is ...
Definition: binlog.cc:3038
int query_error_code(const THD *thd, bool not_killed)
Definition: binlog.cc:3129
void process_after_commit_stage_queue(THD *thd, THD *first)
Process after commit for a sequence of sessions.
Definition: binlog.cc:8431
std::pair< int, my_off_t > flush_thread_caches(THD *thd)
Flush caches for session.
Definition: binlog.cc:8207
int move_crash_safe_index_file_to_index_file(bool need_lock_index)
Move crash safe index file to index file.
Definition: binlog.cc:5040
void report_missing_gtids(const Gtid_set *previous_gtid_set, const Gtid_set *slave_executed_gtid_set, std::string &errmsg)
Function to report the missing GTIDs.
Definition: binlog.cc:9206
int purge_index_entry(THD *thd, ulonglong *decrease_log_space, bool need_lock_index)
Definition: binlog.cc:6040
bool init_and_set_log_file_name(const char *log_name, const char *new_name, uint32 new_index_number)
Definition: binlog.cc:3671
const char * generate_name(const char *log_name, const char *suffix, char *buff)
Definition: binlog.cc:3652
int purge_logs_before_date(time_t purge_time, bool auto_purge)
Remove all logs before the given file date from disk and from the index file.
Definition: binlog.cc:6209
bool opt_binlog_order_commits
Definition: binlog.cc:163
void init_thd_variables(THD *thd, bool all, bool skip_commit)
Set thread variables used while flushing a transaction.
Definition: binlog.cc:8224
int open_crash_safe_index_file()
Open a (new) crash safe index file.
Definition: binlog.cc:5709
void start_union_events(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6801
bool is_inited_purge_index_file()
Definition: binlog.cc:6007
bool open_index_file(const char *index_file_name_arg, const char *log_name, bool need_lock_index)
Definition: binlog.cc:3749
bool write_incident(THD *thd, bool need_lock_log, const char *err_msg, bool do_flush_and_sync=true)
Creates an incident event and writes it to the binary log.
Definition: binlog.cc:7388
bool assign_automatic_gtids_to_flush_group(THD *first_seen)
Assign automatic generated GTIDs for all commit group threads in the flush stage having gtid_next....
Definition: binlog.cc:1420
int register_create_index_entry(const char *entry)
Definition: binlog.cc:6035
int close_crash_safe_index_file()
Close the crash safe index file.
Definition: binlog.cc:5741
int prepare(THD *thd, bool all) override
Log a prepare record of the transaction to the storage engines.
Definition: binlog.cc:7881
void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log, const char *message)
Helper function to handle flush or sync stage errors.
Definition: binlog.cc:8668
int ordered_commit(THD *thd, bool all, bool skip_commit=false)
Flush and commit the transaction.
Definition: binlog.cc:8717
int add_log_to_index(uchar *log_file_name, size_t name_len, bool need_lock_index)
Append log file name to index file.
Definition: binlog.cc:5198
bool init_gtid_sets(Gtid_set *gtid_set, Gtid_set *lost_groups, bool verify_checksum, bool need_lock, Transaction_boundary_parser *trx_parser, Gtid_monitoring_info *partial_trx, bool is_server_starting=false)
Reads the set of all GTIDs in the binary/relay log, and the set of all lost GTIDs in the binary log,...
Definition: binlog.cc:4452
MYSQL_BIN_LOG(uint *sync_period, bool relay_log=false)
Definition: binlog.cc:3421
bool flush_and_sync(const bool force=false)
Flush binlog cache and synchronize to disk.
Definition: binlog.cc:6791
int new_file(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6375
bool show_binlog_events(THD *thd, MYSQL_BIN_LOG *binary_log)
Definition: binlog.cc:3232
void inc_prep_xids(THD *thd)
Increment the prepared XID counter.
Definition: binlog.cc:6340
void dec_prep_xids(THD *thd)
Decrement the prepared XID counter.
Definition: binlog.cc:6351
void stop_union_events(THD *thd)
Definition: binlog.cc:6809
bool flush()
Definition: binlog.cc:6787
int check_trx_rw_engines(THD *thd, Transaction_ctx::enum_trx_scope trx_scope)
Check if the transaction has no rw flag set for any of the storage engines.
Definition: binlog.cc:2973
bool stmt_has_updated_trans_table(Ha_trx_info *ha_list)
This function checks if a transactional table was updated by the current statement.
Definition: binlog.cc:3019
bool find_first_log_not_in_gtid_set(char *binlog_file_name, const Gtid_set *gtid_set, Gtid *first_gtid, std::string &errmsg)
Find the oldest binary log that contains any GTID that is not in the given gtid set.
Definition: binlog.cc:4354
void report_binlog_write_error()
Definition: binlog.cc:7520
bool after_write_to_relay_log(Master_info *mi)
Called after an event has been written to the relay log by the IO thread.
Definition: binlog.cc:6643
void purge()
The method executes logs purging routine.
Definition: binlog.cc:7070
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:43
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:47
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:51
#define mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
Definition: mysql_mutex.h:125
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
uint8_t uint8
Definition: my_inttypes.h:62
ulonglong my_off_t
Definition: my_inttypes.h:71
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
int32_t int32
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:66
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
enum_sql_command
Definition: my_sqlcommand.h:45
Common header for many mysys elements.
static int not_killed
Definition: myisamchk.cc:1629
static QUEUE queue
Definition: myisampack.cc:206
Common definition between mysql server & client.
#define NAME_LEN
Definition: mysql_com.h:66
Instrumentation helpers for conditions.
int(* mysql_cond_broadcast)(mysql_cond_t *that, const char *src_file, unsigned int src_line)
Definition: mysql_cond_service.h:51
ABI for instrumented mutexes.
Type inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:292
The namespace contains classes representing events that can occur in a replication stream.
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:411
Definition: buf0block_hint.cc:29
Definition: os0file.h:85
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:494
static mysql_service_status_t destroy(reference_caching_channel channel) noexcept
Definition: component.cc:49
Instrumentation helpers for conditions.
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
Performance schema instrumentation interface.
Instrumentation helpers for mutexes.
required string event
Definition: replication_group_member_actions.proto:31
Definition: binlog.h:87
Item_result type
Definition: binlog.h:91
ulong length
Definition: binlog.h:90
char * value
Definition: binlog.h:89
bool unsigned_flag
Definition: binlog.h:93
user_var_entry * user_var_event
Definition: binlog.h:88
uint charset_number
Definition: binlog.h:92
TODO: Move this structure to libbinlogevents/include/control_events.h when we start using C++11.
Definition: rpl_gtid.h:1047
Definition: my_sys.h:340
Definition: binlog.h:919
bool log_delayed
Definition: binlog.h:922
my_off_t last_pos_in_file
Definition: binlog.h:921
bool logged_data_file
Definition: binlog.h:922
THD * thd
Definition: binlog.h:920
Definition: binlog.h:116
my_off_t pos
Definition: binlog.h:119
my_off_t index_file_start_offset
Definition: binlog.h:118
LOG_INFO()
Definition: binlog.h:123
bool fatal
Definition: binlog.h:120
char log_file_name[FN_REFLEN]
Definition: binlog.h:117
my_off_t index_file_offset
Definition: binlog.h:118
int entry_index
Definition: binlog.h:121
int encrypted_header_size
Definition: binlog.h:122
Definition: completion_hash.h:34
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
MySQL mutex implementation.
Include file for Sun RPC to compile out of the box.
unsigned int uint
Definition: uca-dump.cc:29
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:858