MySQL 8.3.0
Source Code Documentation
binlog.h
Go to the documentation of this file.
1#ifndef BINLOG_H_INCLUDED
2/* Copyright (c) 2010, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#define BINLOG_H_INCLUDED
25
26#include <string.h>
27#include <sys/types.h>
28#include <time.h>
29#include <atomic>
30#include <utility>
31
32#include "my_dbug.h"
33#include "my_inttypes.h"
34#include "my_io.h"
35#include "my_sharedlib.h"
36#include "my_sys.h"
37#include "mysql/binlog/event/binlog_event.h" // enum_binlog_checksum_alg
47#include "mysql_com.h" // Item_result
48#include "sql/binlog_reader.h" // Binlog_file_reader
51#include "sql/tc_log.h" // TC_LOG
52#include "sql/transaction_info.h" // Transaction_ctx
53#include "thr_mutex.h"
54
57class Gtid_set;
58class Ha_trx_info;
60class Log_event;
61class Master_info;
62class Relay_log_info;
63class Rows_log_event;
64class Tsid_map;
65class THD;
66class Transaction_boundary_parser;
68class user_var_entry;
70
71struct Gtid;
72
74
75/*
76 Maximum unique log filename extension.
77 Note: setting to 0x7FFFFFFF due to atol windows
78 overflow/truncate.
79 */
80#define MAX_LOG_UNIQUE_FN_EXT 0x7FFFFFFF
81
82/*
83 Maximum allowed unique log filename extension for
84 RESET BINARY LOGS AND GTIDS command - 2 Billion
85 */
86#define MAX_ALLOWED_FN_EXT_RESET_MASTER 2000000000
87
90 char *value;
91 ulong length;
95};
96
97/* log info errors */
98#define LOG_INFO_EOF -1
99#define LOG_INFO_IO -2
100#define LOG_INFO_INVALID -3
101#define LOG_INFO_SEEK -4
102#define LOG_INFO_MEM -6
103#define LOG_INFO_FATAL -7
104#define LOG_INFO_IN_USE -8
105#define LOG_INFO_EMFILE -9
106#define LOG_INFO_BACKUP_LOCK -10
107#define LOG_INFO_NOT_IN_USE -11
108
109/* bitmap to MYSQL_BIN_LOG::close() */
110#define LOG_CLOSE_INDEX 1
111#define LOG_CLOSE_TO_BE_OPENED 2
112#define LOG_CLOSE_STOP_EVENT 4
113
114struct LOG_INFO {
118 bool fatal; // if the purge happens to give us a negative offset
119 int entry_index; // used in purge_logs(), calculatd in find_log_pos().
125 pos(0),
126 fatal(false),
127 entry_index(0),
129 thread_id(0) {
130 memset(log_file_name, 0, FN_REFLEN);
131 }
132};
133
134/*
135 TODO use mmap instead of IO_CACHE for binlog
136 (mmap+fsync is two times faster than write+fsync)
137*/
138class MYSQL_BIN_LOG : public TC_LOG {
139 public:
140 class Binlog_ofile;
141
142 private:
144
145 /* LOCK_log is inited by init_pthread_objects() */
147 char *name;
149 char db[NAME_LEN + 1];
152
153 /** Instrumentation key to use for file io in @c log_file */
155 /** The instrumentation key to use for @ LOCK_log. */
157 /** The instrumentation key to use for @ LOCK_index. */
159 /** The instrumentation key to use for @ LOCK_binlog_end_pos. */
161 /** The PFS instrumentation key for @ LOCK_commit_queue. */
163 /** The PFS instrumentation key for @ LOCK_after_commit_queue. */
165 /** The PFS instrumentation key for @ LOCK_done. */
167 /** The PFS instrumentation key for @ LOCK_flush_queue. */
169 /** The PFS instrumentation key for @ LOCK_sync_queue. */
171 /** The PFS instrumentation key for @ LOCK_wait_for_group_turn. */
173 /** The PFS instrumentation key for @ COND_done. */
175 /** The PFS instrumentation key for @ COND_flush_queue. */
177 /** The instrumentation key to use for @ LOCK_commit. */
179 /** The instrumentation key to use for @ LOCK_after_commit. */
181 /** The instrumentation key to use for @ LOCK_sync. */
183 /** The instrumentation key to use for @ LOCK_xids. */
185 /** The instrumentation key to use for @ m_key_LOCK_log_info. */
187 /** The instrumentation key to use for @ update_cond. */
189 /** The instrumentation key to use for @ prep_xids_cond. */
191 /** The PFS instrumentation key for @ COND_wait_for_group_turn. */
193 /** The instrumentation key to use for opening the log file. */
195 /** The instrumentation key to use for opening the log index file. */
197 /** The instrumentation key to use for opening a log cache file. */
199 /** The instrumentation key to use for opening a log index cache file. */
201
202 /* POSIX thread objects are inited by init_pthread_objects() */
210
211 std::atomic<my_off_t> atomic_binlog_end_pos;
215 /*
216 crash_safe_index_file is temp file used for guaranteeing
217 index file crash safe when master server restarts.
218 */
221 /*
222 purge_file is a temp file used in purge_logs so that the index file
223 can be updated before deleting files from disk, yielding better crash
224 recovery. It is created on demand the first time purge_logs is called
225 and then reused for subsequent calls. It is cleaned up in cleanup().
226 */
229 /*
230 The max size before rotation (usable only if log_type == LOG_BIN: binary
231 logs and relay logs).
232 For a binlog, max_size should be max_binlog_size.
233 For a relay log, it should be max_relay_log_size if this is non-zero,
234 max_binlog_size otherwise.
235 max_size is set in init(), and dynamically changed (when one does SET
236 GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
237 fix_max_relay_log_size).
238 */
239 ulong max_size;
240
241 // current file sequence number for load data infile binary logging
243
244 /* pointer to the sync period variable, for binlog this will be
245 sync_binlog_period, for relay log this will be
246 sync_relay_log_period
247 */
250
252 std::atomic<int32> m_atomic_prep_xids{0};
253
254 /**
255 Increment the prepared XID counter.
256 */
257 void inc_prep_xids(THD *thd);
258
259 /**
260 Decrement the prepared XID counter.
261
262 Signal m_prep_xids_cond if the counter reaches zero.
263 */
264 void dec_prep_xids(THD *thd);
265
267
268 inline uint get_sync_period() { return *sync_period_ptr; }
269
270 public:
271 /*
272 This is used to start writing to a new log file. The difference from
273 new_file() is locking. new_file_without_locking() does not acquire
274 LOCK_log.
275 */
277 Format_description_log_event *extra_description_event);
278
279 /**
280 Checks whether binlog caches are disabled (binlog does not cache data) or
281 empty in case binloggging is enabled in the current call to this function.
282 This function may be safely called in case binlogging is disabled.
283 @retval true binlog local caches are empty or disabled and binlogging is
284 enabled
285 @retval false binlog local caches are enabled and contain data or binlogging
286 is disabled
287 */
289
290 private:
291 int new_file_impl(bool need_lock,
292 Format_description_log_event *extra_description_event);
293
294 bool open(PSI_file_key log_file_key, const char *log_name,
295 const char *new_name, uint32 new_index_number);
296 bool init_and_set_log_file_name(const char *log_name, const char *new_name,
297 uint32 new_index_number);
298 int generate_new_name(char *new_name, const char *log_name,
299 uint32 new_index_number = 0);
300 /**
301 * Read binary log stream header and Format_desc event from
302 * binlog_file_reader. Check for LOG_EVENT_BINLOG_IN_USE_F flag.
303 * @param[in] binlog_file_reader a Binlog_file_reader
304 * @return true - LOG_EVENT_BINLOG_IN_USE_F is set
305 * false - LOG_EVENT_BINLOG_IN_USE_F is not set or an error occurred
306 * while reading log events
307 */
308 bool read_binlog_in_use_flag(Binlog_file_reader &binlog_file_reader);
309
310 protected:
311 /**
312 @brief Notifies waiting threads that binary log has been updated
313 */
314 void signal_update();
315
316 public:
317 const char *generate_name(const char *log_name, const char *suffix,
318 char *buff);
319 bool is_open() const { return atomic_log_state != LOG_CLOSED; }
320
321 /* This is relay log */
323
324 uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
325 /*
326 Holds the last seen in Relay-Log FD's checksum alg value.
327 The initial value comes from the slave's local FD that heads
328 the very first Relay-Log file. In the following the value may change
329 with each received master's FD_m.
330 Besides to be used in verification events that IO thread receives
331 (except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd),
332 the value specifies if/how to compute checksum for slave's local events
333 and the first fake Rotate (R_f^1) coming from the master.
334 R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
335
336 Legends for the checksum related comments:
337
338 FD - Format-Description event,
339 R - Rotate event
340 R_f - The fake Rotate event
341 E - An arbitrary event
342
343 The underscore indexes for any event
344 `_s' - Indicates the event is generated by the Replica
345 `_m' - By the Source
346
347 Two special underscore indexes of FD:
348 FD_q - Format Description event for queuing (relay-logging)
349 FD_e - Format Description event for executing (relay-logging)
350
351 Upper indexes:
352 E^n - n:th event is a sequence
353
354 RL - Relay Log
355 (A) - checksum algorithm descriptor value
356 FD.(A) - the value of (A) in FD
357 */
359
360 MYSQL_BIN_LOG(uint *sync_period, bool relay_log = false);
361 ~MYSQL_BIN_LOG() override;
362
364 PSI_mutex_key key_LOCK_index, PSI_mutex_key key_LOCK_commit,
365 PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_after_commit,
366 PSI_mutex_key key_LOCK_after_commit_queue, PSI_mutex_key key_LOCK_done,
367 PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_log,
368 PSI_mutex_key key_LOCK_binlog_end_pos, PSI_mutex_key key_LOCK_sync,
369 PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_xids,
370 PSI_mutex_key key_LOCK_log_info,
371 PSI_mutex_key key_LOCK_wait_for_group_turn, PSI_cond_key key_COND_done,
372 PSI_cond_key key_COND_flush_queue, PSI_cond_key key_update_cond,
373 PSI_cond_key key_prep_xids_cond,
374 PSI_cond_key key_COND_wait_for_group_turn, PSI_file_key key_file_log,
375 PSI_file_key key_file_log_index, PSI_file_key key_file_log_cache,
376 PSI_file_key key_file_log_index_cache) {
377 m_key_COND_done = key_COND_done;
378 m_key_COND_flush_queue = key_COND_flush_queue;
379
380 m_key_LOCK_commit_queue = key_LOCK_commit_queue;
381 m_key_LOCK_after_commit_queue = key_LOCK_after_commit_queue;
382 m_key_LOCK_done = key_LOCK_done;
383 m_key_LOCK_flush_queue = key_LOCK_flush_queue;
384 m_key_LOCK_sync_queue = key_LOCK_sync_queue;
385
386 m_key_LOCK_index = key_LOCK_index;
387 m_key_LOCK_log = key_LOCK_log;
388 m_key_LOCK_binlog_end_pos = key_LOCK_binlog_end_pos;
389 m_key_LOCK_commit = key_LOCK_commit;
390 m_key_LOCK_after_commit = key_LOCK_after_commit;
391 m_key_LOCK_sync = key_LOCK_sync;
392 m_key_LOCK_xids = key_LOCK_xids;
393 m_key_LOCK_log_info = key_LOCK_log_info;
394 m_key_update_cond = key_update_cond;
395 m_key_prep_xids_cond = key_prep_xids_cond;
396 m_key_file_log = key_file_log;
397 m_key_file_log_index = key_file_log_index;
398 m_key_file_log_cache = key_file_log_cache;
399 m_key_file_log_index_cache = key_file_log_index_cache;
400
401 m_key_LOCK_wait_for_group_turn = key_LOCK_wait_for_group_turn;
402 m_key_COND_wait_for_group_turn = key_COND_wait_for_group_turn;
403 }
404
405 public:
406 /** Manage the MTS dependency tracking */
408
409 /**
410 Find the oldest binary log referenced by the index file
411
412 @param[out] binlog_file_name the file name of oldest log found
413 @param[out] errmsg the error message outputted, which is left untouched
414 if the function returns false
415 @return false on success, true on error.
416 */
417 bool find_first_log(std::string &binlog_file_name, std::string &errmsg);
418
419 /**
420 Find the oldest binary log that contains any GTID that
421 is not in the given gtid set.
422
423 @param[out] binlog_file_name the file name of oldest binary log found
424 @param[in] gtid_set the given gtid set
425 @param[out] first_gtid the first GTID information from the binary log
426 file returned at binlog_file_name
427 @param[out] errmsg the error message outputted, which is left untouched
428 if the function returns false
429 @return false on success, true on error.
430 */
431 bool find_first_log_not_in_gtid_set(char *binlog_file_name,
432 const Gtid_set *gtid_set,
433 Gtid *first_gtid, std::string &errmsg);
434
435 /**
436 Reads the set of all GTIDs in the binary/relay log, and the set
437 of all lost GTIDs in the binary log, and stores each set in
438 respective argument.
439
440 @param all_gtids Will be filled with all GTIDs in this binary/relay
441 log.
442 @param lost_gtids Will be filled with all GTIDs in the
443 Previous_gtids_log_event of the first binary log that has a
444 Previous_gtids_log_event. This is requested to binary logs but not
445 to relay logs.
446 @param verify_checksum If true, checksums will be checked.
447 @param need_lock If true, LOCK_log, LOCK_index, and
448 global_tsid_lock->wrlock are acquired; otherwise they are asserted
449 to be taken already.
450 @param [out] trx_parser This will be used to return the actual
451 relaylog transaction parser state because of the possibility
452 of partial transactions.
453 @param [out] partial_trx If a transaction was left incomplete
454 on the relaylog, its GTID information should be returned to be
455 used in the case of the rest of the transaction be added to the
456 relaylog.
457 @param is_server_starting True if the server is starting.
458 @return false on success, true on error.
459 */
460 bool init_gtid_sets(
461 Gtid_set *all_gtids, Gtid_set *lost_gtids, bool verify_checksum,
462 bool need_lock,
464 Gtid_monitoring_info *partial_trx, bool is_server_starting = false);
465
466 void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param) {
467 assert(is_relay_log);
468 previous_gtid_set_relaylog = previous_gtid_set_param;
469 }
470 /**
471 If the thread owns a GTID, this function generates an empty
472 transaction and releases ownership of the GTID.
473
474 - If the binary log is disabled for this thread, the GTID is
475 inserted directly into the mysql.gtid_executed table and the
476 GTID is included in @@global.gtid_executed. (This only happens
477 for DDL, since DML will save the GTID into table and release
478 ownership inside ha_commit_trans.)
479
480 - If the binary log is enabled for this thread, an empty
481 transaction consisting of GTID, BEGIN, COMMIT is written to the
482 binary log, the GTID is included in @@global.gtid_executed, and
483 the GTID is added to the mysql.gtid_executed table on the next
484 binlog rotation.
485
486 This function must be called by any committing statement (COMMIT,
487 implicitly committing statements, or Xid_log_event), after the
488 statement has completed execution, regardless of whether the
489 statement updated the database.
490
491 This logic ensures that an empty transaction is generated for the
492 following cases:
493
494 - Explicit empty transaction:
495 SET GTID_NEXT = 'UUID:NUMBER'; BEGIN; COMMIT;
496
497 - Transaction or DDL that gets completely filtered out in the
498 slave thread.
499
500 @param thd The committing thread
501
502 @retval 0 Success
503 @retval nonzero Error
504 */
505 int gtid_end_transaction(THD *thd);
506 /**
507 Re-encrypt previous existent binary/relay logs as below.
508 Starting from the next to last entry on the index file, iterating
509 down to the first one:
510 - If the file is encrypted, re-encrypt it. Otherwise, skip it.
511 - If failed to open the file, report an error.
512
513 @retval False Success
514 @retval True Error
515 */
516 bool reencrypt_logs();
517
518 private:
519 std::atomic<enum_log_state> atomic_log_state{LOG_CLOSED};
520
521 /* The previous gtid set in relay log. */
523
524 int open(const char *opt_name) override { return open_binlog(opt_name); }
525
526 /**
527 Enter a stage of the ordered commit procedure.
528
529 Entering is stage is done by:
530
531 - Atomically entering a queue of THD objects (which is just one for
532 the first phase).
533
534 - If the queue was empty, the thread is the leader for that stage
535 and it should process the entire queue for that stage.
536
537 - If the queue was not empty, the thread is a follower and can go
538 waiting for the commit to finish.
539
540 The function will lock the stage mutex if the calling thread was designated
541 leader for the phase.
542
543 @param[in] thd Session structure
544 @param[in] stage The stage to enter
545 @param[in] queue Thread queue for the stage
546 @param[in] leave_mutex Mutex that will be released when changing stage
547 @param[in] enter_mutex Mutex that will be taken when changing stage
548
549 @retval true In case this thread did not become leader, the function
550 returns true *after* the leader has completed the commit
551 on its behalf, so the thread should continue doing the
552 thread-local processing after the commit
553 (i.e. call finish_commit).
554
555 @retval false The thread is the leader for the stage and should do
556 the processing.
557 */
559 mysql_mutex_t *leave_mutex, mysql_mutex_t *enter_mutex);
560 std::pair<int, my_off_t> flush_thread_caches(THD *thd);
561 int flush_cache_to_file(my_off_t *flush_end_pos);
562 int finish_commit(THD *thd);
563 std::pair<bool, bool> sync_binlog_file(bool force);
565 void process_after_commit_stage_queue(THD *thd, THD *first);
566
567 /**
568 Set thread variables used while flushing a transaction.
569
570 @param[in] thd thread whose variables need to be set
571 @param[in] all This is @c true if this is a real transaction commit, and
572 @c false otherwise.
573 @param[in] skip_commit
574 This is @c true if the call to @c ha_commit_low should
575 be skipped (it is handled by the caller somehow) and @c
576 false otherwise (the normal case).
577 */
578 void init_thd_variables(THD *thd, bool all, bool skip_commit);
579
580 /**
581 Fetch and empty BINLOG_FLUSH_STAGE and COMMIT_ORDER_FLUSH_STAGE flush queues
582 and flush transactions to the disk, and unblock threads executing slave
583 preserve commit order.
584
585 @param[in] check_and_skip_flush_logs
586 if false then flush prepared records of transactions to the log
587 of storage engine.
588 if true then flush prepared records of transactions to the log
589 of storage engine only if COMMIT_ORDER_FLUSH_STAGE queue is
590 non-empty.
591
592 @return Pointer to the first session of the BINLOG_FLUSH_STAGE stage queue.
593 */
595 const bool check_and_skip_flush_logs = false);
596
597 /**
598 Execute the flush stage.
599
600 @param[out] total_bytes_var Pointer to variable that will be set to total
601 number of bytes flushed, or NULL.
602
603 @param[out] rotate_var Pointer to variable that will be set to true if
604 binlog rotation should be performed after releasing
605 locks. If rotate is not necessary, the variable will
606 not be touched.
607
608 @param[out] out_queue_var Pointer to the sessions queue in flush stage.
609
610 @return Error code on error, zero on success
611 */
612 int process_flush_stage_queue(my_off_t *total_bytes_var, bool *rotate_var,
613 THD **out_queue_var);
614
615 /**
616 Flush and commit the transaction.
617
618 This will execute an ordered flush and commit of all outstanding
619 transactions and is the main function for the binary log group
620 commit logic. The function performs the ordered commit in four stages.
621
622 Pre-condition: transactions should have called ha_prepare_low, using
623 HA_IGNORE_DURABILITY, before entering here.
624
625 Stage#0 implements replica-preserve-commit-order for applier threads that
626 write the binary log. i.e. it forces threads to enter the queue in the
627 correct commit order.
628
629 The stage#1 flushes the caches to the binary log and under
630 LOCK_log and marks all threads that were flushed as not pending.
631
632 The stage#2 syncs the binary log for all transactions in the group.
633
634 The stage#3 executes under LOCK_commit and commits all transactions in
635 order.
636
637 There are three queues of THD objects: one for each stage.
638 The Commit_order_manager maintains it own queue and its own order for the
639 commit. So Stage#0 doesn't maintain separate StageID.
640
641 When a transaction enters a stage, it adds itself to a queue. If the queue
642 was empty so that this becomes the first transaction in the queue, the
643 thread is the *leader* of the queue. Otherwise it is a *follower*. The
644 leader will do all work for all threads in the queue, and the followers
645 will wait until the last stage is finished.
646
647 Stage 0 (SLAVE COMMIT ORDER):
648 1. If replica-preserve-commit-order and is slave applier worker thread, then
649 waits until its turn to commit i.e. till it is on the top of the queue.
650 2. When it reaches top of the queue, it signals next worker in the commit
651 order queue to awake.
652
653 Stage 1 (FLUSH):
654 1. Sync the engines (ha_flush_logs), since they prepared using non-durable
655 settings (HA_IGNORE_DURABILITY).
656 2. Generate GTIDs for all transactions in the queue.
657 3. Write the session caches for all transactions in the queue to the binary
658 log.
659 4. Increment the counter of prepared XIDs.
660
661 Stage 2 (SYNC):
662 1. If it is time to sync, based on the sync_binlog option, sync the binlog.
663 2. If sync_binlog==1, signal dump threads that they can read up to the
664 position after the last transaction in the queue
665
666 Stage 3 (COMMIT):
667 This is performed by each thread separately, if binlog_order_commits=0.
668 Otherwise by the leader does it for all threads.
669 1. Call the after_sync hook.
670 2. update the max_committed counter in the dependency_tracker
671 3. call ha_commit_low
672 4. Call the after_commit hook
673 5. Update gtids
674 6. Decrement the counter of prepared transactions
675
676 If the binary log needs to be rotated, it is done after this. During
677 rotation, it takes a lock that prevents new commit groups from executing the
678 flush stage, and waits until the counter of prepared transactions becomes 0,
679 before it creates the new file.
680
681 @param[in] thd Session to commit transaction for
682 @param[in] all This is @c true if this is a real transaction commit, and
683 @c false otherwise.
684 @param[in] skip_commit
685 This is @c true if the call to @c ha_commit_low should
686 be skipped and @c false otherwise (the normal case).
687 */
688 int ordered_commit(THD *thd, bool all, bool skip_commit = false);
689 void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log,
690 const char *message);
692 class Binlog_event_writer *writer);
694
695 public:
696 int open_binlog(const char *opt_name);
697 void close() override;
698 enum_result commit(THD *thd, bool all) override;
699 int rollback(THD *thd, bool all) override;
700 bool truncate_relaylog_file(Master_info *mi, my_off_t valid_pos);
701 int prepare(THD *thd, bool all) override;
702#if defined(MYSQL_SERVER)
703
706 bool is_transactional);
707
708#endif /* defined(MYSQL_SERVER) */
711 void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock);
712 void set_max_size(ulong max_size_arg);
713
714 void update_binlog_end_pos(bool need_lock = true);
715 void update_binlog_end_pos(const char *file, my_off_t pos);
716
717 /**
718 Wait until we get a signal that the binary log has been updated.
719
720 NOTES
721 @param[in] timeout a pointer to a timespec;
722 NULL means to wait w/o timeout.
723 @retval 0 if got signalled on update
724 @retval non-0 if wait timeout elapsed
725 @note
726 LOCK_binlog_end_pos must be owned before calling this function, may be
727 temporarily released while the thread is waiting and is reacquired before
728 returning from the function
729 */
730 int wait_for_update(const std::chrono::nanoseconds &timeout);
731
732 /**
733 Wait until we get a signal that the binary log has been updated.
734 @retval 0 success
735 @note
736 LOCK_binlog_end_pos must be owned before calling this function, may be
737 temporarily released while the thread is waiting and is reacquired before
738 returning from the function
739 */
740 int wait_for_update();
741
742 public:
744 void cleanup();
745 /**
746 Create a new binary log.
747 @param log_name Name of binlog
748 @param new_name Name of binlog, too. todo: what's the difference
749 between new_name and log_name?
750 @param max_size_arg The size at which this binlog will be rotated.
751 @param null_created_arg If false, and a Format_description_log_event
752 is written, then the Format_description_log_event will have the
753 timestamp 0. Otherwise, it the timestamp will be the time when the
754 event was written to the log.
755 @param need_lock_index If true, LOCK_index is acquired; otherwise
756 LOCK_index must be taken by the caller.
757 @param need_tsid_lock If true, the read lock on global_tsid_lock
758 will be acquired. Otherwise, the caller must hold the read lock
759 on global_tsid_lock.
760 @param extra_description_event The master's FDE to be written by the I/O
761 thread while creating a new relay log file. This should be NULL for
762 binary log files.
763 @param new_index_number The binary log file index number to start from
764 after the RESET BINARY LOGS AND GTIDS command is called.
765 */
766 bool open_binlog(const char *log_name, const char *new_name,
767 ulong max_size_arg, bool null_created_arg,
768 bool need_lock_index, bool need_tsid_lock,
769 Format_description_log_event *extra_description_event,
770 uint32 new_index_number = 0);
771 bool open_index_file(const char *index_file_name_arg, const char *log_name,
772 bool need_lock_index);
773 /* Use this to start writing a new log file */
774 int new_file(Format_description_log_event *extra_description_event);
775
776 bool write_event(Log_event *event_info);
777 bool write_cache(THD *thd, class binlog_cache_data *cache_data,
778 class Binlog_event_writer *writer);
779 /**
780 Assign automatic generated GTIDs for all commit group threads in the flush
781 stage having gtid_next.type == AUTOMATIC_GTID.
782
783 @param first_seen The first thread seen entering the flush stage.
784 @return Returns false if succeeds, otherwise true is returned.
785 */
787 bool write_transaction(THD *thd, binlog_cache_data *cache_data,
788 Binlog_event_writer *writer);
789
790 /**
791 Write a dml into statement cache and then flush it into binlog. It writes
792 Gtid_log_event and BEGIN, COMMIT automatically.
793
794 It is aimed to handle cases of "background" logging where a statement is
795 logged indirectly, like "TRUNCATE TABLE a_memory_table". So don't use it on
796 any normal statement.
797
798 @param[in] thd the THD object of current thread.
799 @param[in] stmt the DML statement.
800 @param[in] stmt_len the length of the DML statement.
801 @param[in] sql_command the type of SQL command.
802
803 @return Returns false if succeeds, otherwise true is returned.
804 */
805 bool write_stmt_directly(THD *thd, const char *stmt, size_t stmt_len,
806 enum enum_sql_command sql_command);
807
808 void report_cache_write_error(THD *thd, bool is_transactional);
809 bool check_write_error(const THD *thd);
810 bool write_incident(THD *thd, bool need_lock_log, const char *err_msg,
811 bool do_flush_and_sync = true);
812 bool write_incident(Incident_log_event *ev, THD *thd, bool need_lock_log,
813 const char *err_msg, bool do_flush_and_sync = true);
817 void start_union_events(THD *thd, query_id_t query_id_param);
818 void stop_union_events(THD *thd);
819 bool is_query_in_union(THD *thd, query_id_t query_id_param);
820
821 bool write_buffer(const char *buf, uint len, Master_info *mi);
822 bool write_event(Log_event *ev, Master_info *mi);
823
824 /**
825 Logging XA commit/rollback of a prepared transaction.
826
827 It fills in the appropriate event in the statement cache whenever xid
828 state is marked with is_binlogged() flag that indicates the prepared
829 part of the transaction must've been logged.
830
831 About early returns from the function:
832 - ONE_PHASE option to XA-COMMIT is handled to skip writing XA-commit
833 event now.
834 - check is for the read-only XA that is not to be logged.
835
836 @param thd THD handle
837 @return error code, 0 success
838 */
839 int write_xa_to_cache(THD *thd);
840
841 private:
843 /**
844 * Truncte log file and clear LOG_EVENT_BINLOG_IN_USE_F when update is set.
845 * @param[in] log_name name of the log file to be trunacted
846 * @param[in] valid_pos position at which to truncate the log file
847 * @param[in] binlog_size length of the log file before truncated
848 * @param[in] update should the LOG_EVENT_BINLOG_IN_USE_F flag be cleared
849 * true - set LOG_EVENT_BINLOG_IN_USE_F to 0
850 * false - do not modify LOG_EVENT_BINLOG_IN_USE_F flag
851 * @return true - sucess, false - failed
852 */
853 bool truncate_update_log_file(const char *log_name, my_off_t valid_pos,
854 my_off_t binlog_size, bool update);
855
856 public:
857 void make_log_name(char *buf, const char *log_ident);
858 bool is_active(const char *log_file_name) const;
859 int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads);
860 int rotate(bool force_rotate, bool *check_purge);
861
862 /**
863 @brief This function runs automatic purge if the conditions to meet
864 automatic purge are met. Such conditions are: log is open, instance is not
865 locked for backup and automatic purge is enabled.
866
867 If all conditions are met, purge is done according to the configuration
868 of the purge window.
869 */
870 void auto_purge();
871
872 /**
873 @brief This member function is to be called at server startup. It checks if
874 purge can be done and does if it can.
875 */
877 int rotate_and_purge(THD *thd, bool force_rotate);
878
879 bool flush();
880 /**
881 Flush binlog cache and synchronize to disk.
882
883 This function flushes events in binlog cache to binary log file,
884 it will do synchronizing according to the setting of system
885 variable 'sync_binlog'. If file is synchronized, @c synced will
886 be set to 1, otherwise 0.
887
888 @param[in] force if true, ignores the 'sync_binlog' and synchronizes the
889 file.
890
891 @retval 0 Success
892 @retval other Failure
893 */
894 bool flush_and_sync(const bool force = false);
895 int purge_logs(const char *to_log, bool included, bool need_lock_index,
896 bool need_update_threads, ulonglong *decrease_log_space,
897 bool auto_purge);
898 int purge_logs_before_date(time_t purge_time, bool auto_purge);
899 int set_crash_safe_index_file_name(const char *base_file_name);
902 int add_log_to_index(uchar *log_file_name, size_t name_len,
903 bool need_lock_index);
904 int move_crash_safe_index_file_to_index_file(bool need_lock_index);
905 int set_purge_index_file_name(const char *base_file_name);
910 int register_purge_index_entry(const char *entry);
911 int register_create_index_entry(const char *entry);
912 int purge_index_entry(THD *thd, ulonglong *decrease_log_space,
913 bool need_lock_index);
914 bool reset_logs(THD *thd, bool delete_only = false);
915 void close(uint exiting, bool need_lock_log, bool need_lock_index);
916
917 // iterating through the log index file
918 int find_log_pos(LOG_INFO *linfo, const char *log_name, bool need_lock_index);
919 int find_next_log(LOG_INFO *linfo, bool need_lock_index);
920 int find_next_relay_log(char log_name[FN_REFLEN + 1]);
921 int get_current_log(LOG_INFO *linfo, bool need_lock_log = true);
922 int raw_get_current_log(LOG_INFO *linfo);
923 uint next_file_id();
924 /**
925 Retrieves the contents of the index file associated with this log object
926 into an `std::list<std::string>` object. The order held by the index file is
927 kept.
928
929 @param need_lock_index whether or not the lock over the index file should be
930 acquired inside the function.
931
932 @return a pair: a function status code; a list of `std::string` objects with
933 the content of the log index file.
934 */
935 std::pair<int, std::list<std::string>> get_log_index(
936 bool need_lock_index = true);
937 inline char *get_index_fname() { return index_file_name; }
938 inline char *get_log_fname() { return log_file_name; }
939 const char *get_name() const { return name; }
940 inline mysql_mutex_t *get_log_lock() { return &LOCK_log; }
944 inline mysql_cond_t *get_log_cond() { return &update_cond; }
946
949 inline IO_CACHE *get_index_file() { return &index_file; }
950
951 /**
952 Function to report the missing GTIDs.
953
954 This function logs the missing transactions on master to its error log
955 as a warning. If the missing GTIDs are too long to print in a message,
956 it suggests the steps to extract the missing transactions.
957
958 This function also informs slave about the GTID set sent by the slave,
959 transactions missing on the master and few suggestions to recover from
960 the error. This message shall be wrapped by
961 ER_SOURCE_FATAL_ERROR_READING_BINLOG on slave and will be logged as an
962 error.
963
964 This function will be called from mysql_binlog_send() function.
965
966 @param slave_executed_gtid_set GTID set executed by slave
967 @param errmsg Pointer to the error message
968 */
969 void report_missing_purged_gtids(const Gtid_set *slave_executed_gtid_set,
970 std::string &errmsg);
971
972 /**
973 Function to report the missing GTIDs.
974
975 This function logs the missing transactions on master to its error log
976 as a warning. If the missing GTIDs are too long to print in a message,
977 it suggests the steps to extract the missing transactions.
978
979 This function also informs slave about the GTID set sent by the slave,
980 transactions missing on the master and few suggestions to recover from
981 the error. This message shall be wrapped by
982 ER_SOURCE_FATAL_ERROR_READING_BINLOG on slave and will be logged as an
983 error.
984
985 This function will be called from find_first_log_not_in_gtid_set()
986 function.
987
988 @param previous_gtid_set Previous GTID set found
989 @param slave_executed_gtid_set GTID set executed by slave
990 @param errmsg Pointer to the error message
991 */
992 void report_missing_gtids(const Gtid_set *previous_gtid_set,
993 const Gtid_set *slave_executed_gtid_set,
994 std::string &errmsg);
996 /*
997 It is called by the threads (e.g. dump thread, applier thread) which want
998 to read hot log without LOCK_log protection.
999 */
1002 return atomic_binlog_end_pos;
1003 }
1007
1008 /**
1009 Deep copy global_tsid_map and gtid_executed.
1010 Both operations are done under LOCK_commit and global_tsid_lock
1011 protection.
1012
1013 @param[out] tsid_map The Tsid_map to which global_tsid_map will
1014 be copied.
1015 @param[out] gtid_set The Gtid_set to which gtid_executed will
1016 be copied.
1017
1018 @return the operation status
1019 @retval 0 OK
1020 @retval !=0 Error
1021 */
1022 int get_gtid_executed(Tsid_map *tsid_map, Gtid_set *gtid_set);
1023
1024 /*
1025 True while rotating binlog, which is caused by logging Incident_log_event.
1026 */
1028
1029 public:
1030 /**
1031 Register LOG_INFO so that log_in_use and adjust_linfo_offsets can
1032 operate on all logs. Note that register_log_info, unregister_log_info,
1033 log_in_use, adjust_linfo_offsets are is used on global mysql_bin_log object.
1034 @param log_info pointer to LOG_INFO which is registred
1035 */
1037 /**
1038 Unregister LOG_INFO when it is no longer needed.
1039 @param log_info pointer to LOG_INFO which is registred
1040 */
1042 /**
1043 Check if any threads use log name.
1044 @note This method expects the LOCK_index to be taken so there are no
1045 concurrent edits against linfo objects being iterated
1046 @param log_name name of a log which is checked for usage
1047
1048 */
1049 int log_in_use(const char *log_name);
1050 /**
1051 Adjust the position pointer in the binary log file for all running replicas.
1052 SYNOPSIS
1053 adjust_linfo_offsets()
1054 purge_offset Number of bytes removed from start of log index file
1055 NOTES
1056 - This is called when doing a PURGE when we delete lines from the
1057 index log file. This method expects the LOCK_index to be taken so there
1058 are no concurrent edits against linfo objects being iterated. REQUIREMENTS
1059 - Before calling this function, we have to ensure that no threads are
1060 using any binary log file before purge_offset.
1061 TODO
1062 - Inform the replica threads that they should sync the position
1063 in the binary log file with flush_relay_log_info.
1064 Now they sync is done for next read.
1065 */
1066 void adjust_linfo_offsets(my_off_t purge_offset);
1067
1068 private:
1070 // Set of log info objects that are in usage and might prevent some other
1071 // operations from executing.
1072 std::set<LOG_INFO *> log_info_set;
1073};
1074
1079};
1080
1082
1083/**
1084 Check if the the transaction is empty.
1085
1086 @param thd The client thread that executed the current statement.
1087
1088 @retval true No changes found in any storage engine
1089 @retval false Otherwise.
1090
1091**/
1092bool is_transaction_empty(THD *thd);
1093/**
1094 Check if the transaction has no rw flag set for any of the storage engines.
1095
1096 @param thd The client thread that executed the current statement.
1097 @param trx_scope The transaction scope to look into.
1098
1099 @retval the number of engines which have actual changes.
1100 */
1102
1103/**
1104 Check if at least one of transacaction and statement binlog caches contains
1105 an empty transaction, other one is empty or contains an empty transaction,
1106 which has two binlog events "BEGIN" and "COMMIT".
1107
1108 @param thd The client thread that executed the current statement.
1109
1110 @retval true At least one of transacaction and statement binlog caches
1111 contains an empty transaction, other one is empty or
1112 contains an empty transaction.
1113 @retval false Otherwise.
1114*/
1116bool trans_has_updated_trans_table(const THD *thd);
1118bool ending_trans(THD *thd, const bool all);
1119bool ending_single_stmt_trans(THD *thd, const bool all);
1120bool trans_cannot_safely_rollback(const THD *thd);
1121bool stmt_cannot_safely_rollback(const THD *thd);
1122
1124
1125/**
1126 @brief Purges the binary log files up to the file name passed as
1127 a paramenter. Purge will not delete the file passed as
1128 an argument.
1129
1130 @param thd The session context.
1131 @param to_log Up to which log file to purge.
1132 @return true if there was an error.
1133 @return false if there was no error.
1134 */
1135bool purge_source_logs_to_file(THD *thd, const char *to_log);
1136
1137bool purge_source_logs_before_date(THD *thd, time_t purge_time);
1139bool mysql_show_binlog_events(THD *thd);
1140void check_binlog_cache_size(THD *thd);
1142bool binlog_enabled();
1143void register_binlog_handler(THD *thd, bool trx);
1144int query_error_code(const THD *thd, bool not_killed);
1145
1146extern const char *log_bin_index;
1147extern const char *log_bin_basename;
1148extern bool opt_binlog_order_commits;
1149extern ulong rpl_read_size;
1150/**
1151 Turns a relative log binary log path into a full path, based on the
1152 opt_bin_logname or opt_relay_logname. Also trims the cr-lf at the
1153 end of the full_path before return to avoid any server startup
1154 problem on windows.
1155
1156 @param from The log name we want to make into an absolute path.
1157 @param to The buffer where to put the results of the
1158 normalization.
1159 @param is_relay_log Switch that makes is used inside to choose which
1160 option (opt_bin_logname or opt_relay_logname) to
1161 use when calculating the base path.
1162
1163 @returns true if a problem occurs, false otherwise.
1164 */
1165
1166bool normalize_binlog_name(char *to, const char *from, bool is_relay_log);
1167
1168#endif /* BINLOG_H_INCLUDED */
int destroy(azio_stream *s)
Definition: azio.cc:371
int64 query_id_t
Definition: binlog.h:71
MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log
Contains the classes representing events occurring in the replication stream.
It owns an allocator, a byte stream, an event_data stream and an event object stream.
Definition: binlog_reader.h:294
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:173
Auxiliary class to copy serialized events to the binary log and correct some of the fields that are n...
Definition: binlog.cc:1380
StageID
Constants for queues for different stages.
Definition: rpl_commit_stage_manager.h:165
For binlog version 4.
Definition: log_event.h:1524
Stores information to monitor a transaction during the different replication stages.
Definition: rpl_gtid.h:1411
Represents a set of GTIDs.
Definition: rpl_gtid.h:1555
Container to hold and allow iteration over a set of Ha_trx_info objects.
Definition: transaction_info.h:502
Either statement transaction or normal transaction - related thread-specific storage engine data.
Definition: transaction_info.h:402
Class representing an incident, an occurrence out of the ordinary, that happened on the master.
Definition: log_event.h:3593
This is the abstract base class for binary log events.
Definition: log_event.h:537
Logical binlog file which wraps and hides the detail of lower layer storage implementation.
Definition: binlog.cc:380
Definition: binlog.h:138
mysql_mutex_t * get_binlog_end_pos_lock()
Definition: binlog.h:1004
const char * get_name() const
Definition: binlog.h:939
mysql_cond_t m_prep_xids_cond
Definition: binlog.h:251
mysql_mutex_t * get_commit_lock()
Definition: binlog.h:942
mysql_mutex_t LOCK_binlog_end_pos
Definition: binlog.h:207
std::atomic< my_off_t > atomic_binlog_end_pos
Definition: binlog.h:211
void unlock_binlog_end_pos()
Definition: binlog.h:1006
PSI_mutex_key m_key_LOCK_xids
The instrumentation key to use for @ LOCK_xids.
Definition: binlog.h:184
mysql_mutex_t LOCK_commit
Definition: binlog.h:204
char db[NAME_LEN+1]
Definition: binlog.h:149
void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param)
Definition: binlog.h:466
IO_CACHE crash_safe_index_file
Definition: binlog.h:219
void reset_bytes_written()
Definition: binlog.h:710
void lock_binlog_end_pos()
Definition: binlog.h:1005
enum_log_state
Definition: binlog.h:143
@ LOG_OPENED
Definition: binlog.h:143
@ LOG_CLOSED
Definition: binlog.h:143
@ LOG_TO_BE_OPENED
Definition: binlog.h:143
mysql_mutex_t LOCK_index
Definition: binlog.h:203
PSI_mutex_key m_key_COND_done
The PFS instrumentation key for @ COND_done.
Definition: binlog.h:174
mysql_mutex_t LOCK_sync
Definition: binlog.h:206
PSI_mutex_key m_key_LOCK_after_commit
The instrumentation key to use for @ LOCK_after_commit.
Definition: binlog.h:180
PSI_mutex_key m_key_LOCK_commit_queue
The PFS instrumentation key for @ LOCK_commit_queue.
Definition: binlog.h:162
bool write_event_to_binlog_and_flush(Log_event *ev)
mysql_mutex_t LOCK_after_commit
Definition: binlog.h:205
Binlog_ofile * get_binlog_file()
Definition: binlog.h:945
mysql_mutex_t LOCK_log_info
Definition: binlog.h:1069
int open(const char *opt_name) override
Initialize and open the coordinator log.
Definition: binlog.h:524
mysql_mutex_t * get_log_lock()
Definition: binlog.h:940
bool is_open() const
Definition: binlog.h:319
IO_CACHE purge_index_file
Definition: binlog.h:227
PSI_cond_key m_key_prep_xids_cond
The instrumentation key to use for @ prep_xids_cond.
Definition: binlog.h:190
my_off_t get_binlog_end_pos() const
Definition: binlog.h:1000
void lock_index()
Definition: binlog.h:947
PSI_mutex_key m_key_LOCK_flush_queue
The PFS instrumentation key for @ LOCK_flush_queue.
Definition: binlog.h:168
PSI_mutex_key m_key_LOCK_after_commit_queue
The PFS instrumentation key for @ LOCK_after_commit_queue.
Definition: binlog.h:164
int32 get_prep_xids()
Definition: binlog.h:266
std::atomic< enum_log_state > atomic_log_state
Definition: binlog.h:519
Gtid_set * previous_gtid_set_relaylog
Definition: binlog.h:522
PSI_cond_key m_key_update_cond
The instrumentation key to use for @ update_cond.
Definition: binlog.h:188
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_after_commit, PSI_mutex_key key_LOCK_after_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_mutex_key key_LOCK_log_info, PSI_mutex_key key_LOCK_wait_for_group_turn, PSI_cond_key key_COND_done, PSI_cond_key key_COND_flush_queue, PSI_cond_key key_update_cond, PSI_cond_key key_prep_xids_cond, PSI_cond_key key_COND_wait_for_group_turn, 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:363
char * get_index_fname()
Definition: binlog.h:937
bool write_error
Definition: binlog.h:150
uint * sync_period_ptr
Definition: binlog.h:248
mysql_mutex_t * get_after_commit_lock()
Definition: binlog.h:943
PSI_mutex_key m_key_LOCK_done
The PFS instrumentation key for @ LOCK_done.
Definition: binlog.h:166
std::set< LOG_INFO * > log_info_set
Definition: binlog.h:1072
std::atomic< int32 > m_atomic_prep_xids
Definition: binlog.h:252
Binlog_ofile * m_binlog_file
Definition: binlog.h:151
PSI_mutex_key m_key_LOCK_sync
The instrumentation key to use for @ LOCK_sync.
Definition: binlog.h:182
void add_bytes_written(ulonglong inc)
Definition: binlog.h:709
bool inited
Definition: binlog.h:150
PSI_file_key m_key_file_log_index_cache
The instrumentation key to use for opening a log index cache file.
Definition: binlog.h:200
mysql_mutex_t * get_index_lock()
Definition: binlog.h:941
PSI_mutex_key m_key_LOCK_binlog_end_pos
The instrumentation key to use for @ LOCK_binlog_end_pos.
Definition: binlog.h:160
char index_file_name[FN_REFLEN]
Definition: binlog.h:214
IO_CACHE * get_index_file()
Definition: binlog.h:949
mysql_cond_t * get_log_cond()
Definition: binlog.h:944
mysql_mutex_t LOCK_log
Definition: binlog.h:146
ulong max_size
Definition: binlog.h:239
bool is_relay_log
Definition: binlog.h:322
PSI_mutex_key m_key_LOCK_index
The instrumentation key to use for @ LOCK_index.
Definition: binlog.h:158
uint get_sync_period()
Definition: binlog.h:268
PSI_cond_key m_key_COND_wait_for_group_turn
The PFS instrumentation key for @ COND_wait_for_group_turn.
Definition: binlog.h:192
PSI_mutex_key m_key_LOCK_log
The instrumentation key to use for @ LOCK_log.
Definition: binlog.h:156
PSI_mutex_key m_key_COND_flush_queue
The PFS instrumentation key for @ COND_flush_queue.
Definition: binlog.h:176
uint file_id
Definition: binlog.h:242
ulonglong bytes_written
Definition: binlog.h:212
mysql_cond_t update_cond
Definition: binlog.h:209
PSI_mutex_key m_key_LOCK_commit
The instrumentation key to use for @ LOCK_commit.
Definition: binlog.h:178
PSI_mutex_key m_key_LOCK_wait_for_group_turn
The PFS instrumentation key for @ LOCK_wait_for_group_turn.
Definition: binlog.h:172
void unlock_index()
Definition: binlog.h:948
PSI_file_key m_key_file_log
The instrumentation key to use for opening the log file.
Definition: binlog.h:194
PSI_mutex_key m_key_LOCK_sync_queue
The PFS instrumentation key for @ LOCK_sync_queue.
Definition: binlog.h:170
char * get_log_fname()
Definition: binlog.h:938
char purge_index_file_name[FN_REFLEN]
Definition: binlog.h:228
mysql::binlog::event::enum_binlog_checksum_alg relay_log_checksum_alg
Definition: binlog.h:358
Transaction_dependency_tracker m_dependency_tracker
Manage the MTS dependency tracking.
Definition: binlog.h:407
IO_CACHE index_file
Definition: binlog.h:213
mysql_mutex_t LOCK_xids
Definition: binlog.h:208
PSI_file_key m_key_file_log_cache
The instrumentation key to use for opening a log cache file.
Definition: binlog.h:198
uint sync_counter
Definition: binlog.h:249
PSI_file_key m_log_file_key
Instrumentation key to use for file io in log_file.
Definition: binlog.h:154
bool is_rotating_caused_by_incident
Definition: binlog.h:1027
char * name
Definition: binlog.h:147
char log_file_name[FN_REFLEN]
Definition: binlog.h:148
uint8 checksum_alg_reset
Definition: binlog.h:324
PSI_mutex_key m_key_LOCK_log_info
The instrumentation key to use for @ m_key_LOCK_log_info.
Definition: binlog.h:186
char crash_safe_index_file_name[FN_REFLEN]
Definition: binlog.h:220
static const int MAX_RETRIES_FOR_DELETE_RENAME_FAILURE
Definition: binlog.h:995
PSI_file_key m_key_file_log_index
The instrumentation key to use for opening the log index file.
Definition: binlog.h:196
Definition: rpl_mi.h:86
Definition: rpl_rli.h:202
Common base class for all row-containing log events.
Definition: log_event.h:2763
Transaction Coordinator Log.
Definition: tc_log.h:143
enum_result
Definition: tc_log.h:159
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
enum_trx_scope
Definition: transaction_info.h:55
Dependency tracker is a container singleton that dispatches between the three methods associated with...
Definition: rpl_trx_tracking.h:216
Represents a bidirectional map between TSID and SIDNO.
Definition: rpl_gtid.h:748
Caches for non-transactional and transactional data before writing it to the binary log.
Definition: binlog.cc:701
This is the base class for verifying transaction boundaries.
Definition: trx_boundary_parser.h:49
Definition: item_func.h:3012
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:49
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:56
void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock)
Definition: binlog.cc:7880
bool mysql_show_binlog_events(THD *thd)
Execute a SHOW BINLOG EVENTS statement.
Definition: binlog.cc:3504
bool stmt_cannot_safely_rollback(const THD *thd)
This function checks if current statement cannot be rollded back safely.
Definition: binlog.cc:3192
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:245
int write_xa_to_cache(THD *thd)
Logging XA commit/rollback of a prepared transaction.
Definition: binlog.cc:2495
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:5591
int close_purge_index_file()
Definition: binlog.cc:6109
void set_max_size(ulong max_size_arg)
Definition: binlog.cc:7899
ulong rpl_read_size
Definition: binlog.cc:188
int flush_cache_to_file(my_off_t *flush_end_pos)
Flush the I/O cache to file.
Definition: binlog.cc:8731
void report_cache_write_error(THD *thd, bool is_transactional)
Definition: binlog.cc:5387
bool is_transaction_empty(THD *thd)
Check if the the transaction is empty.
Definition: binlog.cc:3083
int log_loaded_block(IO_CACHE *file)
Load data's io cache specific hook to be executed before a chunk of data is being read into the cache...
Definition: binlog.cc:3341
bool trans_cannot_safely_rollback(const THD *thd)
This function checks if a transaction cannot be rolled back safely.
Definition: binlog.cc:3179
THD * fetch_and_process_flush_stage_queue(const bool check_and_skip_flush_logs=false)
Fetch and empty BINLOG_FLUSH_STAGE and COMMIT_ORDER_FLUSH_STAGE flush queues and flush transactions t...
Definition: binlog.cc:8500
int rotate(bool force_rotate, bool *check_purge)
The method executes rotation when LOCK_log is already acquired by the caller.
Definition: binlog.cc:7201
void update_thd_next_event_pos(THD *thd)
Definition: binlog.cc:6974
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:5436
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:3121
void close() override
This is called on shutdown, after ha_panic.
Definition: binlog.cc:8106
int new_file_without_locking(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6501
void report_missing_purged_gtids(const Gtid_set *slave_executed_gtid_set, std::string &errmsg)
Function to report the missing GTIDs.
Definition: binlog.cc:9249
uint next_file_id()
Definition: binlog.cc:7323
void cleanup()
Definition: binlog.cc:3553
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:8542
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:7429
int rollback(THD *thd, bool all) override
Write a rollback record of the transaction to the binary log.
Definition: binlog.cc:2644
void init_pthread_objects()
Definition: binlog.cc:3578
bool reencrypt_logs()
Re-encrypt previous existent binary/relay logs as below.
Definition: binlog.cc:1905
void unregister_log_info(LOG_INFO *log_info)
Unregister LOG_INFO when it is no longer needed.
Definition: binlog.cc:7360
int log_in_use(const char *log_name)
Check if any threads use log name.
Definition: binlog.cc:7366
const char * log_bin_index
Definition: binlog.cc:184
int open_binlog(const char *opt_name)
Definition: binlog.cc:7945
~MYSQL_BIN_LOG() override
Definition: binlog.cc:3549
bool binlog_enabled()
Check whether binlog_hton has valid slot and enabled.
Definition: binlog.cc:1332
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:3102
int register_purge_index_entry(const char *entry)
Definition: binlog.cc:6140
int sync_purge_index_file()
Definition: binlog.cc:6129
int get_gtid_executed(Tsid_map *tsid_map, Gtid_set *gtid_set)
Deep copy global_tsid_map and gtid_executed.
Definition: binlog.cc:7331
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:1784
void register_log_info(LOG_INFO *log_info)
Register LOG_INFO so that log_in_use and adjust_linfo_offsets can operate on all logs.
Definition: binlog.cc:7354
int set_purge_index_file_name(const char *base_file_name)
Definition: binlog.cc:6074
void process_commit_stage_queue(THD *thd, THD *queue)
Commit a sequence of sessions.
Definition: binlog.cc:8599
void register_binlog_handler(THD *thd, bool trx)
Definition: binlog.cc:9465
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:3808
bool write_buffer(const char *buf, uint len, Master_info *mi)
Definition: binlog.cc:6915
int open_purge_index_file(bool destroy)
Definition: binlog.cc:6086
int set_crash_safe_index_file_name(const char *base_file_name)
Set the name of crash safe index file.
Definition: binlog.cc:5800
const char * log_bin_basename
Definition: binlog.cc:185
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:5953
bool write_transaction(THD *thd, binlog_cache_data *cache_data, Binlog_event_writer *writer)
Write the Gtid_log_event to the binary log (prior to writing the statement or transaction cache).
Definition: binlog.cc:1629
bool truncate_update_log_file(const char *log_name, my_off_t valid_pos, my_off_t binlog_size, bool update)
Truncte log file and clear LOG_EVENT_BINLOG_IN_USE_F when update is set.
Definition: binlog.cc:6856
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:8067
void check_binlog_cache_size(THD *thd)
Checks if the BINLOG_CACHE_SIZE's value is greater than MAX_BINLOG_CACHE_SIZE.
Definition: binlog.cc:1293
bool is_current_stmt_binlog_enabled_and_caches_empty(const THD *thd) const
Checks whether binlog caches are disabled (binlog does not cache data) or empty in case binloggging i...
Definition: binlog.cc:2943
bool write_event_to_binlog_and_sync(Log_event *ev)
Definition: binlog.cc:7665
bool read_binlog_in_use_flag(Binlog_file_reader &binlog_file_reader)
Read binary log stream header and Format_desc event from binlog_file_reader.
Definition: binlog.cc:7915
bool is_active(const char *log_file_name) const
Check if we are writing/reading to the given log file.
Definition: binlog.cc:6453
void check_binlog_stmt_cache_size(THD *thd)
Checks if the BINLOG_STMT_CACHE_SIZE's value is greater than MAX_BINLOG_STMT_CACHE_SIZE.
Definition: binlog.cc:1313
std::pair< bool, bool > sync_binlog_file(bool force)
Call fsync() to sync the file to disk.
Definition: binlog.cc:8744
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:5570
int generate_new_name(char *new_name, const char *log_name, uint32 new_index_number=0)
Definition: binlog.cc:3742
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event *event, bool is_transactional)
Definition: binlog.cc:6990
int finish_commit(THD *thd)
Helper function executed when leaving ordered_commit.
Definition: binlog.cc:8787
bool write_stmt_directly(THD *thd, const char *stmt, size_t stmt_len, enum enum_sql_command sql_command)
Write a dml into statement cache and then flush it into binlog.
Definition: binlog.cc:7591
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:3168
int raw_get_current_log(LOG_INFO *linfo)
Definition: binlog.cc:5360
int remove_logs_from_index(LOG_INFO *linfo, bool need_update_threads)
Remove logs from index file.
Definition: binlog.cc:5891
enum_result commit(THD *thd, bool all) override
Commit the transaction in the transaction coordinator.
Definition: binlog.cc:8171
bool check_write_error(const THD *thd)
Definition: binlog.cc:5368
bool purge_source_logs_to_file(THD *thd, const char *to_log)
Purges the binary log files up to the file name passed as a paramenter.
Definition: binlog.cc:3207
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:5524
int wait_for_update()
Wait until we get a signal that the binary log has been updated.
Definition: binlog.cc:7763
void make_log_name(char *buf, const char *log_ident)
Create a new log file name.
Definition: binlog.cc:6442
bool change_stage(THD *thd, Commit_stage_manager::StageID stage, THD *queue, mysql_mutex_t *leave_mutex, mysql_mutex_t *enter_mutex)
Enter a stage of the ordered commit procedure.
Definition: binlog.cc:8700
bool find_first_log(std::string &binlog_file_name, std::string &errmsg)
Find the oldest binary log referenced by the index file.
Definition: binlog.cc:4453
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:7703
bool write_event(Log_event *event_info)
Write an event to the binary log cache.
Definition: binlog.cc:7033
void update_binlog_end_pos(bool need_lock=true)
Definition: binlog.cc:9380
int rotate_and_purge(THD *thd, bool force_rotate)
Execute a FLUSH LOGS statement.
Definition: binlog.cc:7291
int get_current_log(LOG_INFO *linfo, bool need_lock_log=true)
Definition: binlog.cc:5352
bool is_query_in_union(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6965
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:6521
bool write_event_to_binlog(Log_event *ev)
Definition: binlog.cc:7644
bool reset_logs(THD *thd, bool delete_only=false)
Removes files, as part of a RESET BINARY LOGS AND GTIDS or RESET REPLICA statement,...
Definition: binlog.cc:5634
bool purge_source_logs_before_date(THD *thd, time_t purge_time)
Execute a PURGE BINARY LOGS BEFORE <date> command.
Definition: binlog.cc:3246
bool stmt_has_updated_trans_table(Ha_trx_info_list const &ha_list)
This function checks if a transactional table was updated by the current statement.
Definition: binlog.cc:3135
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:3153
int query_error_code(const THD *thd, bool not_killed)
Definition: binlog.cc:3273
void process_after_commit_stage_queue(THD *thd, THD *first)
Process after commit for a sequence of sessions.
Definition: binlog.cc:8672
std::pair< int, my_off_t > flush_thread_caches(THD *thd)
Flush caches for session.
Definition: binlog.cc:8448
int move_crash_safe_index_file_to_index_file(bool need_lock_index)
Move crash safe index file to index file.
Definition: binlog.cc:5151
void report_missing_gtids(const Gtid_set *previous_gtid_set, const Gtid_set *slave_executed_gtid_set, std::string &errmsg)
Function to report the missing GTIDs.
Definition: binlog.cc:9313
int purge_index_entry(THD *thd, ulonglong *decrease_log_space, bool need_lock_index)
Definition: binlog.cc:6157
bool init_and_set_log_file_name(const char *log_name, const char *new_name, uint32 new_index_number)
Definition: binlog.cc:3782
const char * generate_name(const char *log_name, const char *suffix, char *buff)
Definition: binlog.cc:3763
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:6326
bool opt_binlog_order_commits
Definition: binlog.cc:182
void init_thd_variables(THD *thd, bool all, bool skip_commit)
Set thread variables used while flushing a transaction.
Definition: binlog.cc:8465
int open_crash_safe_index_file()
Open a (new) crash safe index file.
Definition: binlog.cc:5824
void start_union_events(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:6952
bool is_inited_purge_index_file()
Definition: binlog.cc:6124
bool init_gtid_sets(Gtid_set *all_gtids, Gtid_set *lost_gtids, bool verify_checksum, bool need_lock, mysql::binlog::event::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:4566
bool open_index_file(const char *index_file_name_arg, const char *log_name, bool need_lock_index)
Definition: binlog.cc:3861
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:7623
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:1567
int register_create_index_entry(const char *entry)
Definition: binlog.cc:6152
int close_crash_safe_index_file()
Close the crash safe index file.
Definition: binlog.cc:5856
void auto_purge()
This function runs automatic purge if the conditions to meet automatic purge are met.
Definition: binlog.cc:7231
int prepare(THD *thd, bool all) override
Log a prepare record of the transaction to the storage engines.
Definition: binlog.cc:8118
void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log, const char *message)
Helper function to handle flush or sync stage errors.
Definition: binlog.cc:8891
int ordered_commit(THD *thd, bool all, bool skip_commit=false)
Flush and commit the transaction.
Definition: binlog.cc:8941
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:5309
void adjust_linfo_offsets(my_off_t purge_offset)
Adjust the position pointer in the binary log file for all running replicas.
Definition: binlog.cc:7392
MYSQL_BIN_LOG(uint *sync_period, bool relay_log=false)
Definition: binlog.cc:3525
bool flush_and_sync(const bool force=false)
Flush binlog cache and synchronize to disk.
Definition: binlog.cc:6942
int new_file(Format_description_log_event *extra_description_event)
Definition: binlog.cc:6492
bool show_binlog_events(THD *thd, MYSQL_BIN_LOG *binary_log)
Definition: binlog.cc:3376
void inc_prep_xids(THD *thd)
Increment the prepared XID counter.
Definition: binlog.cc:6457
void dec_prep_xids(THD *thd)
Decrement the prepared XID counter.
Definition: binlog.cc:6468
void stop_union_events(THD *thd)
Definition: binlog.cc:6960
bool flush()
Definition: binlog.cc:6938
void signal_update()
Notifies waiting threads that binary log has been updated.
Definition: binlog.cc:9372
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:3090
bool find_first_log_not_in_gtid_set(char *binlog_file_name, const Gtid_set *gtid_set, Gtid *first_gtid, std::string &errmsg)
Find the oldest binary log that contains any GTID that is not in the given gtid set.
Definition: binlog.cc:4468
void report_binlog_write_error()
Definition: binlog.cc:7755
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:6760
void auto_purge_at_server_startup()
This member function is to be called at server startup.
Definition: binlog.cc:7219
#define log_info(...)
Definition: log_client.h:152
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:43
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:47
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:51
#define mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
Definition: mysql_mutex.h:125
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
uint8_t uint8
Definition: my_inttypes.h:62
ulonglong my_off_t
Definition: my_inttypes.h:71
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
int32_t int32
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:66
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
enum_sql_command
Definition: my_sqlcommand.h:45
Common header for many mysys elements.
uint32 my_thread_id
Definition: my_thread_local.h:33
static int not_killed
Definition: myisamchk.cc:1618
static uint update
Definition: myisamlog.cc:93
static QUEUE queue
Definition: myisampack.cc:209
Common definition between mysql server & client.
#define NAME_LEN
Definition: mysql_com.h:66
Instrumentation helpers for conditions.
ABI for instrumented mutexes.
Type inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:292
Definition: base.h:74
Definition: buf0block_hint.cc:29
Definition: os0file.h:88
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:497
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:460
Instrumentation helpers for conditions.
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
Performance schema instrumentation interface.
Instrumentation helpers for mutexes.
required string event
Definition: replication_group_member_actions.proto:31
Definition: binlog.h:88
Item_result type
Definition: binlog.h:92
ulong length
Definition: binlog.h:91
char * value
Definition: binlog.h:90
bool unsigned_flag
Definition: binlog.h:94
user_var_entry * user_var_event
Definition: binlog.h:89
uint charset_number
Definition: binlog.h:93
TODO: Move this structure to mysql/binlog/event/control_events.h when we start using C++11.
Definition: rpl_gtid.h:1099
Definition: my_sys.h:345
Definition: binlog.h:1075
bool log_delayed
Definition: binlog.h:1078
my_off_t last_pos_in_file
Definition: binlog.h:1077
bool logged_data_file
Definition: binlog.h:1078
THD * thd
Definition: binlog.h:1076
Definition: binlog.h:114
my_thread_id thread_id
Definition: binlog.h:121
my_off_t pos
Definition: binlog.h:117
my_off_t index_file_start_offset
Definition: binlog.h:116
LOG_INFO()
Definition: binlog.h:122
bool fatal
Definition: binlog.h:118
char log_file_name[FN_REFLEN]
Definition: binlog.h:115
my_off_t index_file_offset
Definition: binlog.h:116
int entry_index
Definition: binlog.h:119
int encrypted_header_size
Definition: binlog.h:120
Definition: completion_hash.h:34
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
MySQL mutex implementation.
Include file for Sun RPC to compile out of the box.
Transaction boundary parser definitions.
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:881