MySQL  8.0.16
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 "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:
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 == NULL; }
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();
187  }
188 
189  /**
190  Enroll a set of sessions for a stage.
191 
192  This will queue the session thread for writing and flushing.
193 
194  If the thread being queued is assigned as stage leader, it will
195  return immediately.
196 
197  If wait_if_follower is true the thread is not the stage leader,
198  the thread will be wait for the queue to be processed by the
199  leader before it returns.
200  In DBUG-ON version the follower marks is preempt status as ready.
201 
202  @param stage Stage identifier for the queue to append to.
203  @param first Queue to append.
204  @param stage_mutex
205  Pointer to the currently held stage mutex, or NULL if
206  we're not in a stage.
207 
208  @retval true Thread is stage leader.
209  @retval false Thread was not stage leader and processing has been done.
210  */
211  bool enroll_for(StageID stage, THD *first, mysql_mutex_t *stage_mutex);
212 
213  std::pair<bool, THD *> pop_front(StageID stage) {
214  return m_queue[stage].pop_front();
215  }
216 
217 #ifndef DBUG_OFF
218  /**
219  The method ensures the follower's execution path can be preempted
220  by the leader's thread.
221  Preempt status of @c head follower is checked to engange the leader
222  into waiting when set.
223 
224  @param head THD* of a follower thread
225  */
226  void clear_preempt_status(THD *head);
227 #endif
228 
229  /**
230  Fetch the entire queue and empty it.
231 
232  @return Pointer to the first session of the queue.
233  */
235  DBUG_PRINT("debug", ("Fetching queue for stage %d", stage));
236  return m_queue[stage].fetch_and_empty();
237  }
238 
239  /**
240  Introduces a wait operation on the executing thread. The
241  waiting is done until the timeout elapses or count is
242  reached (whichever comes first).
243 
244  If count == 0, then the session will wait until the timeout
245  elapses. If timeout == 0, then there is no waiting.
246 
247  @param usec the number of microseconds to wait.
248  @param count wait for as many as count to join the queue the
249  session is waiting on
250  @param stage which stage queue size to compare count against.
251  */
252  void wait_count_or_timeout(ulong count, long usec, StageID stage);
253 
254  void signal_done(THD *queue);
255 
256  private:
257  /**
258  Queues for sessions.
259 
260  We need two queues:
261  - Waiting. Threads waiting to be processed
262  - Committing. Threads waiting to be committed.
263  */
265 
266  /** Condition variable to indicate that the commit was processed */
268 
269  /** Mutex used for the condition variable above */
271 #ifndef DBUG_OFF
272  /** Flag is set by Leader when it starts waiting for follower's all-clear */
274 
275  /** Condition variable to indicate a follower started waiting for commit */
277 #endif
278 };
279 
280 /* log info errors */
281 #define LOG_INFO_EOF -1
282 #define LOG_INFO_IO -2
283 #define LOG_INFO_INVALID -3
284 #define LOG_INFO_SEEK -4
285 #define LOG_INFO_MEM -6
286 #define LOG_INFO_FATAL -7
287 #define LOG_INFO_IN_USE -8
288 #define LOG_INFO_EMFILE -9
289 
290 /* bitmap to MYSQL_BIN_LOG::close() */
291 #define LOG_CLOSE_INDEX 1
292 #define LOG_CLOSE_TO_BE_OPENED 2
293 #define LOG_CLOSE_STOP_EVENT 4
294 
295 /*
296  Note that we destroy the lock mutex in the destructor here.
297  This means that object instances cannot be destroyed/go out of scope
298  until we have reset thd->current_linfo to NULL;
299  */
300 struct LOG_INFO {
304  bool fatal; // if the purge happens to give us a negative offset
305  int entry_index; // used in purge_logs(), calculatd in find_log_pos().
308  : index_file_offset(0),
310  pos(0),
311  fatal(0),
312  entry_index(0),
314  memset(log_file_name, 0, FN_REFLEN);
315  }
316 };
317 
318 /*
319  TODO use mmap instead of IO_CACHE for binlog
320  (mmap+fsync is two times faster than write+fsync)
321 */
322 class MYSQL_BIN_LOG : public TC_LOG {
323  public:
324  class Binlog_ofile;
325 
326  private:
328 
329  /* LOCK_log is inited by init_pthread_objects() */
331  char *name;
333  char db[NAME_LEN + 1];
336 
337  /** Instrumentation key to use for file io in @c log_file */
339  /** The instrumentation key to use for @ LOCK_log. */
341  /** The instrumentation key to use for @ LOCK_index. */
343  /** The instrumentation key to use for @ LOCK_binlog_end_pos. */
345 
347 
352  /** The instrumentation key to use for @ LOCK_commit. */
354  /** The instrumentation key to use for @ LOCK_sync. */
356  /** The instrumentation key to use for @ LOCK_xids. */
358  /** The instrumentation key to use for @ update_cond. */
360  /** The instrumentation key to use for @ prep_xids_cond. */
362  /** The instrumentation key to use for opening the log file. */
364  /** The instrumentation key to use for opening the log index file. */
366  /** The instrumentation key to use for opening a log cache file. */
368  /** The instrumentation key to use for opening a log index cache file. */
370 
371  /* POSIX thread objects are inited by init_pthread_objects() */
378 
379  std::atomic<my_off_t> atomic_binlog_end_pos;
383  /*
384  crash_safe_index_file is temp file used for guaranteeing
385  index file crash safe when master server restarts.
386  */
389  /*
390  purge_file is a temp file used in purge_logs so that the index file
391  can be updated before deleting files from disk, yielding better crash
392  recovery. It is created on demand the first time purge_logs is called
393  and then reused for subsequent calls. It is cleaned up in cleanup().
394  */
397  /*
398  The max size before rotation (usable only if log_type == LOG_BIN: binary
399  logs and relay logs).
400  For a binlog, max_size should be max_binlog_size.
401  For a relay log, it should be max_relay_log_size if this is non-zero,
402  max_binlog_size otherwise.
403  max_size is set in init(), and dynamically changed (when one does SET
404  GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
405  fix_max_relay_log_size).
406  */
408 
409  // current file sequence number for load data infile binary logging
411  uint open_count; // For replication
412 
413  /* pointer to the sync period variable, for binlog this will be
414  sync_binlog_period, for relay log this will be
415  sync_relay_log_period
416  */
419 
421  std::atomic<int32> m_atomic_prep_xids{0};
422 
423  /**
424  Increment the prepared XID counter.
425  */
426  void inc_prep_xids(THD *thd);
427 
428  /**
429  Decrement the prepared XID counter.
430 
431  Signal m_prep_xids_cond if the counter reaches zero.
432  */
433  void dec_prep_xids(THD *thd);
434 
435  int32 get_prep_xids() { return m_atomic_prep_xids; }
436 
437  inline uint get_sync_period() { return *sync_period_ptr; }
438 
439  public:
440  /*
441  This is used to start writing to a new log file. The difference from
442  new_file() is locking. new_file_without_locking() does not acquire
443  LOCK_log.
444  */
446  Format_description_log_event *extra_description_event);
447 
448  private:
449  int new_file_impl(bool need_lock,
450  Format_description_log_event *extra_description_event);
451 
452  /** Manage the stages in ordered_commit. */
454 
455  bool open(PSI_file_key log_file_key, const char *log_name,
456  const char *new_name, uint32 new_index_number);
457  bool init_and_set_log_file_name(const char *log_name, const char *new_name,
458  uint32 new_index_number);
459  int generate_new_name(char *new_name, const char *log_name,
460  uint32 new_index_number = 0);
461 
462  public:
463  const char *generate_name(const char *log_name, const char *suffix,
464  char *buff);
465  bool is_open() { return atomic_log_state != LOG_CLOSED; }
466 
467  /* This is relay log */
469 
470  uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
471  /*
472  Holds the last seen in Relay-Log FD's checksum alg value.
473  The initial value comes from the slave's local FD that heads
474  the very first Relay-Log file. In the following the value may change
475  with each received master's FD_m.
476  Besides to be used in verification events that IO thread receives
477  (except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd),
478  the value specifies if/how to compute checksum for slave's local events
479  and the first fake Rotate (R_f^1) coming from the master.
480  R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
481 
482  Legends for the checksum related comments:
483 
484  FD - Format-Description event,
485  R - Rotate event
486  R_f - the fake Rotate event
487  E - an arbirary event
488 
489  The underscore indexes for any event
490  `_s' indicates the event is generated by Slave
491  `_m' - by Master
492 
493  Two special underscore indexes of FD:
494  FD_q - Format Description event for queuing (relay-logging)
495  FD_e - Format Description event for executing (relay-logging)
496 
497  Upper indexes:
498  E^n - n:th event is a sequence
499 
500  RL - Relay Log
501  (A) - checksum algorithm descriptor value
502  FD.(A) - the value of (A) in FD
503  */
505 
506  MYSQL_BIN_LOG(uint *sync_period);
507  ~MYSQL_BIN_LOG();
508 
510  PSI_mutex_key key_LOCK_index, PSI_mutex_key key_LOCK_commit,
511  PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_done,
512  PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_log,
513  PSI_mutex_key key_LOCK_binlog_end_pos, PSI_mutex_key key_LOCK_sync,
514  PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_xids,
515  PSI_cond_key key_COND_done, PSI_cond_key key_update_cond,
516  PSI_cond_key key_prep_xids_cond, PSI_file_key key_file_log,
517  PSI_file_key key_file_log_index, PSI_file_key key_file_log_cache,
518  PSI_file_key key_file_log_index_cache) {
519  m_key_COND_done = key_COND_done;
520 
521  m_key_LOCK_commit_queue = key_LOCK_commit_queue;
522  m_key_LOCK_done = key_LOCK_done;
523  m_key_LOCK_flush_queue = key_LOCK_flush_queue;
524  m_key_LOCK_sync_queue = key_LOCK_sync_queue;
525 
526  m_key_LOCK_index = key_LOCK_index;
527  m_key_LOCK_log = key_LOCK_log;
528  m_key_LOCK_binlog_end_pos = key_LOCK_binlog_end_pos;
529  m_key_LOCK_commit = key_LOCK_commit;
530  m_key_LOCK_sync = key_LOCK_sync;
531  m_key_LOCK_xids = key_LOCK_xids;
532  m_key_update_cond = key_update_cond;
533  m_key_prep_xids_cond = key_prep_xids_cond;
534  m_key_file_log = key_file_log;
535  m_key_file_log_index = key_file_log_index;
536  m_key_file_log_cache = key_file_log_cache;
537  m_key_file_log_index_cache = key_file_log_index_cache;
538  }
539 
540  public:
541  /** Manage the MTS dependency tracking */
543 
544  /**
545  Find the oldest binary log that contains any GTID that
546  is not in the given gtid set.
547 
548  @param[out] binlog_file_name the file name of oldest binary log found
549  @param[in] gtid_set the given gtid set
550  @param[out] first_gtid the first GTID information from the binary log
551  file returned at binlog_file_name
552  @param[out] errmsg the error message outputted, which is left untouched
553  if the function returns false
554  @return false on success, true on error.
555  */
556  bool find_first_log_not_in_gtid_set(char *binlog_file_name,
557  const Gtid_set *gtid_set,
558  Gtid *first_gtid, const char **errmsg);
559 
560  /**
561  Reads the set of all GTIDs in the binary/relay log, and the set
562  of all lost GTIDs in the binary log, and stores each set in
563  respective argument.
564 
565  @param gtid_set Will be filled with all GTIDs in this binary/relay
566  log.
567  @param lost_groups Will be filled with all GTIDs in the
568  Previous_gtids_log_event of the first binary log that has a
569  Previous_gtids_log_event. This is requested to binary logs but not
570  to relay logs.
571  @param verify_checksum If true, checksums will be checked.
572  @param need_lock If true, LOCK_log, LOCK_index, and
573  global_sid_lock->wrlock are acquired; otherwise they are asserted
574  to be taken already.
575  @param [out] trx_parser This will be used to return the actual
576  relaylog transaction parser state because of the possibility
577  of partial transactions.
578  @param [out] partial_trx If a transaction was left incomplete
579  on the relaylog, its GTID information should be returned to be
580  used in the case of the rest of the transaction be added to the
581  relaylog.
582  @param is_server_starting True if the server is starting.
583  @return false on success, true on error.
584  */
585  bool init_gtid_sets(Gtid_set *gtid_set, Gtid_set *lost_groups,
586  bool verify_checksum, bool need_lock,
587  Transaction_boundary_parser *trx_parser,
588  Gtid_monitoring_info *partial_trx,
589  bool is_server_starting = false);
590 
591  void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param) {
593  previous_gtid_set_relaylog = previous_gtid_set_param;
594  }
595  /**
596  If the thread owns a GTID, this function generates an empty
597  transaction and releases ownership of the GTID.
598 
599  - If the binary log is disabled for this thread, the GTID is
600  inserted directly into the mysql.gtid_executed table and the
601  GTID is included in @@global.gtid_executed. (This only happens
602  for DDL, since DML will save the GTID into table and release
603  ownership inside ha_commit_trans.)
604 
605  - If the binary log is enabled for this thread, an empty
606  transaction consisting of GTID, BEGIN, COMMIT is written to the
607  binary log, the GTID is included in @@global.gtid_executed, and
608  the GTID is added to the mysql.gtid_executed table on the next
609  binlog rotation.
610 
611  This function must be called by any committing statement (COMMIT,
612  implicitly committing statements, or Xid_log_event), after the
613  statement has completed execution, regardless of whether the
614  statement updated the database.
615 
616  This logic ensures that an empty transaction is generated for the
617  following cases:
618 
619  - Explicit empty transaction:
620  SET GTID_NEXT = 'UUID:NUMBER'; BEGIN; COMMIT;
621 
622  - Transaction or DDL that gets completely filtered out in the
623  slave thread.
624 
625  @param thd The committing thread
626 
627  @retval 0 Success
628  @retval nonzero Error
629  */
630  int gtid_end_transaction(THD *thd);
631  /**
632  Re-encrypt previous existent binary/relay logs as below.
633  Starting from the next to last entry on the index file, iterating
634  down to the first one:
635  - If the file is encrypted, re-encrypt it. Otherwise, skip it.
636  - If failed to open the file, report an error.
637 
638  @retval False Success
639  @retval True Error
640  */
641  bool reencrypt_logs();
642 
643  private:
644  std::atomic<enum_log_state> atomic_log_state{LOG_CLOSED};
645 
646  /* The previous gtid set in relay log. */
648 
649  int open(const char *opt_name) { return open_binlog(opt_name); }
650  bool change_stage(THD *thd, Stage_manager::StageID stage, THD *queue,
651  mysql_mutex_t *leave, mysql_mutex_t *enter);
652  std::pair<int, my_off_t> flush_thread_caches(THD *thd);
653  int flush_cache_to_file(my_off_t *flush_end_pos);
654  int finish_commit(THD *thd);
655  std::pair<bool, bool> sync_binlog_file(bool force);
657  void process_after_commit_stage_queue(THD *thd, THD *first);
658  int process_flush_stage_queue(my_off_t *total_bytes_var, bool *rotate_var,
659  THD **out_queue_var);
660  int ordered_commit(THD *thd, bool all, bool skip_commit = false);
661  void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log);
663  class Binlog_event_writer *writer);
665 
666  public:
667  int open_binlog(const char *opt_name);
668  void close();
669  enum_result commit(THD *thd, bool all);
670  int rollback(THD *thd, bool all);
671  bool truncate_relaylog_file(Master_info *mi, my_off_t valid_pos);
672  int prepare(THD *thd, bool all);
673 #if defined(MYSQL_SERVER)
674 
675  void update_thd_next_event_pos(THD *thd);
677  bool is_transactional);
678 
679 #endif /* defined(MYSQL_SERVER) */
682  void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock);
683  void set_max_size(ulong max_size_arg);
684  void signal_update() {
685  DBUG_ENTER("MYSQL_BIN_LOG::signal_update");
688  }
689 
690  void update_binlog_end_pos(bool need_lock = true);
691  void update_binlog_end_pos(const char *file, my_off_t pos);
692 
693  int wait_for_update(const struct timespec *timeout);
694 
695  public:
696  void init_pthread_objects();
697  void cleanup();
698  /**
699  Create a new binary log.
700  @param log_name Name of binlog
701  @param new_name Name of binlog, too. todo: what's the difference
702  between new_name and log_name?
703  @param max_size_arg The size at which this binlog will be rotated.
704  @param null_created_arg If false, and a Format_description_log_event
705  is written, then the Format_description_log_event will have the
706  timestamp 0. Otherwise, it the timestamp will be the time when the
707  event was written to the log.
708  @param need_lock_index If true, LOCK_index is acquired; otherwise
709  LOCK_index must be taken by the caller.
710  @param need_sid_lock If true, the read lock on global_sid_lock
711  will be acquired. Otherwise, the caller must hold the read lock
712  on global_sid_lock.
713  @param extra_description_event The master's FDE to be written by the I/O
714  thread while creating a new relay log file. This should be NULL for
715  binary log files.
716  @param new_index_number The binary log file index number to start from
717  after the RESET MASTER TO command is called.
718  */
719  bool open_binlog(const char *log_name, const char *new_name,
720  ulong max_size_arg, bool null_created_arg,
721  bool need_lock_index, bool need_sid_lock,
722  Format_description_log_event *extra_description_event,
723  uint32 new_index_number = 0);
724  bool open_index_file(const char *index_file_name_arg, const char *log_name,
725  bool need_lock_index);
726  /* Use this to start writing a new log file */
727  int new_file(Format_description_log_event *extra_description_event);
728 
729  bool write_event(Log_event *event_info);
730  bool write_cache(THD *thd, class binlog_cache_data *cache_data,
731  class Binlog_event_writer *writer);
732  /**
733  Assign automatic generated GTIDs for all commit group threads in the flush
734  stage having gtid_next.type == AUTOMATIC_GTID.
735 
736  @param first_seen The first thread seen entering the flush stage.
737  @return Returns false if succeeds, otherwise true is returned.
738  */
739  bool assign_automatic_gtids_to_flush_group(THD *first_seen);
740  bool write_gtid(THD *thd, binlog_cache_data *cache_data,
741  class Binlog_event_writer *writer);
742 
743  /**
744  Write a dml into statement cache and then flush it into binlog. It writes
745  Gtid_log_event and BEGIN, COMMIT automatically.
746 
747  It is aimed to handle cases of "background" logging where a statement is
748  logged indirectly, like "DELETE FROM a_memory_table". So don't use it on
749  any normal statement.
750 
751  @param[in] thd the THD object of current thread.
752  @param[in] stmt the DELETE statement.
753  @param[in] stmt_len the length of DELETE statement.
754 
755  @return Returns false if succeeds, otherwise true is returned.
756  */
757  bool write_dml_directly(THD *thd, const char *stmt, size_t stmt_len);
758 
759  void report_cache_write_error(THD *thd, bool is_transactional);
760  bool check_write_error(const THD *thd);
761  bool write_incident(THD *thd, bool need_lock_log, const char *err_msg,
762  bool do_flush_and_sync = true);
763  bool write_incident(Incident_log_event *ev, THD *thd, bool need_lock_log,
764  const char *err_msg, bool do_flush_and_sync = true);
768  void start_union_events(THD *thd, query_id_t query_id_param);
769  void stop_union_events(THD *thd);
770  bool is_query_in_union(THD *thd, query_id_t query_id_param);
771 
772  bool write_buffer(const char *buf, uint len, Master_info *mi);
773  bool write_event(Log_event *ev, Master_info *mi);
774 
775  private:
777 
778  public:
779  void make_log_name(char *buf, const char *log_ident);
780  bool is_active(const char *log_file_name);
781  int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads);
782  int rotate(bool force_rotate, bool *check_purge);
783  void purge();
784  int rotate_and_purge(THD *thd, bool force_rotate);
785 
786  bool flush();
787  /**
788  Flush binlog cache and synchronize to disk.
789 
790  This function flushes events in binlog cache to binary log file,
791  it will do synchronizing according to the setting of system
792  variable 'sync_binlog'. If file is synchronized, @c synced will
793  be set to 1, otherwise 0.
794 
795  @param[in] force if true, ignores the 'sync_binlog' and synchronizes the
796  file.
797 
798  @retval 0 Success
799  @retval other Failure
800  */
801  bool flush_and_sync(const bool force = false);
802  int purge_logs(const char *to_log, bool included, bool need_lock_index,
803  bool need_update_threads, ulonglong *decrease_log_space,
804  bool auto_purge);
805  int purge_logs_before_date(time_t purge_time, bool auto_purge);
806  int set_crash_safe_index_file_name(const char *base_file_name);
809  int add_log_to_index(uchar *log_file_name, size_t name_len,
810  bool need_lock_index);
811  int move_crash_safe_index_file_to_index_file(bool need_lock_index);
812  int set_purge_index_file_name(const char *base_file_name);
813  int open_purge_index_file(bool destroy);
816  int sync_purge_index_file();
817  int register_purge_index_entry(const char *entry);
818  int register_create_index_entry(const char *entry);
819  int purge_index_entry(THD *thd, ulonglong *decrease_log_space,
820  bool need_lock_index);
821  bool reset_logs(THD *thd, bool delete_only = false);
822  void close(uint exiting, bool need_lock_log, bool need_lock_index);
823 
824  // iterating through the log index file
825  int find_log_pos(LOG_INFO *linfo, const char *log_name, bool need_lock_index);
826  int find_next_log(LOG_INFO *linfo, bool need_lock_index);
827  int find_next_relay_log(char log_name[FN_REFLEN + 1]);
828  int get_current_log(LOG_INFO *linfo, bool need_lock_log = true);
829  int raw_get_current_log(LOG_INFO *linfo);
830  uint next_file_id();
831  /**
832  Retrieves the contents of the index file associated with this log object
833  into an `std::list<std::string>` object. The order held by the index file is
834  kept.
835 
836  @param need_lock_index whether or not the lock over the index file should be
837  acquired inside the function.
838 
839  @return a pair: a function status code; a list of `std::string` objects with
840  the content of the log index file.
841  */
842  std::pair<int, std::list<std::string>> get_log_index(
843  bool need_lock_index = true);
844  inline char *get_index_fname() { return index_file_name; }
845  inline char *get_log_fname() { return log_file_name; }
846  inline char *get_name() { return name; }
847  inline mysql_mutex_t *get_log_lock() { return &LOCK_log; }
848  inline mysql_cond_t *get_log_cond() { return &update_cond; }
850 
853  inline IO_CACHE *get_index_file() { return &index_file; }
854  inline uint32 get_open_count() { return open_count; }
856  /*
857  It is called by the threads (e.g. dump thread, applier thread) which want
858  to read hot log without LOCK_log protection.
859  */
862  return atomic_binlog_end_pos;
863  }
867 
868  /**
869  Deep copy global_sid_map and gtid_executed.
870  Both operations are done under LOCK_commit and global_sid_lock
871  protection.
872 
873  @param[out] sid_map The Sid_map to which global_sid_map will
874  be copied.
875  @param[out] gtid_set The Gtid_set to which gtid_executed will
876  be copied.
877 
878  @return the operation status
879  @retval 0 OK
880  @retval !=0 Error
881  */
882  int get_gtid_executed(Sid_map *sid_map, Gtid_set *gtid_set);
883 
884  /*
885  True while rotating binlog, which is caused by logging Incident_log_event.
886  */
888 };
889 
894 };
895 
897 
898 /**
899  Check if the the transaction is empty.
900 
901  @param thd The client thread that executed the current statement.
902 
903  @retval true No changes found in any storage engine
904  @retval false Otherwise.
905 
906 **/
907 bool is_transaction_empty(THD *thd);
908 /**
909  Check if the transaction has no rw flag set for any of the storage engines.
910 
911  @param thd The client thread that executed the current statement.
912  @param trx_scope The transaction scope to look into.
913 
914  @retval the number of engines which have actual changes.
915  */
917 
918 /**
919  Check if at least one of transacaction and statement binlog caches contains
920  an empty transaction, other one is empty or contains an empty transaction,
921  which has two binlog events "BEGIN" and "COMMIT".
922 
923  @param thd The client thread that executed the current statement.
924 
925  @retval true At least one of transacaction and statement binlog caches
926  contains an empty transaction, other one is empty or
927  contains an empty transaction.
928  @retval false Otherwise.
929 */
931 bool trans_has_updated_trans_table(const THD *thd);
933 bool ending_trans(THD *thd, const bool all);
934 bool ending_single_stmt_trans(THD *thd, const bool all);
935 bool trans_cannot_safely_rollback(const THD *thd);
936 bool stmt_cannot_safely_rollback(const THD *thd);
937 
938 int log_loaded_block(IO_CACHE *file);
939 
940 bool purge_master_logs(THD *thd, const char *to_log);
941 bool purge_master_logs_before_date(THD *thd, time_t purge_time);
943 bool mysql_show_binlog_events(THD *thd);
944 void check_binlog_cache_size(THD *thd);
946 bool binlog_enabled();
947 void register_binlog_handler(THD *thd, bool trx);
948 int query_error_code(const THD *thd, bool not_killed);
949 
950 extern const char *log_bin_index;
951 extern const char *log_bin_basename;
952 extern bool opt_binlog_order_commits;
953 extern ulong rpl_read_size;
954 /**
955  Turns a relative log binary log path into a full path, based on the
956  opt_bin_logname or opt_relay_logname. Also trims the cr-lf at the
957  end of the full_path before return to avoid any server startup
958  problem on windows.
959 
960  @param from The log name we want to make into an absolute path.
961  @param to The buffer where to put the results of the
962  normalization.
963  @param is_relay_log Switch that makes is used inside to choose which
964  option (opt_bin_logname or opt_relay_logname) to
965  use when calculating the base path.
966 
967  @returns true if a problem occurs, false otherwise.
968  */
969 
970 bool normalize_binlog_name(char *to, const char *from, bool is_relay_log);
971 
972 #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:3589
bool init_and_set_log_file_name(const char *log_name, const char *new_name, uint32 new_index_number)
Definition: binlog.cc:3629
enum_result commit(THD *thd, bool all)
Commit the transaction in the transaction coordinator.
Definition: binlog.cc:7838
unsigned long long int ulonglong
Definition: my_inttypes.h:69
PSI_mutex_key m_key_LOCK_log
The instrumentation key to use for @ LOCK_log.
Definition: binlog.h:340
Instrumentation helpers for mutexes.
PSI_mutex_key m_key_LOCK_done
Definition: binlog.h:349
unsigned char uchar
Definition: my_inttypes.h:49
bool append(THD *first)
Append a linked list of threads to the queue.
Definition: binlog.cc:2217
PSI_file_key m_key_file_log_cache
The instrumentation key to use for opening a log cache file.
Definition: binlog.h:367
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:160
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:359
void unlock_binlog_end_pos()
Definition: binlog.h:866
IO_CACHE purge_index_file
Definition: binlog.h:395
t pos
Definition: dbug_analyze.cc:148
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:849
StageID
Constants for queues for different stages.
Definition: binlog.h:165
void stop_union_events(THD *thd)
Definition: binlog.cc:6740
Definition: binlog.h:165
ssize_t count
Definition: memcached.c:386
Gtid_set * previous_gtid_set_relaylog
Definition: binlog.h:647
mysql_mutex_t m_lock_done
Mutex used for the condition variable above.
Definition: binlog.h:270
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:7734
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:2372
void process_after_commit_stage_queue(THD *thd, THD *first)
Process after commit for a sequence of sessions.
Definition: binlog.cc:8281
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:2995
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
longlong int64
Definition: my_inttypes.h:71
void update_binlog_end_pos(bool need_lock=true)
Definition: binlog.cc:9078
uint sync_counter
Definition: binlog.h:418
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:1400
Definition: binlog.h:322
#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:4994
Transaction Coordinator Log.
Definition: tc_log.h:54
bool log_delayed
Definition: binlog.h:893
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:6266
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:6813
Mutex_queue m_queue[STAGE_COUNTER]
Queues for sessions.
Definition: binlog.h:264
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 occuring 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:509
void process_commit_stage_queue(THD *thd, THD *queue)
Commit a sequence of sessions.
Definition: binlog.cc:8208
bool open_index_file(const char *index_file_name_arg, const char *log_name, bool need_lock_index)
Definition: binlog.cc:3708
unsigned char uint8
Definition: my_inttypes.h:51
void start_union_events(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6732
bool leader_await_preempt_status
Flag is set by Leader when it starts waiting for follower&#39;s all-clear.
Definition: binlog.h:273
int set_crash_safe_index_file_name(const char *base_file_name)
Set the name of crash safe index file.
Definition: binlog.cc:5626
PSI_cond_key m_key_prep_xids_cond
The instrumentation key to use for @ prep_xids_cond.
Definition: binlog.h:361
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:365
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
enum_trx_scope
Definition: transaction_info.h:53
char * get_index_fname()
Definition: binlog.h:844
void deinit()
Definition: binlog.h:183
Performance schema instrumentation interface.
THD * fetch_and_empty()
Fetch the entire queue for a stage.
Definition: binlog.cc:2352
int new_file(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6318
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:5435
static QUEUE queue
Definition: myisampack.cc:206
ulong max_size
Definition: binlog.h:407
bool check_write_error(const THD *thd)
Definition: binlog.cc:5210
Item_result type
Definition: binlog.h:90
#define NAME_LEN
Definition: mysql_com.h:65
DBUG_VOID_RETURN
Definition: dbug_analyze.cc:151
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:344
bool stmt_cannot_safely_rollback(const THD *thd)
This function checks if current statement cannot be rollded back safely.
Definition: binlog.cc:3086
Mutex_queue()
Definition: binlog.h:104
void inc(Shards &shards, size_t id)
Increment the counter.
Definition: ut0counter.h:248
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:5368
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:357
ulong rpl_read_size
Definition: binlog.cc:163
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:3028
char log_file_name[FN_REFLEN]
Definition: binlog.h:332
void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock)
Definition: binlog.cc:7558
Transaction_dependency_tracker m_dependency_tracker
Manage the MTS dependency tracking.
Definition: binlog.h:542
bool write_buffer(const char *buf, uint len, Master_info *mi)
Definition: binlog.cc:6695
#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:1609
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:847
Functions related to handling of plugins and other dynamically loaded libraries.
bool is_rotating_caused_by_incident
Definition: binlog.h:887
int purge_index_entry(THD *thd, ulonglong *decrease_log_space, bool need_lock_index)
Definition: binlog.cc:5982
char * get_name()
Definition: binlog.h:846
int get_gtid_executed(Sid_map *sid_map, Gtid_set *gtid_set)
Deep copy global_sid_map and gtid_executed.
Definition: binlog.cc:7085
std::pair< bool, THD * > pop_front(StageID stage)
Definition: binlog.h:213
std::atomic< my_off_t > atomic_binlog_end_pos
Definition: binlog.h:379
void deinit()
Definition: binlog.h:110
char crash_safe_index_file_name[FN_REFLEN]
Definition: binlog.h:388
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:110
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:41
void lock_index()
Definition: binlog.h:851
mysql_mutex_t * get_binlog_end_pos_lock()
Definition: binlog.h:864
#define DBUG_ASSERT(A)
Definition: my_dbug.h:128
Performance schema instrumentation interface.
Definition: binlog.h:327
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:6150
int close_purge_index_file()
Definition: binlog.cc:5934
void inc_prep_xids(THD *thd)
Increment the prepared XID counter.
Definition: binlog.cc:6281
int query_error_code(const THD *thd, bool not_killed)
Definition: binlog.cc:3138
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:6347
mysql_cond_t * get_log_cond()
Definition: binlog.h:848
bool flush()
Definition: binlog.cc:6718
#define DBUG_ENTER(a)
Definition: my_dbug.h:80
Stage_manager()
Definition: binlog.h:158
uint8 checksum_alg_reset
Definition: binlog.h:470
uint get_sync_period()
Definition: binlog.h:437
THD * fetch_queue_for(StageID stage)
Fetch the entire queue and empty it.
Definition: binlog.h:234
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:6585
void dec_prep_xids(THD *thd)
Decrement the prepared XID counter.
Definition: binlog.cc:6293
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:7288
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:2982
bool write_event_to_binlog_and_sync(Log_event *ev)
Definition: binlog.cc:7331
int32 get_size()
Definition: binlog.h:130
bool logged_data_file
Definition: binlog.h:893
void register_binlog_handler(THD *thd, bool trx)
Definition: binlog.cc:9153
void signal_update()
Definition: binlog.h:684
mysql_cond_t m_cond_preempt
Condition variable to indicate a follower started waiting for commit.
Definition: binlog.h:276
Definition: my_sys.h:354
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:8140
uint open_count
Definition: binlog.h:411
uint charset_number
Definition: binlog.h:91
THD * thd
Definition: binlog.h:891
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:5477
int finish_commit(THD *thd)
Helper function executed when leaving ordered_commit.
Definition: binlog.cc:8443
Common base class for all row-containing log events.
Definition: log_event.h:2544
int32 get_prep_xids()
Definition: binlog.h:435
char log_file_name[FN_REFLEN]
Definition: binlog.h:301
bool mysql_show_binlog_events(THD *thd)
Execute a SHOW BINLOG EVENTS statement.
Definition: binlog.cc:3360
Definition: binlog.h:300
mysql_mutex_t LOCK_index
Definition: binlog.h:372
unsigned int len
Definition: dbug_analyze.cc:216
IO_CACHE crash_safe_index_file
Definition: binlog.h:387
void lock_binlog_end_pos()
Definition: binlog.h:865
unsigned int uint
Definition: uca-dump.cc:29
#define FN_REFLEN
Definition: my_io.h:82
LOG_INFO()
Definition: binlog.h:307
char purge_index_file_name[FN_REFLEN]
Definition: binlog.h:396
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
bool is_query_in_union(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6745
int prepare(THD *thd, bool all)
Log a prepare record of the transaction to the storage engines.
Definition: binlog.cc:7785
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:5414
Logical binlog file which wraps and hides the detail of lower layer storage implementation.
Definition: binlog.cc:248
Definition: binlog.h:327
PSI_mutex_key m_key_LOCK_sync_queue
Definition: binlog.h:351
mysql_cond_t m_cond_done
Condition variable to indicate that the commit was processed.
Definition: binlog.h:267
#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:8401
uint * sync_period_ptr
Definition: binlog.h:417
void close()
This is called on shutdown, after ha_panic.
Definition: binlog.cc:7773
PSI_file_key m_key_file_log_index_cache
The instrumentation key to use for opening a log index cache file.
Definition: binlog.h:369
void set_max_size(ulong max_size_arg)
Definition: binlog.cc:7578
ulonglong bytes_written
Definition: binlog.h:380
mysql_mutex_t LOCK_log
Definition: binlog.h:330
Definition: binlog.h:890
bool is_open()
Definition: binlog.h:465
char * name
Definition: binlog.h:331
int open_crash_safe_index_file()
Open a (new) crash safe index file.
Definition: binlog.cc:5650
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:189
Definition: binlog.h:327
std::pair< bool, THD * > pop_front()
Definition: binlog.cc:2252
Instrumentation helpers for mutexes.
bool write_event_to_binlog(Log_event *ev)
Definition: binlog.cc:7310
void unlock()
Definition: binlog.h:134
Common header for many mysys elements.
std::atomic< int32 > m_atomic_prep_xids
Definition: binlog.h:421
bool purge_master_logs(THD *thd, const char *to_log)
Execute a PURGE BINARY LOGS TO <log> command.
Definition: binlog.cc:3101
char db[NAME_LEN+1]
Definition: binlog.h:333
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:7125
my_off_t pos
Definition: binlog.h:303
IO_CACHE * get_index_file()
Definition: binlog.h:853
Stage_manager stage_manager
Manage the stages in ordered_commit.
Definition: binlog.h:453
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:3014
Instrumentation helpers for conditions.
int open_purge_index_file(bool destroy)
Definition: binlog.cc:5911
int raw_get_current_log(LOG_INFO *linfo)
Definition: binlog.cc:5202
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:7421
void purge()
The method executes logs purging routine.
Definition: binlog.cc:7001
void signal_done(THD *queue)
Definition: binlog.cc:2395
const char * generate_name(const char *log_name, const char *suffix, char *buff)
Definition: binlog.cc:3610
PSI_mutex_key m_key_LOCK_commit
The instrumentation key to use for @ LOCK_commit.
Definition: binlog.h:353
PSI_mutex_key m_key_LOCK_sync
The instrumentation key to use for @ LOCK_sync.
Definition: binlog.h:355
int ordered_commit(THD *thd, bool all, bool skip_commit=false)
Flush and commit the transaction.
Definition: binlog.cc:8653
mysql_mutex_t LOCK_xids
Definition: binlog.h:376
unsigned long my_off_t
Definition: my_inttypes.h:88
bool fatal
Definition: binlog.h:304
void init_pthread_objects()
Definition: binlog.cc:3433
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:7255
int new_file_without_locking(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6327
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:2975
mysql_mutex_t LOCK_sync
Definition: binlog.h:374
void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param)
Definition: binlog.h:591
Definition: rpl_mi.h:85
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:7369
binary_log::enum_binlog_checksum_alg relay_log_checksum_alg
Definition: binlog.h:504
mysql_cond_t update_cond
Definition: binlog.h:377
my_off_t index_file_start_offset
Definition: binlog.h:302
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:3206
int close_crash_safe_index_file()
Close the crash safe index file.
Definition: binlog.cc:5682
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:5780
PSI_file_key m_key_file_log
The instrumentation key to use for opening the log file.
Definition: binlog.h:363
bool show_binlog_events(THD *thd, MYSQL_BIN_LOG *binary_log)
Definition: binlog.cc:3241
uint32 get_open_count()
Definition: binlog.h:854
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:420
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:2277
bool trans_cannot_safely_rollback(const THD *thd)
This function checks if a transaction cannot be rolled back safely.
Definition: binlog.cc:3073
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:8341
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:4289
bool inited
Definition: binlog.h:334
void reset_bytes_written()
Definition: binlog.h:681
Definition: item_func.h:2797
const char * log_bin_index
Definition: binlog.cc:159
int rotate_and_purge(THD *thd, bool force_rotate)
Execute a FLUSH LOGS statement.
Definition: binlog.cc:7045
uint file_id
Definition: binlog.h:410
ABI for instrumented mutexes.
char index_file_name[FN_REFLEN]
Definition: binlog.h:382
void destroy(T *ptr)
Definition: my_alloc.h:373
PSI_mutex_key m_key_COND_done
Definition: binlog.h:346
mysql_mutex_t LOCK_binlog_end_pos
Definition: binlog.h:375
Common #defines and includes for file and socket I/O.
PSI_mutex_key m_key_LOCK_commit_queue
Definition: binlog.h:348
void report_cache_write_error(THD *thd, bool is_transactional)
Definition: binlog.cc:5229
void add_bytes_written(ulonglong inc)
Definition: binlog.h:680
int register_purge_index_entry(const char *entry)
Definition: binlog.cc:5965
Either statement transaction or normal transaction - related thread-specific storage engine data...
Definition: transaction_info.h:412
my_off_t index_file_offset
Definition: binlog.h:302
bool reencrypt_logs()
Re-encrypt previous existent binary/relay logs as below.
Definition: binlog.cc:1681
bool flush_and_sync(const bool force=false)
Flush binlog cache and synchronize to disk.
Definition: binlog.cc:6722
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:3381
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:2449
my_off_t last_pos_in_file
Definition: binlog.h:892
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event *event, bool is_transactional)
Definition: binlog.cc:6770
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:5954
std::pair< int, my_off_t > flush_thread_caches(THD *thd)
Flush caches for session.
Definition: binlog.cc:8108
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:8561
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:1455
int wait_for_update(const struct timespec *timeout)
Wait until we get a signal that the binary log has been updated.
Definition: binlog.cc:7444
my_off_t get_binlog_end_pos() const
Definition: binlog.h:860
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:3047
int entry_index
Definition: binlog.h:305
Definition: binlog.h:165
bool is_relay_log
Definition: binlog.h:468
PSI_file_key m_log_file_key
Instrumentation key to use for file io in log_file.
Definition: binlog.h:338
bool is_active(const char *log_file_name)
Check if we are writing/reading to the given log file.
Definition: binlog.cc:6277
PSI_mutex_key m_key_LOCK_index
The instrumentation key to use for @ LOCK_index.
Definition: binlog.h:342
mysql_mutex_t m_lock
Lock for protecting the queue.
Definition: binlog.h:154
char * get_log_fname()
Definition: binlog.h:845
int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads)
Remove logs from index file.
Definition: binlog.cc:5717
std::atomic< enum_log_state > atomic_log_state
Definition: binlog.h:644
int open(const char *opt_name)
Initialize and open the coordinator log.
Definition: binlog.h:649
~MYSQL_BIN_LOG()
Definition: binlog.cc:3406
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:144
static const int MAX_RETRIES_FOR_DELETE_RENAME_FAILURE
Definition: binlog.h:855
void cleanup()
Definition: binlog.cc:3410
uint next_file_id()
Definition: binlog.cc:7077
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:5899
void unlock_index()
Definition: binlog.h:852
int encrypted_header_size
Definition: binlog.h:306
IO_CACHE index_file
Definition: binlog.h:381
int rotate(bool force_rotate, bool *check_purge)
The method executes rotation when LOCK_log is already acquired by the caller.
Definition: binlog.cc:6980
int open_binlog(const char *opt_name)
Definition: binlog.cc:7603
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:5280
int get_current_log(LOG_INFO *linfo, bool need_lock_log=true)
Definition: binlog.cc:5194
bool purge_master_logs_before_date(THD *thd, time_t purge_time)
Execute a PURGE BINARY LOGS BEFORE <date> command.
Definition: binlog.cc:3126
enum_log_state
Definition: binlog.h:327
bool write_error
Definition: binlog.h:334
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:4405
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:3062
bool is_inited_purge_index_file()
Definition: binlog.cc:5949
Auxiliary class to copy serialized events to the binary log and correct some of the fields that are n...
Definition: binlog.cc:1214
unsigned long ulong
Definition: my_inttypes.h:46
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:3654
Binlog_ofile * m_binlog_file
Definition: binlog.h:335
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:5152
Definition: binlog.h:86
bool opt_binlog_order_commits
Definition: binlog.cc:157
ulong length
Definition: binlog.h:89
mysql_mutex_t LOCK_commit
Definition: binlog.h:373
char * value
Definition: binlog.h:88
void update_thd_next_event_pos(THD *thd)
Definition: binlog.cc:6754
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:8388
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:2404
static int not_killed
Definition: myisamchk.cc:1616
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776
Class representing an incident, an occurance out of the ordinary, that happened on the master...
Definition: log_event.h:3304
PSI_mutex_key m_key_LOCK_flush_queue
Definition: binlog.h:350
int register_create_index_entry(const char *entry)
Definition: binlog.cc:5977
bool is_empty() const
Definition: binlog.h:112