MySQL  8.0.18
Source Code Documentation
binlog.h
Go to the documentation of this file.
1 #ifndef BINLOG_H_INCLUDED
2 /* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
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
48 #include "sql/rpl_trx_tracking.h"
49 #include "sql/tc_log.h" // TC_LOG
50 #include "sql/transaction_info.h" // Transaction_ctx
51 #include "thr_mutex.h"
52 
55 class Gtid_set;
56 class Ha_trx_info;
57 class Incident_log_event;
58 class Log_event;
59 class Master_info;
60 class Relay_log_info;
61 class Rows_log_event;
62 class Sid_map;
63 class THD;
65 class binlog_cache_data;
66 class user_var_entry;
68 
69 struct Gtid;
70 
71 typedef int64 query_id_t;
72 
73 /*
74  Maximum unique log filename extension.
75  Note: setting to 0x7FFFFFFF due to atol windows
76  overflow/truncate.
77  */
78 #define MAX_LOG_UNIQUE_FN_EXT 0x7FFFFFFF
79 
80 /*
81  Maximum allowed unique log filename extension for
82  RESET MASTER TO command - 2 Billion
83  */
84 #define MAX_ALLOWED_FN_EXT_RESET_MASTER 2000000000
85 
88  char *value;
93 };
94 
95 /**
96  Class for maintaining the commit stages for binary log group commit.
97  */
99  public:
100  class Mutex_queue {
101  friend class Stage_manager;
102 
103  public:
104  Mutex_queue() : m_first(nullptr), m_last(&m_first), m_size(0) {}
105 
106  void init(PSI_mutex_key key_LOCK_queue) {
107  mysql_mutex_init(key_LOCK_queue, &m_lock, MY_MUTEX_INIT_FAST);
108  }
109 
111 
112  bool is_empty() const { return m_first == nullptr; }
113 
114  /**
115  Append a linked list of threads to the queue.
116  @retval true The queue was empty before this operation.
117  @retval false The queue was non-empty before this operation.
118  */
119  bool append(THD *first);
120 
121  /**
122  Fetch the entire queue for a stage.
123 
124  This will fetch the entire queue in one go.
125  */
126  THD *fetch_and_empty();
127 
128  std::pair<bool, THD *> pop_front();
129 
130  inline int32 get_size() { return m_size.load(); }
131 
132  private:
135 
136  /**
137  Pointer to the first thread in the queue, or NULL if the queue is
138  empty.
139  */
141 
142  /**
143  Pointer to the location holding the end of the queue.
144 
145  This is either @c &first, or a pointer to the @c next_to_commit of
146  the last thread that is enqueued.
147  */
149 
150  /** size of the queue */
151  std::atomic<int32> m_size;
152 
153  /** Lock for protecting the queue. */
155  };
156 
157  public:
159 
161 
162  /**
163  Constants for queues for different stages.
164  */
166 
167  void init(PSI_mutex_key key_LOCK_flush_queue,
168  PSI_mutex_key key_LOCK_sync_queue,
169  PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_done,
170  PSI_cond_key key_COND_done) {
172  mysql_cond_init(key_COND_done, &m_cond_done);
173 #ifndef DBUG_OFF
174  /* reuse key_COND_done 'cos a new PSI object would be wasteful in !DBUG_OFF
175  */
176  mysql_cond_init(key_COND_done, &m_cond_preempt);
177 #endif
178  m_queue[FLUSH_STAGE].init(key_LOCK_flush_queue);
179  m_queue[SYNC_STAGE].init(key_LOCK_sync_queue);
180  m_queue[COMMIT_STAGE].init(key_LOCK_commit_queue);
181  }
182 
183  void deinit() {
184  for (size_t i = 0; i < STAGE_COUNTER; ++i) m_queue[i].deinit();
186 #ifndef DBUG_OFF
188 #endif
190  }
191 
192  /**
193  Enroll a set of sessions for a stage.
194 
195  This will queue the session thread for writing and flushing.
196 
197  If the thread being queued is assigned as stage leader, it will
198  return immediately.
199 
200  If wait_if_follower is true the thread is not the stage leader,
201  the thread will be wait for the queue to be processed by the
202  leader before it returns.
203  In DBUG-ON version the follower marks is preempt status as ready.
204 
205  @param stage Stage identifier for the queue to append to.
206  @param first Queue to append.
207  @param stage_mutex
208  Pointer to the currently held stage mutex, or NULL if
209  we're not in a stage.
210 
211  @retval true Thread is stage leader.
212  @retval false Thread was not stage leader and processing has been done.
213  */
214  bool enroll_for(StageID stage, THD *first, mysql_mutex_t *stage_mutex);
215 
216  std::pair<bool, THD *> pop_front(StageID stage) {
217  return m_queue[stage].pop_front();
218  }
219 
220 #ifndef DBUG_OFF
221  /**
222  The method ensures the follower's execution path can be preempted
223  by the leader's thread.
224  Preempt status of @c head follower is checked to engange the leader
225  into waiting when set.
226 
227  @param head THD* of a follower thread
228  */
229  void clear_preempt_status(THD *head);
230 #endif
231 
232  /**
233  Fetch the entire queue and empty it.
234 
235  @return Pointer to the first session of the queue.
236  */
238  DBUG_PRINT("debug", ("Fetching queue for stage %d", stage));
239  return m_queue[stage].fetch_and_empty();
240  }
241 
242  /**
243  Introduces a wait operation on the executing thread. The
244  waiting is done until the timeout elapses or count is
245  reached (whichever comes first).
246 
247  If count == 0, then the session will wait until the timeout
248  elapses. If timeout == 0, then there is no waiting.
249 
250  @param usec the number of microseconds to wait.
251  @param count wait for as many as count to join the queue the
252  session is waiting on
253  @param stage which stage queue size to compare count against.
254  */
255  void wait_count_or_timeout(ulong count, long usec, StageID stage);
256 
257  void signal_done(THD *queue);
258 
259  private:
260  /**
261  Queues for sessions.
262 
263  We need two queues:
264  - Waiting. Threads waiting to be processed
265  - Committing. Threads waiting to be committed.
266  */
268 
269  /** Condition variable to indicate that the commit was processed */
271 
272  /** Mutex used for the condition variable above */
274 #ifndef DBUG_OFF
275  /** Flag is set by Leader when it starts waiting for follower's all-clear */
277 
278  /** Condition variable to indicate a follower started waiting for commit */
280 #endif
281 };
282 
283 /* log info errors */
284 #define LOG_INFO_EOF -1
285 #define LOG_INFO_IO -2
286 #define LOG_INFO_INVALID -3
287 #define LOG_INFO_SEEK -4
288 #define LOG_INFO_MEM -6
289 #define LOG_INFO_FATAL -7
290 #define LOG_INFO_IN_USE -8
291 #define LOG_INFO_EMFILE -9
292 
293 /* bitmap to MYSQL_BIN_LOG::close() */
294 #define LOG_CLOSE_INDEX 1
295 #define LOG_CLOSE_TO_BE_OPENED 2
296 #define LOG_CLOSE_STOP_EVENT 4
297 
298 /*
299  Note that we destroy the lock mutex in the destructor here.
300  This means that object instances cannot be destroyed/go out of scope
301  until we have reset thd->current_linfo to NULL;
302  */
303 struct LOG_INFO {
307  bool fatal; // if the purge happens to give us a negative offset
308  int entry_index; // used in purge_logs(), calculatd in find_log_pos().
311  : index_file_offset(0),
313  pos(0),
314  fatal(0),
315  entry_index(0),
317  memset(log_file_name, 0, FN_REFLEN);
318  }
319 };
320 
321 /*
322  TODO use mmap instead of IO_CACHE for binlog
323  (mmap+fsync is two times faster than write+fsync)
324 */
325 class MYSQL_BIN_LOG : public TC_LOG {
326  public:
327  class Binlog_ofile;
328 
329  private:
331 
332  /* LOCK_log is inited by init_pthread_objects() */
334  char *name;
336  char db[NAME_LEN + 1];
339 
340  /** Instrumentation key to use for file io in @c log_file */
342  /** The instrumentation key to use for @ LOCK_log. */
344  /** The instrumentation key to use for @ LOCK_index. */
346  /** The instrumentation key to use for @ LOCK_binlog_end_pos. */
348 
350 
355  /** The instrumentation key to use for @ LOCK_commit. */
357  /** The instrumentation key to use for @ LOCK_sync. */
359  /** The instrumentation key to use for @ LOCK_xids. */
361  /** The instrumentation key to use for @ update_cond. */
363  /** The instrumentation key to use for @ prep_xids_cond. */
365  /** The instrumentation key to use for opening the log file. */
367  /** The instrumentation key to use for opening the log index file. */
369  /** The instrumentation key to use for opening a log cache file. */
371  /** The instrumentation key to use for opening a log index cache file. */
373 
374  /* POSIX thread objects are inited by init_pthread_objects() */
381 
382  std::atomic<my_off_t> atomic_binlog_end_pos;
386  /*
387  crash_safe_index_file is temp file used for guaranteeing
388  index file crash safe when master server restarts.
389  */
392  /*
393  purge_file is a temp file used in purge_logs so that the index file
394  can be updated before deleting files from disk, yielding better crash
395  recovery. It is created on demand the first time purge_logs is called
396  and then reused for subsequent calls. It is cleaned up in cleanup().
397  */
400  /*
401  The max size before rotation (usable only if log_type == LOG_BIN: binary
402  logs and relay logs).
403  For a binlog, max_size should be max_binlog_size.
404  For a relay log, it should be max_relay_log_size if this is non-zero,
405  max_binlog_size otherwise.
406  max_size is set in init(), and dynamically changed (when one does SET
407  GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
408  fix_max_relay_log_size).
409  */
411 
412  // current file sequence number for load data infile binary logging
414 
415  /* pointer to the sync period variable, for binlog this will be
416  sync_binlog_period, for relay log this will be
417  sync_relay_log_period
418  */
421 
423  std::atomic<int32> m_atomic_prep_xids{0};
424 
425  /**
426  Increment the prepared XID counter.
427  */
428  void inc_prep_xids(THD *thd);
429 
430  /**
431  Decrement the prepared XID counter.
432 
433  Signal m_prep_xids_cond if the counter reaches zero.
434  */
435  void dec_prep_xids(THD *thd);
436 
438 
439  inline uint get_sync_period() { return *sync_period_ptr; }
440 
441  public:
442  /*
443  This is used to start writing to a new log file. The difference from
444  new_file() is locking. new_file_without_locking() does not acquire
445  LOCK_log.
446  */
448  Format_description_log_event *extra_description_event);
449 
450  private:
451  int new_file_impl(bool need_lock,
452  Format_description_log_event *extra_description_event);
453 
454  /** Manage the stages in ordered_commit. */
456 
457  bool open(PSI_file_key log_file_key, const char *log_name,
458  const char *new_name, uint32 new_index_number);
459  bool init_and_set_log_file_name(const char *log_name, const char *new_name,
460  uint32 new_index_number);
461  int generate_new_name(char *new_name, const char *log_name,
462  uint32 new_index_number = 0);
463 
464  public:
465  const char *generate_name(const char *log_name, const char *suffix,
466  char *buff);
467  bool is_open() { return atomic_log_state != LOG_CLOSED; }
468 
469  /* This is relay log */
471 
472  uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
473  /*
474  Holds the last seen in Relay-Log FD's checksum alg value.
475  The initial value comes from the slave's local FD that heads
476  the very first Relay-Log file. In the following the value may change
477  with each received master's FD_m.
478  Besides to be used in verification events that IO thread receives
479  (except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd),
480  the value specifies if/how to compute checksum for slave's local events
481  and the first fake Rotate (R_f^1) coming from the master.
482  R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
483 
484  Legends for the checksum related comments:
485 
486  FD - Format-Description event,
487  R - Rotate event
488  R_f - the fake Rotate event
489  E - an arbirary event
490 
491  The underscore indexes for any event
492  `_s' indicates the event is generated by Slave
493  `_m' - by Master
494 
495  Two special underscore indexes of FD:
496  FD_q - Format Description event for queuing (relay-logging)
497  FD_e - Format Description event for executing (relay-logging)
498 
499  Upper indexes:
500  E^n - n:th event is a sequence
501 
502  RL - Relay Log
503  (A) - checksum algorithm descriptor value
504  FD.(A) - the value of (A) in FD
505  */
507 
508  MYSQL_BIN_LOG(uint *sync_period);
509  ~MYSQL_BIN_LOG();
510 
512  PSI_mutex_key key_LOCK_index, PSI_mutex_key key_LOCK_commit,
513  PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_done,
514  PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_log,
515  PSI_mutex_key key_LOCK_binlog_end_pos, PSI_mutex_key key_LOCK_sync,
516  PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_xids,
517  PSI_cond_key key_COND_done, PSI_cond_key key_update_cond,
518  PSI_cond_key key_prep_xids_cond, PSI_file_key key_file_log,
519  PSI_file_key key_file_log_index, PSI_file_key key_file_log_cache,
520  PSI_file_key key_file_log_index_cache) {
521  m_key_COND_done = key_COND_done;
522 
523  m_key_LOCK_commit_queue = key_LOCK_commit_queue;
524  m_key_LOCK_done = key_LOCK_done;
525  m_key_LOCK_flush_queue = key_LOCK_flush_queue;
526  m_key_LOCK_sync_queue = key_LOCK_sync_queue;
527 
528  m_key_LOCK_index = key_LOCK_index;
529  m_key_LOCK_log = key_LOCK_log;
530  m_key_LOCK_binlog_end_pos = key_LOCK_binlog_end_pos;
531  m_key_LOCK_commit = key_LOCK_commit;
532  m_key_LOCK_sync = key_LOCK_sync;
533  m_key_LOCK_xids = key_LOCK_xids;
534  m_key_update_cond = key_update_cond;
535  m_key_prep_xids_cond = key_prep_xids_cond;
536  m_key_file_log = key_file_log;
537  m_key_file_log_index = key_file_log_index;
538  m_key_file_log_cache = key_file_log_cache;
539  m_key_file_log_index_cache = key_file_log_index_cache;
540  }
541 
542  public:
543  /** Manage the MTS dependency tracking */
545 
546  /**
547  Find the oldest binary log that contains any GTID that
548  is not in the given gtid set.
549 
550  @param[out] binlog_file_name the file name of oldest binary log found
551  @param[in] gtid_set the given gtid set
552  @param[out] first_gtid the first GTID information from the binary log
553  file returned at binlog_file_name
554  @param[out] errmsg the error message outputted, which is left untouched
555  if the function returns false
556  @return false on success, true on error.
557  */
558  bool find_first_log_not_in_gtid_set(char *binlog_file_name,
559  const Gtid_set *gtid_set,
560  Gtid *first_gtid, const char **errmsg);
561 
562  /**
563  Reads the set of all GTIDs in the binary/relay log, and the set
564  of all lost GTIDs in the binary log, and stores each set in
565  respective argument.
566 
567  @param gtid_set Will be filled with all GTIDs in this binary/relay
568  log.
569  @param lost_groups Will be filled with all GTIDs in the
570  Previous_gtids_log_event of the first binary log that has a
571  Previous_gtids_log_event. This is requested to binary logs but not
572  to relay logs.
573  @param verify_checksum If true, checksums will be checked.
574  @param need_lock If true, LOCK_log, LOCK_index, and
575  global_sid_lock->wrlock are acquired; otherwise they are asserted
576  to be taken already.
577  @param [out] trx_parser This will be used to return the actual
578  relaylog transaction parser state because of the possibility
579  of partial transactions.
580  @param [out] partial_trx If a transaction was left incomplete
581  on the relaylog, its GTID information should be returned to be
582  used in the case of the rest of the transaction be added to the
583  relaylog.
584  @param is_server_starting True if the server is starting.
585  @return false on success, true on error.
586  */
587  bool init_gtid_sets(Gtid_set *gtid_set, Gtid_set *lost_groups,
588  bool verify_checksum, bool need_lock,
589  Transaction_boundary_parser *trx_parser,
590  Gtid_monitoring_info *partial_trx,
591  bool is_server_starting = false);
592 
593  void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param) {
595  previous_gtid_set_relaylog = previous_gtid_set_param;
596  }
597  /**
598  If the thread owns a GTID, this function generates an empty
599  transaction and releases ownership of the GTID.
600 
601  - If the binary log is disabled for this thread, the GTID is
602  inserted directly into the mysql.gtid_executed table and the
603  GTID is included in @@global.gtid_executed. (This only happens
604  for DDL, since DML will save the GTID into table and release
605  ownership inside ha_commit_trans.)
606 
607  - If the binary log is enabled for this thread, an empty
608  transaction consisting of GTID, BEGIN, COMMIT is written to the
609  binary log, the GTID is included in @@global.gtid_executed, and
610  the GTID is added to the mysql.gtid_executed table on the next
611  binlog rotation.
612 
613  This function must be called by any committing statement (COMMIT,
614  implicitly committing statements, or Xid_log_event), after the
615  statement has completed execution, regardless of whether the
616  statement updated the database.
617 
618  This logic ensures that an empty transaction is generated for the
619  following cases:
620 
621  - Explicit empty transaction:
622  SET GTID_NEXT = 'UUID:NUMBER'; BEGIN; COMMIT;
623 
624  - Transaction or DDL that gets completely filtered out in the
625  slave thread.
626 
627  @param thd The committing thread
628 
629  @retval 0 Success
630  @retval nonzero Error
631  */
632  int gtid_end_transaction(THD *thd);
633  /**
634  Re-encrypt previous existent binary/relay logs as below.
635  Starting from the next to last entry on the index file, iterating
636  down to the first one:
637  - If the file is encrypted, re-encrypt it. Otherwise, skip it.
638  - If failed to open the file, report an error.
639 
640  @retval False Success
641  @retval True Error
642  */
643  bool reencrypt_logs();
644 
645  private:
646  std::atomic<enum_log_state> atomic_log_state{LOG_CLOSED};
647 
648  /* The previous gtid set in relay log. */
650 
651  int open(const char *opt_name) { return open_binlog(opt_name); }
652  bool change_stage(THD *thd, Stage_manager::StageID stage, THD *queue,
653  mysql_mutex_t *leave, mysql_mutex_t *enter);
654  std::pair<int, my_off_t> flush_thread_caches(THD *thd);
655  int flush_cache_to_file(my_off_t *flush_end_pos);
656  int finish_commit(THD *thd);
657  std::pair<bool, bool> sync_binlog_file(bool force);
659  void process_after_commit_stage_queue(THD *thd, THD *first);
660  int process_flush_stage_queue(my_off_t *total_bytes_var, bool *rotate_var,
661  THD **out_queue_var);
662  int ordered_commit(THD *thd, bool all, bool skip_commit = false);
663  void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log);
665  class Binlog_event_writer *writer);
667 
668  public:
669  int open_binlog(const char *opt_name);
670  void close();
671  enum_result commit(THD *thd, bool all);
672  int rollback(THD *thd, bool all);
673  bool truncate_relaylog_file(Master_info *mi, my_off_t valid_pos);
674  int prepare(THD *thd, bool all);
675 #if defined(MYSQL_SERVER)
676 
677  void update_thd_next_event_pos(THD *thd);
679  bool is_transactional);
680 
681 #endif /* defined(MYSQL_SERVER) */
684  void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock);
685  void set_max_size(ulong max_size_arg);
686  void signal_update() {
687  DBUG_TRACE;
689  return;
690  }
691 
692  void update_binlog_end_pos(bool need_lock = true);
693  void update_binlog_end_pos(const char *file, my_off_t pos);
694 
695  int wait_for_update(const struct timespec *timeout);
696 
697  public:
698  void init_pthread_objects();
699  void cleanup();
700  /**
701  Create a new binary log.
702  @param log_name Name of binlog
703  @param new_name Name of binlog, too. todo: what's the difference
704  between new_name and log_name?
705  @param max_size_arg The size at which this binlog will be rotated.
706  @param null_created_arg If false, and a Format_description_log_event
707  is written, then the Format_description_log_event will have the
708  timestamp 0. Otherwise, it the timestamp will be the time when the
709  event was written to the log.
710  @param need_lock_index If true, LOCK_index is acquired; otherwise
711  LOCK_index must be taken by the caller.
712  @param need_sid_lock If true, the read lock on global_sid_lock
713  will be acquired. Otherwise, the caller must hold the read lock
714  on global_sid_lock.
715  @param extra_description_event The master's FDE to be written by the I/O
716  thread while creating a new relay log file. This should be NULL for
717  binary log files.
718  @param new_index_number The binary log file index number to start from
719  after the RESET MASTER TO command is called.
720  */
721  bool open_binlog(const char *log_name, const char *new_name,
722  ulong max_size_arg, bool null_created_arg,
723  bool need_lock_index, bool need_sid_lock,
724  Format_description_log_event *extra_description_event,
725  uint32 new_index_number = 0);
726  bool open_index_file(const char *index_file_name_arg, const char *log_name,
727  bool need_lock_index);
728  /* Use this to start writing a new log file */
729  int new_file(Format_description_log_event *extra_description_event);
730 
731  bool write_event(Log_event *event_info);
732  bool write_cache(THD *thd, class binlog_cache_data *cache_data,
733  class Binlog_event_writer *writer);
734  /**
735  Assign automatic generated GTIDs for all commit group threads in the flush
736  stage having gtid_next.type == AUTOMATIC_GTID.
737 
738  @param first_seen The first thread seen entering the flush stage.
739  @return Returns false if succeeds, otherwise true is returned.
740  */
741  bool assign_automatic_gtids_to_flush_group(THD *first_seen);
742  bool write_gtid(THD *thd, binlog_cache_data *cache_data,
743  class Binlog_event_writer *writer);
744 
745  /**
746  Write a dml into statement cache and then flush it into binlog. It writes
747  Gtid_log_event and BEGIN, COMMIT automatically.
748 
749  It is aimed to handle cases of "background" logging where a statement is
750  logged indirectly, like "DELETE FROM a_memory_table". So don't use it on
751  any normal statement.
752 
753  @param[in] thd the THD object of current thread.
754  @param[in] stmt the DELETE statement.
755  @param[in] stmt_len the length of DELETE statement.
756 
757  @return Returns false if succeeds, otherwise true is returned.
758  */
759  bool write_dml_directly(THD *thd, const char *stmt, size_t stmt_len);
760 
761  void report_cache_write_error(THD *thd, bool is_transactional);
762  bool check_write_error(const THD *thd);
763  bool write_incident(THD *thd, bool need_lock_log, const char *err_msg,
764  bool do_flush_and_sync = true);
765  bool write_incident(Incident_log_event *ev, THD *thd, bool need_lock_log,
766  const char *err_msg, bool do_flush_and_sync = true);
770  void start_union_events(THD *thd, query_id_t query_id_param);
771  void stop_union_events(THD *thd);
772  bool is_query_in_union(THD *thd, query_id_t query_id_param);
773 
774  bool write_buffer(const char *buf, uint len, Master_info *mi);
775  bool write_event(Log_event *ev, Master_info *mi);
776 
777  private:
779 
780  public:
781  void make_log_name(char *buf, const char *log_ident);
782  bool is_active(const char *log_file_name);
783  int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads);
784  int rotate(bool force_rotate, bool *check_purge);
785  void purge();
786  int rotate_and_purge(THD *thd, bool force_rotate);
787 
788  bool flush();
789  /**
790  Flush binlog cache and synchronize to disk.
791 
792  This function flushes events in binlog cache to binary log file,
793  it will do synchronizing according to the setting of system
794  variable 'sync_binlog'. If file is synchronized, @c synced will
795  be set to 1, otherwise 0.
796 
797  @param[in] force if true, ignores the 'sync_binlog' and synchronizes the
798  file.
799 
800  @retval 0 Success
801  @retval other Failure
802  */
803  bool flush_and_sync(const bool force = false);
804  int purge_logs(const char *to_log, bool included, bool need_lock_index,
805  bool need_update_threads, ulonglong *decrease_log_space,
806  bool auto_purge);
807  int purge_logs_before_date(time_t purge_time, bool auto_purge);
808  int set_crash_safe_index_file_name(const char *base_file_name);
811  int add_log_to_index(uchar *log_file_name, size_t name_len,
812  bool need_lock_index);
813  int move_crash_safe_index_file_to_index_file(bool need_lock_index);
814  int set_purge_index_file_name(const char *base_file_name);
815  int open_purge_index_file(bool destroy);
818  int sync_purge_index_file();
819  int register_purge_index_entry(const char *entry);
820  int register_create_index_entry(const char *entry);
821  int purge_index_entry(THD *thd, ulonglong *decrease_log_space,
822  bool need_lock_index);
823  bool reset_logs(THD *thd, bool delete_only = false);
824  void close(uint exiting, bool need_lock_log, bool need_lock_index);
825 
826  // iterating through the log index file
827  int find_log_pos(LOG_INFO *linfo, const char *log_name, bool need_lock_index);
828  int find_next_log(LOG_INFO *linfo, bool need_lock_index);
829  int find_next_relay_log(char log_name[FN_REFLEN + 1]);
830  int get_current_log(LOG_INFO *linfo, bool need_lock_log = true);
831  int raw_get_current_log(LOG_INFO *linfo);
832  uint next_file_id();
833  /**
834  Retrieves the contents of the index file associated with this log object
835  into an `std::list<std::string>` object. The order held by the index file is
836  kept.
837 
838  @param need_lock_index whether or not the lock over the index file should be
839  acquired inside the function.
840 
841  @return a pair: a function status code; a list of `std::string` objects with
842  the content of the log index file.
843  */
844  std::pair<int, std::list<std::string>> get_log_index(
845  bool need_lock_index = true);
846  inline char *get_index_fname() { return index_file_name; }
847  inline char *get_log_fname() { return log_file_name; }
848  const char *get_name() const { return name; }
849  inline mysql_mutex_t *get_log_lock() { return &LOCK_log; }
850  inline mysql_cond_t *get_log_cond() { return &update_cond; }
852 
855  inline IO_CACHE *get_index_file() { return &index_file; }
857  /*
858  It is called by the threads (e.g. dump thread, applier thread) which want
859  to read hot log without LOCK_log protection.
860  */
863  return atomic_binlog_end_pos;
864  }
868 
869  /**
870  Deep copy global_sid_map and gtid_executed.
871  Both operations are done under LOCK_commit and global_sid_lock
872  protection.
873 
874  @param[out] sid_map The Sid_map to which global_sid_map will
875  be copied.
876  @param[out] gtid_set The Gtid_set to which gtid_executed will
877  be copied.
878 
879  @return the operation status
880  @retval 0 OK
881  @retval !=0 Error
882  */
883  int get_gtid_executed(Sid_map *sid_map, Gtid_set *gtid_set);
884 
885  /*
886  True while rotating binlog, which is caused by logging Incident_log_event.
887  */
889 };
890 
895 };
896 
898 
899 /**
900  Check if the the transaction is empty.
901 
902  @param thd The client thread that executed the current statement.
903 
904  @retval true No changes found in any storage engine
905  @retval false Otherwise.
906 
907 **/
908 bool is_transaction_empty(THD *thd);
909 /**
910  Check if the transaction has no rw flag set for any of the storage engines.
911 
912  @param thd The client thread that executed the current statement.
913  @param trx_scope The transaction scope to look into.
914 
915  @retval the number of engines which have actual changes.
916  */
918 
919 /**
920  Check if at least one of transacaction and statement binlog caches contains
921  an empty transaction, other one is empty or contains an empty transaction,
922  which has two binlog events "BEGIN" and "COMMIT".
923 
924  @param thd The client thread that executed the current statement.
925 
926  @retval true At least one of transacaction and statement binlog caches
927  contains an empty transaction, other one is empty or
928  contains an empty transaction.
929  @retval false Otherwise.
930 */
932 bool trans_has_updated_trans_table(const THD *thd);
934 bool ending_trans(THD *thd, const bool all);
935 bool ending_single_stmt_trans(THD *thd, const bool all);
936 bool trans_cannot_safely_rollback(const THD *thd);
937 bool stmt_cannot_safely_rollback(const THD *thd);
938 
939 int log_loaded_block(IO_CACHE *file);
940 
941 bool purge_master_logs(THD *thd, const char *to_log);
942 bool purge_master_logs_before_date(THD *thd, time_t purge_time);
944 bool mysql_show_binlog_events(THD *thd);
945 void check_binlog_cache_size(THD *thd);
947 bool binlog_enabled();
948 void register_binlog_handler(THD *thd, bool trx);
949 int query_error_code(const THD *thd, bool not_killed);
950 
951 extern const char *log_bin_index;
952 extern const char *log_bin_basename;
953 extern bool opt_binlog_order_commits;
954 extern ulong rpl_read_size;
955 /**
956  Turns a relative log binary log path into a full path, based on the
957  opt_bin_logname or opt_relay_logname. Also trims the cr-lf at the
958  end of the full_path before return to avoid any server startup
959  problem on windows.
960 
961  @param from The log name we want to make into an absolute path.
962  @param to The buffer where to put the results of the
963  normalization.
964  @param is_relay_log Switch that makes is used inside to choose which
965  option (opt_bin_logname or opt_relay_logname) to
966  use when calculating the base path.
967 
968  @returns true if a problem occurs, false otherwise.
969  */
970 
971 bool normalize_binlog_name(char *to, const char *from, bool is_relay_log);
972 
973 #endif /* BINLOG_H_INCLUDED */
THD * m_first
Pointer to the first thread in the queue, or NULL if the queue is empty.
Definition: binlog.h:140
int generate_new_name(char *new_name, const char *log_name, uint32 new_index_number=0)
Definition: binlog.cc:3597
bool init_and_set_log_file_name(const char *log_name, const char *new_name, uint32 new_index_number)
Definition: binlog.cc:3637
enum_result commit(THD *thd, bool all)
Commit the transaction in the transaction coordinator.
Definition: binlog.cc:7848
unsigned long long int ulonglong
Definition: my_inttypes.h:55
PSI_mutex_key m_key_LOCK_log
The instrumentation key to use for @ LOCK_log.
Definition: binlog.h:343
Instrumentation helpers for mutexes.
PSI_mutex_key m_key_LOCK_done
Definition: binlog.h:352
unsigned char uchar
Definition: my_inttypes.h:51
bool append(THD *first)
Append a linked list of threads to the queue.
Definition: binlog.cc:2216
PSI_file_key m_key_file_log_cache
The instrumentation key to use for opening a log cache file.
Definition: binlog.h:370
Dependency tracker is a container singleton that dispatches between the three methods associated with...
Definition: rpl_trx_tracking.h:215
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:46
const char * log_bin_basename
Definition: binlog.cc:161
MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log
PSI_cond_key m_key_update_cond
The instrumentation key to use for @ update_cond.
Definition: binlog.h:362
void unlock_binlog_end_pos()
Definition: binlog.h:867
IO_CACHE purge_index_file
Definition: binlog.h:398
Item_result
Type of the user defined function return slot and arguments
Definition: udf_registration_types.h:38
Binlog_ofile * get_binlog_file()
Definition: binlog.h:851
StageID
Constants for queues for different stages.
Definition: binlog.h:165
void stop_union_events(THD *thd)
Definition: binlog.cc:6755
Definition: binlog.h:165
ssize_t count
Definition: memcached.c:386
Gtid_set * previous_gtid_set_relaylog
Definition: binlog.h:649
mysql_mutex_t m_lock_done
Mutex used for the condition variable above.
Definition: binlog.h:273
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:7744
Definition: binlog.h:165
void wait_count_or_timeout(ulong count, long usec, StageID stage)
Introduces a wait operation on the executing thread.
Definition: binlog.cc:2371
void process_after_commit_stage_queue(THD *thd, THD *first)
Process after commit for a sequence of sessions.
Definition: binlog.cc:8295
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:3000
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
void update_binlog_end_pos(bool need_lock=true)
Definition: binlog.cc:9094
uint sync_counter
Definition: binlog.h:420
Include file for Sun RPC to compile out of the box.
Some integer typedefs for easier portability.
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:1399
Definition: binlog.h:325
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:39
int move_crash_safe_index_file_to_index_file(bool need_lock_index)
Move crash safe index file to index file.
Definition: binlog.cc:5000
Transaction Coordinator Log.
Definition: tc_log.h:54
bool log_delayed
Definition: binlog.h:894
Caches for non-transactional and transactional data before writing it to the binary log...
Definition: binlog.cc:563
void make_log_name(char *buf, const char *log_ident)
Create a new log file name.
Definition: binlog.cc:6284
MySQL mutex implementation.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
void check_binlog_cache_size(THD *thd)
Checks if the BINLOG_CACHE_SIZE&#39;s value is greater than MAX_BINLOG_CACHE_SIZE.
Definition: binlog.cc:1126
bool write_event(Log_event *event_info)
Write an event to the binary log cache.
Definition: binlog.cc:6828
Mutex_queue m_queue[STAGE_COUNTER]
Queues for sessions.
Definition: binlog.h:267
bool write_event_to_binlog_and_flush(Log_event *ev)
#define mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
Definition: mysql_mutex.h:123
Contains the classes representing events occurring in the replication stream.
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_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:511
void process_commit_stage_queue(THD *thd, THD *queue)
Commit a sequence of sessions.
Definition: binlog.cc:8221
bool open_index_file(const char *index_file_name_arg, const char *log_name, bool need_lock_index)
Definition: binlog.cc:3715
void start_union_events(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6747
bool leader_await_preempt_status
Flag is set by Leader when it starts waiting for follower&#39;s all-clear.
Definition: binlog.h:276
int set_crash_safe_index_file_name(const char *base_file_name)
Set the name of crash safe index file.
Definition: binlog.cc:5644
PSI_cond_key m_key_prep_xids_cond
The instrumentation key to use for @ prep_xids_cond.
Definition: binlog.h:364
For binlog version 4.
Definition: log_event.h:1458
PSI_file_key m_key_file_log_index
The instrumentation key to use for opening the log index file.
Definition: binlog.h:368
enum_trx_scope
Definition: transaction_info.h:53
char * get_index_fname()
Definition: binlog.h:846
void deinit()
Definition: binlog.h:183
Performance schema instrumentation interface.
THD * fetch_and_empty()
Fetch the entire queue for a stage.
Definition: binlog.cc:2351
int new_file(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6334
void inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:255
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:5440
static QUEUE queue
Definition: myisampack.cc:206
ulong max_size
Definition: binlog.h:410
bool check_write_error(const THD *thd)
Definition: binlog.cc:5217
Item_result type
Definition: binlog.h:90
#define NAME_LEN
Definition: mysql_com.h:67
TODO: Move this structure to libbinlogevents/include/control_events.h when we start using C++11...
Definition: rpl_gtid.h:924
bool binlog_enabled()
Check whether binlog_hton has valid slot and enabled
Definition: binlog.cc:1165
Represents a bidirectional map between SID and SIDNO.
Definition: rpl_gtid.h:582
PSI_mutex_key m_key_LOCK_binlog_end_pos
The instrumentation key to use for @ LOCK_binlog_end_pos.
Definition: binlog.h:347
bool stmt_cannot_safely_rollback(const THD *thd)
This function checks if current statement cannot be rollded back safely.
Definition: binlog.cc:3091
Mutex_queue()
Definition: binlog.h:104
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:5373
user_var_entry * user_var_event
Definition: binlog.h:87
Instrumentation helpers for conditions.
PSI_mutex_key m_key_LOCK_xids
The instrumentation key to use for @ LOCK_xids.
Definition: binlog.h:360
ulong rpl_read_size
Definition: binlog.cc:164
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:3033
char log_file_name[FN_REFLEN]
Definition: binlog.h:335
void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock)
Definition: binlog.cc:7570
Transaction_dependency_tracker m_dependency_tracker
Manage the MTS dependency tracking.
Definition: binlog.h:544
bool write_buffer(const char *buf, uint len, Master_info *mi)
Definition: binlog.cc:6710
#define mysql_cond_destroy(C)
Definition: mysql_cond.h:39
~Stage_manager()
Definition: binlog.h:160
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:1608
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:49
Common definition between mysql server & client.
mysql_mutex_t * get_log_lock()
Definition: binlog.h:849
Functions related to handling of plugins and other dynamically loaded libraries.
bool is_rotating_caused_by_incident
Definition: binlog.h:888
int purge_index_entry(THD *thd, ulonglong *decrease_log_space, bool need_lock_index)
Definition: binlog.cc:6000
int get_gtid_executed(Sid_map *sid_map, Gtid_set *gtid_set)
Deep copy global_sid_map and gtid_executed.
Definition: binlog.cc:7100
std::pair< bool, THD * > pop_front(StageID stage)
Definition: binlog.h:216
std::atomic< my_off_t > atomic_binlog_end_pos
Definition: binlog.h:382
void deinit()
Definition: binlog.h:110
char crash_safe_index_file_name[FN_REFLEN]
Definition: binlog.h:391
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:41
void lock_index()
Definition: binlog.h:853
mysql_mutex_t * get_binlog_end_pos_lock()
Definition: binlog.h:865
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
Performance schema instrumentation interface.
Definition: binlog.h:330
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:6168
int close_purge_index_file()
Definition: binlog.cc:5952
void inc_prep_xids(THD *thd)
Increment the prepared XID counter.
Definition: binlog.cc:6299
int query_error_code(const THD *thd, bool not_killed)
Definition: binlog.cc:3143
void init(PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_done, PSI_cond_key key_COND_done)
Definition: binlog.h:167
THD ** m_last
Pointer to the location holding the end of the queue.
Definition: binlog.h:148
Definition: rpl_rli.h:164
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:6363
mysql_cond_t * get_log_cond()
Definition: binlog.h:850
bool flush()
Definition: binlog.cc:6733
char * pos
Definition: do_ctype.cc:76
Stage_manager()
Definition: binlog.h:158
uint8 checksum_alg_reset
Definition: binlog.h:472
uint get_sync_period()
Definition: binlog.h:439
THD * fetch_queue_for(StageID stage)
Fetch the entire queue and empty it.
Definition: binlog.h:237
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:6601
void dec_prep_xids(THD *thd)
Decrement the prepared XID counter.
Definition: binlog.cc:6310
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:7303
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:2987
bool write_event_to_binlog_and_sync(Log_event *ev)
Definition: binlog.cc:7345
int32 get_size()
Definition: binlog.h:130
bool logged_data_file
Definition: binlog.h:894
void register_binlog_handler(THD *thd, bool trx)
Definition: binlog.cc:9169
int64_t int64
Definition: my_inttypes.h:67
void signal_update()
Definition: binlog.h:686
mysql_cond_t m_cond_preempt
Condition variable to indicate a follower started waiting for commit.
Definition: binlog.h:279
Definition: my_sys.h:360
This is the base class for verifying transaction boundaries in a replication event stream...
Definition: rpl_trx_boundary_parser.h:49
This is the abstract base class for binary log events.
Definition: log_event.h:517
#define mysql_mutex_init(K, M, A)
Definition: mysql_mutex.h:34
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:8153
uint charset_number
Definition: binlog.h:91
THD * thd
Definition: binlog.h:892
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:5483
int finish_commit(THD *thd)
Helper function executed when leaving ordered_commit.
Definition: binlog.cc:8457
Common base class for all row-containing log events.
Definition: log_event.h:2538
int32 get_prep_xids()
Definition: binlog.h:437
char log_file_name[FN_REFLEN]
Definition: binlog.h:304
bool mysql_show_binlog_events(THD *thd)
Execute a SHOW BINLOG EVENTS statement.
Definition: binlog.cc:3371
Definition: binlog.h:303
mysql_mutex_t LOCK_index
Definition: binlog.h:375
IO_CACHE crash_safe_index_file
Definition: binlog.h:390
void lock_binlog_end_pos()
Definition: binlog.h:866
unsigned int uint
Definition: uca-dump.cc:29
#define FN_REFLEN
Definition: my_io.h:82
LOG_INFO()
Definition: binlog.h:310
char purge_index_file_name[FN_REFLEN]
Definition: binlog.h:399
int(* mysql_cond_broadcast)(mysql_cond_t *that, const char *src_file, unsigned int src_line)
Definition: mysql_cond_service.h:51
enum_result
Definition: tc_log.h:70
Class for maintaining the commit stages for binary log group commit.
Definition: binlog.h:98
uint32_t uint32
Definition: my_inttypes.h:66
bool is_query_in_union(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6760
int prepare(THD *thd, bool all)
Log a prepare record of the transaction to the storage engines.
Definition: binlog.cc:7795
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:5419
Logical binlog file which wraps and hides the detail of lower layer storage implementation.
Definition: binlog.cc:249
Definition: binlog.h:330
PSI_mutex_key m_key_LOCK_sync_queue
Definition: binlog.h:354
mysql_cond_t m_cond_done
Condition variable to indicate that the commit was processed.
Definition: binlog.h:270
#define mysql_cond_init(K, C)
Definition: mysql_cond.h:35
std::pair< bool, bool > sync_binlog_file(bool force)
Call fsync() to sync the file to disk.
Definition: binlog.cc:8415
uint * sync_period_ptr
Definition: binlog.h:419
void close()
This is called on shutdown, after ha_panic.
Definition: binlog.cc:7783
PSI_file_key m_key_file_log_index_cache
The instrumentation key to use for opening a log index cache file.
Definition: binlog.h:372
void set_max_size(ulong max_size_arg)
Definition: binlog.cc:7589
ulonglong bytes_written
Definition: binlog.h:383
mysql_mutex_t LOCK_log
Definition: binlog.h:333
Definition: binlog.h:891
uint8_t uint8
Definition: my_inttypes.h:62
bool is_open()
Definition: binlog.h:467
char * name
Definition: binlog.h:334
int open_crash_safe_index_file()
Open a (new) crash safe index file.
Definition: binlog.cc:5668
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:190
Definition: binlog.h:330
std::pair< bool, THD * > pop_front()
Definition: binlog.cc:2251
Instrumentation helpers for mutexes.
bool write_event_to_binlog(Log_event *ev)
Definition: binlog.cc:7324
void unlock()
Definition: binlog.h:134
Common header for many mysys elements.
std::atomic< int32 > m_atomic_prep_xids
Definition: binlog.h:423
bool purge_master_logs(THD *thd, const char *to_log)
Execute a PURGE BINARY LOGS TO <log> command.
Definition: binlog.cc:3106
char db[NAME_LEN+1]
Definition: binlog.h:336
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:7140
my_off_t pos
Definition: binlog.h:306
IO_CACHE * get_index_file()
Definition: binlog.h:855
Stage_manager stage_manager
Manage the stages in ordered_commit.
Definition: binlog.h:455
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:3019
Instrumentation helpers for conditions.
int open_purge_index_file(bool destroy)
Definition: binlog.cc:5929
DBUG_TRACE
Definition: do_ctype.cc:46
int raw_get_current_log(LOG_INFO *linfo)
Definition: binlog.cc:5209
Represents a set of GTIDs.
Definition: rpl_gtid.h:1302
std::atomic< int32 > m_size
size of the queue
Definition: binlog.h:151
void report_binlog_write_error()
Definition: binlog.cc:7435
void purge()
The method executes logs purging routine.
Definition: binlog.cc:7016
void signal_done(THD *queue)
Definition: binlog.cc:2394
const char * generate_name(const char *log_name, const char *suffix, char *buff)
Definition: binlog.cc:3618
PSI_mutex_key m_key_LOCK_commit
The instrumentation key to use for @ LOCK_commit.
Definition: binlog.h:356
PSI_mutex_key m_key_LOCK_sync
The instrumentation key to use for @ LOCK_sync.
Definition: binlog.h:358
int ordered_commit(THD *thd, bool all, bool skip_commit=false)
Flush and commit the transaction.
Definition: binlog.cc:8667
mysql_mutex_t LOCK_xids
Definition: binlog.h:379
unsigned long my_off_t
Definition: my_inttypes.h:77
bool fatal
Definition: binlog.h:307
void init_pthread_objects()
Definition: binlog.cc:3441
bool write_dml_directly(THD *thd, const char *stmt, size_t stmt_len)
Write a dml into statement cache and then flush it into binlog.
Definition: binlog.cc:7270
int new_file_without_locking(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6343
Stores information to monitor a transaction during the different replication stages.
Definition: rpl_gtid.h:1161
bool is_transaction_empty(THD *thd)
Check if the the transaction is empty.
Definition: binlog.cc:2980
mysql_mutex_t LOCK_sync
Definition: binlog.h:377
void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param)
Definition: binlog.h:593
Definition: rpl_mi.h:86
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:7383
binary_log::enum_binlog_checksum_alg relay_log_checksum_alg
Definition: binlog.h:506
mysql_cond_t update_cond
Definition: binlog.h:380
my_off_t index_file_start_offset
Definition: binlog.h:305
int log_loaded_block(IO_CACHE *file)
Load data&#39;s io cache specific hook to be executed before a chunk of data is being read into the cache...
Definition: binlog.cc:3211
int close_crash_safe_index_file()
Close the crash safe index file.
Definition: binlog.cc:5700
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:5798
PSI_file_key m_key_file_log
The instrumentation key to use for opening the log file.
Definition: binlog.h:366
bool show_binlog_events(THD *thd, MYSQL_BIN_LOG *binary_log)
Definition: binlog.cc:3246
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
bool unsigned_flag
Definition: binlog.h:92
mysql_cond_t m_prep_xids_cond
Definition: binlog.h:422
void init(PSI_mutex_key key_LOCK_queue)
Definition: binlog.h:106
bool enroll_for(StageID stage, THD *first, mysql_mutex_t *stage_mutex)
Enroll a set of sessions for a stage.
Definition: binlog.cc:2276
bool trans_cannot_safely_rollback(const THD *thd)
This function checks if a transaction cannot be rolled back safely.
Definition: binlog.cc:3078
int64 query_id_t
Definition: binlog.h:69
bool change_stage(THD *thd, Stage_manager::StageID stage, THD *queue, mysql_mutex_t *leave, mysql_mutex_t *enter)
Enter a stage of the ordered commit procedure.
Definition: binlog.cc:8355
bool find_first_log_not_in_gtid_set(char *binlog_file_name, const Gtid_set *gtid_set, Gtid *first_gtid, const char **errmsg)
Find the oldest binary log that contains any GTID that is not in the given gtid set.
Definition: binlog.cc:4296
bool inited
Definition: binlog.h:337
void reset_bytes_written()
Definition: binlog.h:683
Definition: item_func.h:2848
const char * log_bin_index
Definition: binlog.cc:160
const char * get_name() const
Definition: binlog.h:848
int rotate_and_purge(THD *thd, bool force_rotate)
Execute a FLUSH LOGS statement.
Definition: binlog.cc:7060
uint file_id
Definition: binlog.h:413
ABI for instrumented mutexes.
char index_file_name[FN_REFLEN]
Definition: binlog.h:385
void destroy(T *ptr)
Definition: my_alloc.h:381
PSI_mutex_key m_key_COND_done
Definition: binlog.h:349
mysql_mutex_t LOCK_binlog_end_pos
Definition: binlog.h:378
Common #defines and includes for file and socket I/O.
PSI_mutex_key m_key_LOCK_commit_queue
Definition: binlog.h:351
void report_cache_write_error(THD *thd, bool is_transactional)
Definition: binlog.cc:5236
void add_bytes_written(ulonglong inc)
Definition: binlog.h:682
int register_purge_index_entry(const char *entry)
Definition: binlog.cc:5983
Either statement transaction or normal transaction - related thread-specific storage engine data...
Definition: transaction_info.h:408
my_off_t index_file_offset
Definition: binlog.h:305
int32_t int32
Definition: my_inttypes.h:65
bool reencrypt_logs()
Re-encrypt previous existent binary/relay logs as below.
Definition: binlog.cc:1680
bool flush_and_sync(const bool force=false)
Flush binlog cache and synchronize to disk.
Definition: binlog.cc:6737
void check_binlog_stmt_cache_size(THD *thd)
Checks if the BINLOG_STMT_CACHE_SIZE&#39;s value is greater than MAX_BINLOG_STMT_CACHE_SIZE.
Definition: binlog.cc:1146
MYSQL_BIN_LOG(uint *sync_period)
Definition: binlog.cc:3392
void lock()
Definition: binlog.h:133
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:53
int rollback(THD *thd, bool all)
Write a rollback record of the transaction to the binary log.
Definition: binlog.cc:2448
my_off_t last_pos_in_file
Definition: binlog.h:893
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event *event, bool is_transactional)
Definition: binlog.cc:6785
The namespace contains classes representing events that can occur in a replication stream...
#define MY_MUTEX_INIT_FAST
Definition: thr_mutex.h:66
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:44
int sync_purge_index_file()
Definition: binlog.cc:5972
std::pair< int, my_off_t > flush_thread_caches(THD *thd)
Flush caches for session.
Definition: binlog.cc:8121
void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log)
Helper function to handle flush or sync stage errors.
Definition: binlog.cc:8575
bool write_gtid(THD *thd, binlog_cache_data *cache_data, class Binlog_event_writer *writer)
Write the Gtid_log_event to the binary log (prior to writing the statement or transaction cache)...
Definition: binlog.cc:1454
int wait_for_update(const struct timespec *timeout)
Wait until we get a signal that the binary log has been updated.
Definition: binlog.cc:7458
my_off_t get_binlog_end_pos() const
Definition: binlog.h:861
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:3052
int entry_index
Definition: binlog.h:308
Definition: binlog.h:165
bool is_relay_log
Definition: binlog.h:470
PSI_file_key m_log_file_key
Instrumentation key to use for file io in log_file.
Definition: binlog.h:341
bool is_active(const char *log_file_name)
Check if we are writing/reading to the given log file.
Definition: binlog.cc:6295
PSI_mutex_key m_key_LOCK_index
The instrumentation key to use for @ LOCK_index.
Definition: binlog.h:345
mysql_mutex_t m_lock
Lock for protecting the queue.
Definition: binlog.h:154
char * get_log_fname()
Definition: binlog.h:847
int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads)
Remove logs from index file.
Definition: binlog.cc:5735
std::atomic< enum_log_state > atomic_log_state
Definition: binlog.h:646
int open(const char *opt_name)
Initialize and open the coordinator log.
Definition: binlog.h:651
~MYSQL_BIN_LOG()
Definition: binlog.cc:3416
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:172
static const int MAX_RETRIES_FOR_DELETE_RENAME_FAILURE
Definition: binlog.h:856
void cleanup()
Definition: binlog.cc:3420
uint next_file_id()
Definition: binlog.cc:7092
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:398
int set_purge_index_file_name(const char *base_file_name)
Definition: binlog.cc:5917
void unlock_index()
Definition: binlog.h:854
int encrypted_header_size
Definition: binlog.h:309
IO_CACHE index_file
Definition: binlog.h:384
int rotate(bool force_rotate, bool *check_purge)
The method executes rotation when LOCK_log is already acquired by the caller.
Definition: binlog.cc:6995
int open_binlog(const char *opt_name)
Definition: binlog.cc:7613
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:5285
int get_current_log(LOG_INFO *linfo, bool need_lock_log=true)
Definition: binlog.cc:5201
bool purge_master_logs_before_date(THD *thd, time_t purge_time)
Execute a PURGE BINARY LOGS BEFORE <date> command.
Definition: binlog.cc:3131
enum_log_state
Definition: binlog.h:330
bool write_error
Definition: binlog.h:337
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:4412
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:3067
bool is_inited_purge_index_file()
Definition: binlog.cc:5967
Auxiliary class to copy serialized events to the binary log and correct some of the fields that are n...
Definition: binlog.cc:1213
unsigned long ulong
Definition: my_inttypes.h:48
Definition: completion_hash.h:34
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:3662
Binlog_ofile * m_binlog_file
Definition: binlog.h:338
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:5158
Definition: binlog.h:86
bool opt_binlog_order_commits
Definition: binlog.cc:158
ulong length
Definition: binlog.h:89
mysql_mutex_t LOCK_commit
Definition: binlog.h:376
char * value
Definition: binlog.h:88
void update_thd_next_event_pos(THD *thd)
Definition: binlog.cc:6769
Definition: binlog.h:165
int flush_cache_to_file(my_off_t *flush_end_pos)
Flush the I/O cache to file.
Definition: binlog.cc:8402
Definition: binlog.h:100
void clear_preempt_status(THD *head)
The method ensures the follower&#39;s execution path can be preempted by the leader&#39;s thread...
Definition: binlog.cc:2403
static int not_killed
Definition: myisamchk.cc:1615
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
Class representing an incident, an occurance out of the ordinary, that happened on the master...
Definition: log_event.h:3298
PSI_mutex_key m_key_LOCK_flush_queue
Definition: binlog.h:353
int register_create_index_entry(const char *entry)
Definition: binlog.cc:5995
bool is_empty() const
Definition: binlog.h:112