MySQL 26.7.0
Source Code Documentation
binlog.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
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#ifndef BINLOG_H_INCLUDED
24#define BINLOG_H_INCLUDED
25
26#include <string.h>
27#include <sys/types.h>
28#include <time.h>
29#include <atomic>
30#include <string_view>
31#include <utility>
32
33#include "my_dbug.h"
34#include "my_inttypes.h"
35#include "my_io.h"
36#include "my_sharedlib.h"
37#include "my_sys.h"
38#include "mysql/binlog/event/binlog_event.h" // enum_binlog_checksum_alg
48#include "mysql_com.h" // Item_result
50#include "sql/binlog_index.h" // Log_info, Binlog_index
51#include "sql/binlog_reader.h" // Binlog_file_reader
54#include "sql/tc_log.h" // TC_LOG
55#include "sql/transaction_info.h" // Transaction_ctx
56#include "thr_mutex.h"
57
60class Gtid_set;
61class Ha_trx_info;
62class Log_event;
63class Master_info;
64class Relay_log_info;
65class Rows_log_event;
66class Tsid_map;
67class THD;
68class Transaction_boundary_parser;
70class user_var_entry;
72
73struct Gtid;
74
76
77/*
78 Maximum unique log filename extension.
79 Note: setting to 0x7FFFFFFF due to atol windows
80 overflow/truncate.
81 */
82#define MAX_LOG_UNIQUE_FN_EXT 0x7FFFFFFF
83
84/*
85 Maximum allowed unique log filename extension for
86 RESET BINARY LOGS AND GTIDS command - 2 Billion
87 */
88#define MAX_ALLOWED_FN_EXT_RESET_BIN_LOGS 2000000000
89
92 char *value;
93 ulong length;
97};
98
99/* bitmap to MYSQL_BIN_LOG::close() */
100#define LOG_CLOSE_INDEX 1
101#define LOG_CLOSE_TO_BE_OPENED 2
102#define LOG_CLOSE_STOP_EVENT 4
103
104/*
105 TODO use mmap instead of IO_CACHE for binlog
106 (mmap+fsync is two times faster than write+fsync)
107*/
108class MYSQL_BIN_LOG : public TC_LOG {
109 public:
110 class Binlog_ofile;
111
112 private:
114
115 /* LOCK_log is inited by init_pthread_objects() */
117 char *name;
119 char db[NAME_LEN + 1];
122
123 /** Instrumentation key to use for file io in @c log_file */
125 /** The instrumentation key to use for @ LOCK_log. */
127 /** The instrumentation key to use for @ LOCK_binlog_end_pos. */
129 /** The PFS instrumentation key for @ LOCK_commit_queue. */
131 /** The PFS instrumentation key for @ LOCK_after_commit_queue. */
133 /** The PFS instrumentation key for @ LOCK_done. */
135 /** The PFS instrumentation key for @ LOCK_flush_queue. */
137 /** The PFS instrumentation key for @ LOCK_sync_queue. */
139 /** The PFS instrumentation key for @ LOCK_wait_for_group_turn. */
141 /** The PFS instrumentation key for @ COND_done. */
143 /** The PFS instrumentation key for @ COND_flush_queue. */
145 /** The instrumentation key to use for @ LOCK_commit. */
147 /** The instrumentation key to use for @ LOCK_after_commit. */
149 /** The instrumentation key to use for @ LOCK_sync. */
151 /** The instrumentation key to use for @ LOCK_xids. */
153 /** The instrumentation key to use for @ m_key_LOCK_log_info. */
155 /** The instrumentation key to use for @ update_cond. */
157 /** The instrumentation key to use for @ prep_xids_cond. */
159 /** The PFS instrumentation key for @ COND_wait_for_group_turn. */
161 /** The instrumentation key to use for opening the log file. */
163 /** The instrumentation key to use for opening a log cache file. */
165
166 /* POSIX thread objects are inited by init_pthread_objects() */
173
174 std::atomic<my_off_t> atomic_binlog_end_pos;
176
177 /** Concurrent access to binlog index file */
179
180 /*
181 The max size before rotation (usable only if log_type == LOG_BIN: binary
182 logs and relay logs).
183 For a binlog, max_size should be max_binlog_size.
184 For a relay log, it should be max_relay_log_size if this is non-zero,
185 max_binlog_size otherwise.
186 max_size is set in init(), and dynamically changed (when one does SET
187 GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
188 fix_max_relay_log_size).
189 */
190 ulong max_size;
191
192 // current file sequence number for load data infile binary logging
194
195 /* pointer to the sync period variable, for binlog this will be
196 sync_binlog_period, for relay log this will be
197 sync_relay_log_period
198 */
201
203 std::atomic<int32> m_atomic_prep_xids{0};
204
205 /**
206 Increment the prepared XID counter.
207 */
208 void inc_prep_xids(THD *thd);
209
210 /**
211 Decrement the prepared XID counter.
212
213 Signal m_prep_xids_cond if the counter reaches zero.
214 */
215 void dec_prep_xids(THD *thd);
216
218
219 public:
220 /**
221 Wait until the number of prepared XIDs are zero.
222 */
223 void wait_for_prep_xids();
224 [[nodiscard]] inline char *get_log_file_name() { return log_file_name; }
225 [[nodiscard]] inline ulong get_max_size() { return max_size; }
226 [[nodiscard]] inline uint get_sync_period() { return *sync_period_ptr; }
227 [[nodiscard]] inline uint get_sync_counter() { return sync_counter; }
228
229 /*
230 This is used to start writing to a new log file. The difference from
231 new_file() is locking. new_file_without_locking() does not acquire
232 LOCK_log.
233 */
235 Format_description_log_event *extra_description_event);
236
237 /**
238 Checks whether binlog caches are disabled (binlog does not cache data) or
239 empty in case binloggging is enabled in the current call to this function.
240 This function may be safely called in case binlogging is disabled.
241 @retval true binlog local caches are empty or disabled and binlogging is
242 enabled
243 @retval false binlog local caches are enabled and contain data or binlogging
244 is disabled
245 */
247
248 private:
249 int new_file_impl(bool need_lock,
250 Format_description_log_event *extra_description_event);
251
252 bool open(PSI_file_key log_file_key, const char *log_name,
253 const char *new_name, uint32 new_index_number);
254 bool init_and_set_log_file_name(const char *log_name, const char *new_name,
255 uint32 new_index_number);
256 int generate_new_name(char *new_name, const char *log_name,
257 uint32 new_index_number = 0);
258 /**
259 * Read binary log stream header and Format_desc event from
260 * binlog_file_reader. Check for LOG_EVENT_BINLOG_IN_USE_F flag.
261 * @param[in] binlog_file_reader a Binlog_file_reader
262 * @return true - LOG_EVENT_BINLOG_IN_USE_F is set
263 * false - LOG_EVENT_BINLOG_IN_USE_F is not set or an error occurred
264 * while reading log events
265 */
266 bool read_binlog_in_use_flag(Binlog_file_reader &binlog_file_reader);
267
268 protected:
269 /**
270 @brief Notifies waiting threads that binary log has been updated
271 */
272 void signal_update();
273
274 public:
275 const char *generate_name(const char *log_name, const char *suffix,
276 char *buff);
277 bool is_open() const { return atomic_log_state != LOG_CLOSED; }
278
279 /** @see Binlog_index_monitor::get_filename_list */
280 std::pair<std::list<std::string>, mysql::utils::Error> get_filename_list();
281
282 /* This is relay log */
284
285 uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
286 /*
287 Holds the last seen in Relay-Log FD's checksum alg value.
288 The initial value comes from the slave's local FD that heads
289 the very first Relay-Log file. In the following the value may change
290 with each received master's FD_m.
291 Besides to be used in verification events that IO thread receives
292 (except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd),
293 the value specifies if/how to compute checksum for slave's local events
294 and the first fake Rotate (R_f^1) coming from the master.
295 R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
296
297 Legends for the checksum related comments:
298
299 FD - Format-Description event,
300 R - Rotate event
301 R_f - The fake Rotate event
302 E - An arbitrary event
303
304 The underscore indexes for any event
305 `_s' - Indicates the event is generated by the Replica
306 `_m' - By the Source
307
308 Two special underscore indexes of FD:
309 FD_q - Format Description event for queuing (relay-logging)
310 FD_e - Format Description event for executing (relay-logging)
311
312 Upper indexes:
313 E^n - n:th event is a sequence
314
315 RL - Relay Log
316 (A) - checksum algorithm descriptor value
317 FD.(A) - the value of (A) in FD
318 */
320
321 MYSQL_BIN_LOG(uint *sync_period, bool relay_log = false);
322 ~MYSQL_BIN_LOG() override;
323
325 PSI_mutex_key key_LOCK_index, PSI_mutex_key key_LOCK_commit,
326 PSI_mutex_key key_LOCK_commit_queue, PSI_mutex_key key_LOCK_after_commit,
327 PSI_mutex_key key_LOCK_after_commit_queue, PSI_mutex_key key_LOCK_done,
328 PSI_mutex_key key_LOCK_flush_queue, PSI_mutex_key key_LOCK_log,
329 PSI_mutex_key key_LOCK_binlog_end_pos, PSI_mutex_key key_LOCK_sync,
330 PSI_mutex_key key_LOCK_sync_queue, PSI_mutex_key key_LOCK_xids,
331 PSI_mutex_key key_LOCK_log_info,
332 PSI_mutex_key key_LOCK_wait_for_group_turn, PSI_cond_key key_COND_done,
333 PSI_cond_key key_COND_flush_queue, PSI_cond_key key_update_cond,
334 PSI_cond_key key_prep_xids_cond,
335 PSI_cond_key key_COND_wait_for_group_turn, PSI_file_key key_file_log,
336 PSI_file_key key_file_log_index, PSI_file_key key_file_log_cache,
337 PSI_file_key key_file_log_index_cache) {
338 m_key_COND_done = key_COND_done;
339 m_key_COND_flush_queue = key_COND_flush_queue;
340
341 m_key_LOCK_commit_queue = key_LOCK_commit_queue;
342 m_key_LOCK_after_commit_queue = key_LOCK_after_commit_queue;
343 m_key_LOCK_done = key_LOCK_done;
344 m_key_LOCK_flush_queue = key_LOCK_flush_queue;
345 m_key_LOCK_sync_queue = key_LOCK_sync_queue;
346
347 m_key_LOCK_log = key_LOCK_log;
348 m_key_LOCK_binlog_end_pos = key_LOCK_binlog_end_pos;
349 m_key_LOCK_commit = key_LOCK_commit;
350 m_key_LOCK_after_commit = key_LOCK_after_commit;
351 m_key_LOCK_sync = key_LOCK_sync;
352 m_key_LOCK_xids = key_LOCK_xids;
353 m_key_LOCK_log_info = key_LOCK_log_info;
354 m_key_update_cond = key_update_cond;
355 m_key_prep_xids_cond = key_prep_xids_cond;
356 m_key_file_log = key_file_log;
357 m_key_file_log_cache = key_file_log_cache;
358
359 m_binlog_index_monitor.set_psi_keys(key_LOCK_index, key_file_log_index,
360 key_file_log_index_cache);
361
362 m_key_LOCK_wait_for_group_turn = key_LOCK_wait_for_group_turn;
363 m_key_COND_wait_for_group_turn = key_COND_wait_for_group_turn;
364 }
365
366 public:
367 /** Manage the MTS dependency tracking */
369
370 /**
371 Find the oldest binary log referenced by the index file
372
373 @param[out] binlog_file_name the file name of oldest log found
374 @param[out] errmsg the error message outputted, which is left untouched
375 if the function returns false
376 @return false on success, true on error.
377 */
378 bool find_first_log(std::string &binlog_file_name, std::string &errmsg);
379
380 /**
381 Find the oldest binary log that contains any GTID that
382 is not in the given gtid set.
383
384 @param[out] binlog_file_name the file name of oldest binary log found
385 @param[in] gtid_set the given gtid set
386 @param[out] first_gtid the first GTID information from the binary log
387 file returned at binlog_file_name
388 @param[out] errmsg the error message outputted, which is left untouched
389 if the function returns false
390 @return false on success, true on error.
391 */
392 bool find_first_log_not_in_gtid_set(char *binlog_file_name,
393 const Gtid_set *gtid_set,
394 Gtid *first_gtid, std::string &errmsg);
395
396 /**
397 Reads the set of all GTIDs in the binary/relay log, and the set
398 of all lost GTIDs in the binary log, and stores each set in
399 respective argument.
400
401 @param all_gtids Will be filled with all GTIDs in this binary/relay
402 log.
403 @param lost_gtids Will be filled with all GTIDs in the
404 Previous_gtids_log_event of the first binary log that has a
405 Previous_gtids_log_event. This is requested to binary logs but not
406 to relay logs.
407 @param verify_checksum If true, checksums will be checked.
408 @param need_lock If true, LOCK_log, LOCK_index, and
409 global_tsid_lock->wrlock are acquired; otherwise they are asserted
410 to be taken already.
411 @param [out] trx_parser This will be used to return the actual
412 relaylog transaction parser state because of the possibility
413 of partial transactions.
414 @param [out] partial_trx If a transaction was left incomplete
415 on the relaylog, its GTID information should be returned to be
416 used in the case of the rest of the transaction be added to the
417 relaylog.
418 @param is_server_starting True if the server is starting.
419 @return false on success, true on error.
420 */
421 bool init_gtid_sets(
422 Gtid_set *all_gtids, Gtid_set *lost_gtids, bool verify_checksum,
423 bool need_lock,
425 Gtid_monitoring_info *partial_trx, bool is_server_starting = false);
426
427 void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param) {
428 assert(is_relay_log);
429 previous_gtid_set_relaylog = previous_gtid_set_param;
430 }
431 /**
432 If the thread owns a GTID, this function generates an empty
433 transaction and releases ownership of the GTID.
434
435 - If the binary log is disabled for this thread, the GTID is
436 inserted directly into the mysql.gtid_executed table and the
437 GTID is included in @@global.gtid_executed. (This only happens
438 for DDL, since DML will save the GTID into table and release
439 ownership inside ha_commit_trans.)
440
441 - If the binary log is enabled for this thread, an empty
442 transaction consisting of GTID, BEGIN, COMMIT is written to the
443 binary log, the GTID is included in @@global.gtid_executed, and
444 the GTID is added to the mysql.gtid_executed table on the next
445 binlog rotation.
446
447 This function must be called by any committing statement (COMMIT,
448 implicitly committing statements, or Xid_log_event), after the
449 statement has completed execution, regardless of whether the
450 statement updated the database.
451
452 This logic ensures that an empty transaction is generated for the
453 following cases:
454
455 - Explicit empty transaction:
456 SET GTID_NEXT = 'UUID:NUMBER'; BEGIN; COMMIT;
457
458 - Transaction or DDL that gets completely filtered out in the
459 slave thread.
460
461 @param thd The committing thread
462
463 @retval 0 Success
464 @retval nonzero Error
465 */
466 int gtid_end_transaction(THD *thd);
467 /**
468 Re-encrypt previous existent binary/relay logs as below.
469 Starting from the next to last entry on the index file, iterating
470 down to the first one:
471 - If the file is encrypted, re-encrypt it. Otherwise, skip it.
472 - If failed to open the file, report an error.
473
474 @retval False Success
475 @retval True Error
476 */
477 bool reencrypt_logs();
478
479 /**
480 Enter a stage of the ordered commit procedure.
481
482 Entering is stage is done by:
483
484 - Atomically entering a queue of THD objects (which is just one for
485 the first phase).
486
487 - If the queue was empty, the thread is the leader for that stage
488 and it should process the entire queue for that stage.
489
490 - If the queue was not empty, the thread is a follower and can go
491 waiting for the commit to finish.
492
493 The function will lock the stage mutex if the calling thread was designated
494 leader for the phase.
495
496 @param[in] thd Session structure
497 @param[in] stage The stage to enter
498 @param[in] queue Thread queue for the stage
499 @param[in] leave_mutex Mutex that will be released when changing stage
500 @param[in] enter_mutex Mutex that will be taken when changing stage
501
502 @retval true In case this thread did not become leader, the function
503 returns true *after* the leader has completed the commit
504 on its behalf, so the thread should continue doing the
505 thread-local processing after the commit
506 (i.e. call finish_commit).
507
508 @retval false The thread is the leader for the stage and should do
509 the processing.
510 */
512 mysql_mutex_t *leave_mutex, mysql_mutex_t *enter_mutex);
513
514 /**
515 Set thread variables used while flushing a transaction.
516
517 @param[in] thd thread whose variables need to be set
518 @param[in] all This is @c true if this is a real transaction commit, and
519 @c false otherwise.
520 @param[in] skip_commit
521 This is @c true if the call to @c ha_commit_low should
522 be skipped (it is handled by the caller somehow) and @c
523 false otherwise (the normal case).
524 */
525 void init_thd_variables(THD *thd, bool all, bool skip_commit);
526
527 [[nodiscard]] int flush_cache_to_file(my_off_t *flush_end_pos);
528 [[nodiscard]] std::pair<int, my_off_t> flush_thread_caches(THD *thd);
529 void handle_binlog_flush_or_sync_error(THD *thd, bool need_lock_log,
530 const char *message);
531 void reset_thread_caches(THD *thd);
532
533 [[nodiscard]] std::pair<bool, bool> sync_binlog_file(bool force);
534 [[nodiscard]] int call_after_sync_hook(THD *queue_head);
535
537 void process_after_commit_stage_queue(THD *thd, THD *first);
538
539 [[nodiscard]] int finish_commit(THD *thd);
540
541 private:
542 std::atomic<enum_log_state> atomic_log_state{LOG_CLOSED};
543
544 /* The previous gtid set in relay log. */
546
547 [[nodiscard]] int open(const char *opt_name) override {
548 return open_binlog(opt_name);
549 }
550
551 /**
552 Finishes the transaction in the engines. If the `commit_low` flag is set,
553 will commit in the engines, otherwise, if the underlying statement is an
554 `XA ROLLBACK`, it will rollback in the engines.
555
556 @param thd The THD session object holding the transaction to finalize.
557 @param all Finalizing a transaction (i.e. true) or a statement
558 (i.e. false).
559 @param run_after_commit In the case of a commit being issued, whether or
560 not to run the `after_commit` hook.
561 */
562 void finish_transaction_in_engines(THD *thd, bool all, bool run_after_commit);
563
564 /**
565 Flush and commit the transaction.
566
567 This will execute an ordered flush and commit of all outstanding
568 transactions and is the main function for the binary log group
569 commit logic. The function performs the ordered commit in four stages.
570
571 Pre-condition: transactions should have called ha_prepare_low, using
572 HA_IGNORE_DURABILITY, before entering here.
573
574 Stage#0 implements replica-preserve-commit-order for applier threads that
575 write the binary log. i.e. it forces threads to enter the queue in the
576 correct commit order.
577
578 The stage#1 flushes the caches to the binary log and under
579 LOCK_log and marks all threads that were flushed as not pending.
580
581 The stage#2 syncs the binary log for all transactions in the group.
582
583 The stage#3 executes under LOCK_commit and commits all transactions in
584 order.
585
586 There are three queues of THD objects: one for each stage.
587 The Commit_order_manager maintains it own queue and its own order for the
588 commit. So Stage#0 doesn't maintain separate StageID.
589
590 When a transaction enters a stage, it adds itself to a queue. If the queue
591 was empty so that this becomes the first transaction in the queue, the
592 thread is the *leader* of the queue. Otherwise it is a *follower*. The
593 leader will do all work for all threads in the queue, and the followers
594 will wait until the last stage is finished.
595
596 Stage 0 (SLAVE COMMIT ORDER):
597 1. If replica-preserve-commit-order and is slave applier worker thread, then
598 waits until its turn to commit i.e. till it is on the top of the queue.
599 2. When it reaches top of the queue, it signals next worker in the commit
600 order queue to awake.
601
602 Stage 1 (FLUSH):
603 1. Sync the engines (ha_flush_logs), since they prepared using non-durable
604 settings (HA_IGNORE_DURABILITY).
605 2. Generate GTIDs for all transactions in the queue.
606 3. Write the session caches for all transactions in the queue to the binary
607 log.
608 4. Increment the counter of prepared XIDs.
609
610 Stage 2 (SYNC):
611 1. If it is time to sync, based on the sync_binlog option, sync the binlog.
612 2. If sync_binlog==1, signal dump threads that they can read up to the
613 position after the last transaction in the queue
614
615 Stage 3 (COMMIT):
616 This is performed by each thread separately, if binlog_order_commits=0.
617 Otherwise by the leader does it for all threads.
618 1. Call the after_sync hook.
619 2. update the max_committed counter in the dependency_tracker
620 3. call ha_commit_low
621 4. Call the after_commit hook
622 5. Update gtids
623 6. Decrement the counter of prepared transactions
624
625 If the binary log needs to be rotated, it is done after this. During
626 rotation, it takes a lock that prevents new commit groups from executing the
627 flush stage, and waits until the counter of prepared transactions becomes 0,
628 before it creates the new file.
629
630 @param[in] thd Session to commit transaction for
631 @param[in] all This is @c true if this is a real transaction commit, and
632 @c false otherwise.
633 @param[in] skip_commit
634 This is @c true if the call to @c ha_commit_low should
635 be skipped and @c false otherwise (the normal case).
636 */
637 int ordered_commit(THD *thd, bool all, bool skip_commit = false);
639 class Binlog_event_writer *writer);
641
642 public:
643 int open_binlog(const char *opt_name);
644 void close() override;
645 enum_result commit(THD *thd, bool all) override;
646 int rollback(THD *thd, bool all) override;
647 bool truncate_relaylog_file(Master_info *mi, my_off_t valid_pos);
648 int prepare(THD *thd, bool all) override;
649#if defined(MYSQL_SERVER)
650
653 bool is_transactional);
654
655#endif /* defined(MYSQL_SERVER) */
658 /// @brief Adds bytes written in the current relay log into the variable
659 /// handling the total number of bytes acquired by the replica. Resets the
660 /// counter of bytes written. If requested by caller,
661 /// acquires relay log space lock
662 /// @param rli Pointer to the applier metadata object
663 /// @param need_log_space_lock Information on whether to acquire the
664 /// lock protecting data responsible for keeping the relay log space at bay
665 void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock);
666 void set_max_size(ulong max_size_arg);
667
668 void update_binlog_end_pos(bool need_lock = true);
669 void update_binlog_end_pos(const char *file, my_off_t pos);
670
671 /**
672 Wait until we get a signal that the binary log has been updated.
673
674 NOTES
675 @param[in] timeout a pointer to a timespec;
676 NULL means to wait w/o timeout.
677 @retval 0 if got signalled on update
678 @retval non-0 if wait timeout elapsed
679 @note
680 LOCK_binlog_end_pos must be owned before calling this function, may be
681 temporarily released while the thread is waiting and is reacquired before
682 returning from the function
683 */
684 int wait_for_update(const std::chrono::nanoseconds &timeout);
685
686 /**
687 Wait until we get a signal that the binary log has been updated.
688 @retval 0 success
689 @note
690 LOCK_binlog_end_pos must be owned before calling this function, may be
691 temporarily released while the thread is waiting and is reacquired before
692 returning from the function
693 */
694 int wait_for_update();
695
696 public:
698 void cleanup();
699 /**
700 Create a new binary log.
701 @param log_name Name of binlog
702 @param new_name Name of binlog, too. todo: what's the difference
703 between new_name and log_name?
704 @param max_size_arg The size at which this binlog will be rotated.
705 @param null_created_arg If false, and a Format_description_log_event
706 is written, then the Format_description_log_event will have the
707 timestamp 0. Otherwise, it the timestamp will be the time when the
708 event was written to the log.
709 @param need_lock_index If true, LOCK_index is acquired; otherwise
710 LOCK_index must be taken by the caller.
711 @param need_tsid_lock If true, the read lock on global_tsid_lock
712 will be acquired. Otherwise, the caller must hold the read lock
713 on global_tsid_lock.
714 @param extra_description_event The master's FDE to be written by the I/O
715 thread while creating a new relay log file. This should be NULL for
716 binary log files.
717 @param new_index_number The binary log file index number to start from
718 after the RESET BINARY LOGS AND GTIDS command is called.
719 */
720 bool open_binlog(const char *log_name, const char *new_name,
721 ulong max_size_arg, bool null_created_arg,
722 bool need_lock_index, bool need_tsid_lock,
723 Format_description_log_event *extra_description_event,
724 uint32 new_index_number = 0);
725 bool open_index_file(const char *index_file_name_arg, const char *log_name,
726 bool need_lock_index);
727 /* Use this to start writing a new log file */
728 int new_file(Format_description_log_event *extra_description_event);
729
730 bool write_event(Log_event *event_info);
731 bool write_cache(THD *thd, class binlog_cache_data *cache_data,
732 class Binlog_event_writer *writer);
733 /**
734 Assign automatic generated GTIDs for all commit group threads in the flush
735 stage having gtid_next.type == AUTOMATIC_GTID.
736
737 @param first_seen The first thread seen entering the flush stage.
738 @return Returns false if succeeds, otherwise true is returned.
739 */
741 bool write_transaction(THD *thd, binlog_cache_data *cache_data,
742 Binlog_event_writer *writer,
743 bool parallelization_barrier);
744
745 /**
746 Write a dml into statement cache and then flush it into binlog. It writes
747 Gtid_log_event and BEGIN, COMMIT automatically.
748
749 It is aimed to handle cases of "background" logging where a statement is
750 logged indirectly, like "TRUNCATE TABLE a_memory_table". So don't use it on
751 any normal statement.
752
753 @param[in] thd the THD object of current thread.
754 @param[in] stmt the DML statement.
755 @param[in] stmt_len the length of the DML statement.
756 @param[in] sql_command the type of SQL command.
757
758 @return Returns false if succeeds, otherwise true is returned.
759 */
760 bool write_stmt_directly(THD *thd, const char *stmt, size_t stmt_len,
761 enum enum_sql_command sql_command);
762
763 void report_cache_write_error(THD *thd, bool is_transactional);
764 bool check_write_error(const THD *thd);
767 void start_union_events(THD *thd, query_id_t query_id_param);
768 void stop_union_events(THD *thd);
769 bool is_query_in_union(THD *thd, query_id_t query_id_param);
770
771 bool write_buffer(const char *buf, uint len, Master_info *mi);
772 bool write_event(Log_event *ev, Master_info *mi);
773
774 /**
775 Logging XA commit/rollback of a prepared transaction.
776
777 It fills in the appropriate event in the statement cache whenever xid
778 state is marked with is_binlogged() flag that indicates the prepared
779 part of the transaction must've been logged.
780
781 About early returns from the function:
782 - ONE_PHASE option to XA-COMMIT is handled to skip writing XA-commit
783 event now.
784 - check is for the read-only XA that is not to be logged.
785
786 @param thd THD handle
787 @return error code, 0 success
788 */
789 int write_xa_to_cache(THD *thd);
790
791 ///
792 /// Write an incident and call commit.
793 ///
794 /// The incident is written by marking the transaction cache as having an
795 /// incident and then commit it to binlog. During commit, the flush stage will
796 /// write and Incident_log_event and preceding Gtid_log_event to give the
797 /// incident a proper GTID. The incident will also cause the binlog to be
798 /// rotated and check if some purge is applicable.
799 ///
800 /// @param[in] thd the THD object of current thread.
801 /// @param[in] incident_message A message describing the incident.
802 ///
803 /// @return Returns false if succeeds, otherwise true is returned.
804 ///
805 bool write_incident_commit(THD *thd, std::string_view incident_message);
806
807 private:
809
810 public:
811 /**
812 * Truncte log file and clear LOG_EVENT_BINLOG_IN_USE_F when update is set.
813 * @param[in] log_name name of the log file to be trunacted
814 * @param[in] valid_pos position at which to truncate the log file
815 * @param[in] binlog_size length of the log file before truncated
816 * @param[in] update should the LOG_EVENT_BINLOG_IN_USE_F flag be cleared
817 * true - set LOG_EVENT_BINLOG_IN_USE_F to 0
818 * false - do not modify LOG_EVENT_BINLOG_IN_USE_F flag
819 * @return true - sucess, false - failed
820 */
821 bool truncate_update_log_file(const char *log_name, my_off_t valid_pos,
822 my_off_t binlog_size, bool update);
823
824 void make_log_name(char *buf, const char *log_ident);
825 bool is_active(const char *log_file_name) const;
826
827 /** @see Binlog_index_monitor::remove_logs_outside_range_from_index */
828 int remove_logs_outside_range_from_index(const std::string &first,
829 const std::string &last);
830 int rotate(bool force_rotate, bool *check_purge);
831
832 /**
833 @brief This function runs automatic purge if the conditions to meet
834 automatic purge are met. Such conditions are: log is open, instance is not
835 locked for backup and automatic purge is enabled.
836
837 If all conditions are met, purge is done according to the configuration
838 of the purge window.
839 */
840 void auto_purge();
841
842 /**
843 @brief This member function is to be called at server startup. It checks if
844 purge can be done and does if it can.
845 */
847 int rotate_and_purge(THD *thd, bool force_rotate);
848
849 bool flush();
850 /**
851 Flush binlog cache and synchronize to disk.
852
853 This function flushes events in binlog cache to binary log file,
854 it will do synchronizing according to the setting of system
855 variable 'sync_binlog'. If file is synchronized, @c synced will
856 be set to 1, otherwise 0.
857
858 @param[in] force if true, ignores the 'sync_binlog' and synchronizes the
859 file.
860
861 @retval 0 Success
862 @retval other Failure
863 */
864 bool flush_and_sync(const bool force = false);
865 int purge_logs(const char *to_log, bool included, bool need_lock_index,
866 bool need_update_threads, ulonglong *decrease_log_space,
867 bool auto_purge);
868 int purge_logs_before_date(time_t purge_time, bool auto_purge);
869 int purge_index_entry(THD *thd, ulonglong *decrease_log_space,
870 bool need_lock_index);
871 bool reset_logs(THD *thd, bool delete_only = false);
872 void close(uint exiting, bool need_lock_log, bool need_lock_index);
873
874 // iterating through the log index file
875 int find_log_pos(Log_info *linfo, const char *log_name, bool need_lock_index);
876 int find_next_log(Log_info *linfo, bool need_lock_index);
877 int find_next_relay_log(char log_name[FN_REFLEN + 1]);
878 int get_current_log(Log_info *linfo, bool need_lock_log = true);
879 int raw_get_current_log(Log_info *linfo);
880 uint next_file_id();
881 /** @see Binlog_index_monitor::get_log_index */
882 std::pair<int, std::list<std::string>> get_log_index(
883 bool need_lock_index = true);
884 inline const char *get_index_fname() {
886 }
887 inline char *get_log_fname() { return log_file_name; }
888 const char *get_name() const { return name; }
889 inline mysql_mutex_t *get_log_lock() { return &LOCK_log; }
890 [[nodiscard]] inline mysql_mutex_t *get_sync_lock() { return &LOCK_sync; }
893 inline mysql_cond_t *get_log_cond() { return &update_cond; }
895
898 }
903 }
904
905 /**
906 Function to report the missing GTIDs.
907
908 This function logs the missing transactions on master to its error log
909 as a warning. If the missing GTIDs are too long to print in a message,
910 it suggests the steps to extract the missing transactions.
911
912 This function also informs slave about the GTID set sent by the slave,
913 transactions missing on the master and few suggestions to recover from
914 the error. This message shall be wrapped by
915 ER_SOURCE_FATAL_ERROR_READING_BINLOG on slave and will be logged as an
916 error.
917
918 This function will be called from mysql_binlog_send() function.
919
920 @param slave_executed_gtid_set GTID set executed by slave
921 @param errmsg Pointer to the error message
922 */
923 void report_missing_purged_gtids(const Gtid_set *slave_executed_gtid_set,
924 std::string &errmsg);
925
926 /**
927 Function to report the missing GTIDs.
928
929 This function logs the missing transactions on master to its error log
930 as a warning. If the missing GTIDs are too long to print in a message,
931 it suggests the steps to extract the missing transactions.
932
933 This function also informs slave about the GTID set sent by the slave,
934 transactions missing on the master and few suggestions to recover from
935 the error. This message shall be wrapped by
936 ER_SOURCE_FATAL_ERROR_READING_BINLOG on slave and will be logged as an
937 error.
938
939 This function will be called from find_first_log_not_in_gtid_set()
940 function.
941
942 @param previous_gtid_set Previous GTID set found
943 @param slave_executed_gtid_set GTID set executed by slave
944 @param errmsg Pointer to the error message
945 */
946 void report_missing_gtids(const Gtid_set *previous_gtid_set,
947 const Gtid_set *slave_executed_gtid_set,
948 std::string &errmsg);
949 /*
950 It is called by the threads (e.g. dump thread, applier thread) which want
951 to read hot log without LOCK_log protection.
952 */
956 }
960
961 /**
962 Deep copy global_tsid_map and gtid_executed.
963 Both operations are done under LOCK_commit and global_tsid_lock
964 protection.
965
966 @param[out] tsid_map The Tsid_map to which global_tsid_map will
967 be copied.
968 @param[out] gtid_set The Gtid_set to which gtid_executed will
969 be copied.
970
971 @return the operation status
972 @retval 0 OK
973 @retval !=0 Error
974 */
975 int get_gtid_executed(Tsid_map *tsid_map, Gtid_set *gtid_set);
976
977 public:
978 /**
979 Register Log_info so that log_in_use and adjust_linfo_offsets can
980 operate on all logs. Note that register_log_info, unregister_log_info,
981 log_in_use, adjust_linfo_offsets are is used on global mysql_bin_log object.
982 @param log_info pointer to Log_info which is registred
983 */
985 /**
986 Unregister Log_info when it is no longer needed.
987 @param log_info pointer to Log_info which is registred
988 */
990 /**
991 Check if any threads use log name.
992 @note This method expects the LOCK_index to be taken so there are no
993 concurrent edits against linfo objects being iterated
994 @param log_name name of a log which is checked for usage
995
996 */
997 int log_in_use(const char *log_name);
998 /**
999 Adjust the position pointer in the binary log file for all running replicas.
1000 SYNOPSIS
1001 adjust_linfo_offsets()
1002 purge_offset Number of bytes removed from start of log index file
1003 NOTES
1004 - This is called when doing a PURGE when we delete lines from the
1005 index log file. This method expects the LOCK_index to be taken so there
1006 are no concurrent edits against linfo objects being iterated. REQUIREMENTS
1007 - Before calling this function, we have to ensure that no threads are
1008 using any binary log file before purge_offset.
1009 TODO
1010 - Inform the replica threads that they should sync the position
1011 in the binary log file with flush_relay_log_info.
1012 Now they sync is done for next read.
1013 */
1014 void adjust_linfo_offsets(my_off_t purge_offset);
1015
1016 private:
1018
1019 public:
1020 [[nodiscard]] bool binlog_register_observer();
1022 [[nodiscard]] bool is_persistence_enabled();
1023
1025 std::shared_ptr<Binlog_tc_log_processing> tc_log_processing);
1026
1027 private:
1028 std::shared_ptr<Binlog_tc_log_processing> m_tc_log_processing;
1029};
1030
1035};
1036
1038
1039/**
1040 Check if the the transaction is empty.
1041
1042 @param thd The client thread that executed the current statement.
1043
1044 @retval true No changes found in any storage engine
1045 @retval false Otherwise.
1046
1047**/
1048bool is_transaction_empty(THD *thd);
1049/**
1050 Check if the transaction has no rw flag set for any of the storage engines.
1051
1052 @param thd The client thread that executed the current statement.
1053 @param trx_scope The transaction scope to look into.
1054
1055 @retval the number of engines which have actual changes.
1056 */
1058
1059/**
1060 Check if at least one of transacaction and statement binlog caches contains
1061 an empty transaction, other one is empty or contains an empty transaction,
1062 which has two binlog events "BEGIN" and "COMMIT".
1063
1064 @param thd The client thread that executed the current statement.
1065
1066 @retval true At least one of transacaction and statement binlog caches
1067 contains an empty transaction, other one is empty or
1068 contains an empty transaction.
1069 @retval false Otherwise.
1070*/
1072bool trans_has_updated_trans_table(const THD *thd);
1074bool ending_trans(THD *thd, const bool all);
1075bool ending_single_stmt_trans(THD *thd, const bool all);
1076bool trans_cannot_safely_rollback(const THD *thd);
1077bool stmt_cannot_safely_rollback(const THD *thd);
1078
1080
1081/**
1082 @brief Purges the binary log files up to the file name passed as
1083 a paramenter. Purge will not delete the file passed as
1084 an argument.
1085
1086 @param thd The session context.
1087 @param to_log Up to which log file to purge.
1088 @return true if there was an error.
1089 @return false if there was no error.
1090 */
1091bool purge_source_logs_to_file(THD *thd, const char *to_log);
1092
1093bool purge_source_logs_before_date(THD *thd, time_t purge_time);
1095bool mysql_show_binlog_events(THD *thd);
1096void check_binlog_cache_size(THD *thd);
1098bool binlog_enabled();
1099int query_error_code(const THD *thd, bool not_killed);
1100
1101extern const char *log_bin_index;
1102extern const char *log_bin_basename;
1103extern bool opt_binlog_order_commits;
1104extern ulong rpl_read_size;
1105
1106#endif /* BINLOG_H_INCLUDED */
int64 query_id_t
Definition: binlog.h:73
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:469
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:174
Auxiliary class to copy serialized events to the binary log and correct some of the fields that are n...
Definition: binlog.cc:1071
Binlog_index_monitor synchronizes access to Binlog_index object.
Definition: binlog_index.h:343
void lock()
Definition: binlog_index.h:554
IO_CACHE * get_index_file()
Definition: binlog_index.h:521
const char * get_index_fname() const
Definition: binlog_index.cc:1095
void unlock()
Definition: binlog_index.h:555
mysql_mutex_t * get_index_lock()
Definition: binlog_index.h:553
void set_psi_keys(PSI_mutex_key key_LOCK_index, PSI_file_key key_file_log_index, PSI_file_key key_file_log_index_cache)
Definition: binlog_index.cc:773
StageID
Constants for queues for different stages.
Definition: rpl_commit_stage_manager.h:166
For binlog version 4.
Definition: log_event.h:1558
Stores information to monitor a transaction during the different replication stages.
Definition: rpl_gtid.h:1414
Represents a set of GTIDs.
Definition: rpl_gtid.h:1558
Container to hold and allow iteration over a set of Ha_trx_info objects.
Definition: transaction_info.h:530
Either statement transaction or normal transaction - related thread-specific storage engine data.
Definition: transaction_info.h:430
This is the abstract base class for binary log events.
Definition: log_event.h:539
Logical binlog file which wraps and hides the detail of lower layer storage implementation.
Definition: binlog_ofile.h:35
Definition: binlog.h:108
mysql_mutex_t * get_binlog_end_pos_lock()
Definition: binlog.h:957
const char * get_name() const
Definition: binlog.h:888
mysql_cond_t m_prep_xids_cond
Definition: binlog.h:202
mysql_mutex_t * get_commit_lock()
Definition: binlog.h:891
mysql_mutex_t LOCK_binlog_end_pos
Definition: binlog.h:170
std::atomic< my_off_t > atomic_binlog_end_pos
Definition: binlog.h:174
void unlock_binlog_end_pos()
Definition: binlog.h:959
PSI_mutex_key m_key_LOCK_xids
The instrumentation key to use for @ LOCK_xids.
Definition: binlog.h:152
mysql_mutex_t LOCK_commit
Definition: binlog.h:167
char db[NAME_LEN+1]
Definition: binlog.h:119
void set_previous_gtid_set_relaylog(Gtid_set *previous_gtid_set_param)
Definition: binlog.h:427
void reset_bytes_written()
Definition: binlog.h:657
void lock_binlog_end_pos()
Definition: binlog.h:958
enum_log_state
Definition: binlog.h:113
@ LOG_OPENED
Definition: binlog.h:113
@ LOG_CLOSED
Definition: binlog.h:113
@ LOG_TO_BE_OPENED
Definition: binlog.h:113
PSI_mutex_key m_key_COND_done
The PFS instrumentation key for @ COND_done.
Definition: binlog.h:142
mysql_mutex_t LOCK_sync
Definition: binlog.h:169
PSI_mutex_key m_key_LOCK_after_commit
The instrumentation key to use for @ LOCK_after_commit.
Definition: binlog.h:148
PSI_mutex_key m_key_LOCK_commit_queue
The PFS instrumentation key for @ LOCK_commit_queue.
Definition: binlog.h:130
const char * get_index_fname()
Definition: binlog.h:884
mysql_mutex_t LOCK_after_commit
Definition: binlog.h:168
Binlog_ofile * get_binlog_file()
Definition: binlog.h:894
mysql_mutex_t LOCK_log_info
Definition: binlog.h:1017
int open(const char *opt_name) override
Initialize and open the coordinator log.
Definition: binlog.h:547
mysql_mutex_t * get_log_lock()
Definition: binlog.h:889
bool is_open() const
Definition: binlog.h:277
PSI_cond_key m_key_prep_xids_cond
The instrumentation key to use for @ prep_xids_cond.
Definition: binlog.h:158
my_off_t get_binlog_end_pos() const
Definition: binlog.h:953
void lock_index()
Definition: binlog.h:899
PSI_mutex_key m_key_LOCK_flush_queue
The PFS instrumentation key for @ LOCK_flush_queue.
Definition: binlog.h:136
PSI_mutex_key m_key_LOCK_after_commit_queue
The PFS instrumentation key for @ LOCK_after_commit_queue.
Definition: binlog.h:132
std::shared_ptr< Binlog_tc_log_processing > m_tc_log_processing
Definition: binlog.h:1028
int32 get_prep_xids()
Definition: binlog.h:217
std::atomic< enum_log_state > atomic_log_state
Definition: binlog.h:542
Gtid_set * previous_gtid_set_relaylog
Definition: binlog.h:545
PSI_cond_key m_key_update_cond
The instrumentation key to use for @ update_cond.
Definition: binlog.h:156
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:324
bool write_error
Definition: binlog.h:120
uint * sync_period_ptr
Definition: binlog.h:199
mysql_mutex_t * get_after_commit_lock()
Definition: binlog.h:892
PSI_mutex_key m_key_LOCK_done
The PFS instrumentation key for @ LOCK_done.
Definition: binlog.h:134
Binlog_index_monitor m_binlog_index_monitor
Concurrent access to binlog index file.
Definition: binlog.h:178
std::atomic< int32 > m_atomic_prep_xids
Definition: binlog.h:203
Binlog_ofile * m_binlog_file
Definition: binlog.h:121
PSI_mutex_key m_key_LOCK_sync
The instrumentation key to use for @ LOCK_sync.
Definition: binlog.h:150
void add_bytes_written(ulonglong inc)
Definition: binlog.h:656
uint get_sync_counter()
Definition: binlog.h:227
bool inited
Definition: binlog.h:120
mysql_mutex_t * get_index_lock()
Definition: binlog.h:896
PSI_mutex_key m_key_LOCK_binlog_end_pos
The instrumentation key to use for @ LOCK_binlog_end_pos.
Definition: binlog.h:128
IO_CACHE * get_index_file()
Definition: binlog.h:901
mysql_cond_t * get_log_cond()
Definition: binlog.h:893
mysql_mutex_t LOCK_log
Definition: binlog.h:116
ulong max_size
Definition: binlog.h:190
bool is_relay_log
Definition: binlog.h:283
uint get_sync_period()
Definition: binlog.h:226
PSI_cond_key m_key_COND_wait_for_group_turn
The PFS instrumentation key for @ COND_wait_for_group_turn.
Definition: binlog.h:160
PSI_mutex_key m_key_LOCK_log
The instrumentation key to use for @ LOCK_log.
Definition: binlog.h:126
PSI_mutex_key m_key_COND_flush_queue
The PFS instrumentation key for @ COND_flush_queue.
Definition: binlog.h:144
uint file_id
Definition: binlog.h:193
ulong get_max_size()
Definition: binlog.h:225
ulonglong bytes_written
Definition: binlog.h:175
mysql_cond_t update_cond
Definition: binlog.h:172
PSI_mutex_key m_key_LOCK_commit
The instrumentation key to use for @ LOCK_commit.
Definition: binlog.h:146
PSI_mutex_key m_key_LOCK_wait_for_group_turn
The PFS instrumentation key for @ LOCK_wait_for_group_turn.
Definition: binlog.h:140
void unlock_index()
Definition: binlog.h:900
PSI_file_key m_key_file_log
The instrumentation key to use for opening the log file.
Definition: binlog.h:162
PSI_mutex_key m_key_LOCK_sync_queue
The PFS instrumentation key for @ LOCK_sync_queue.
Definition: binlog.h:138
char * get_log_fname()
Definition: binlog.h:887
mysql::binlog::event::enum_binlog_checksum_alg relay_log_checksum_alg
Definition: binlog.h:319
Transaction_dependency_tracker m_dependency_tracker
Manage the MTS dependency tracking.
Definition: binlog.h:368
mysql_mutex_t * get_sync_lock()
Definition: binlog.h:890
mysql_mutex_t LOCK_xids
Definition: binlog.h:171
PSI_file_key m_key_file_log_cache
The instrumentation key to use for opening a log cache file.
Definition: binlog.h:164
uint sync_counter
Definition: binlog.h:200
PSI_file_key m_log_file_key
Instrumentation key to use for file io in log_file.
Definition: binlog.h:124
char * name
Definition: binlog.h:117
char log_file_name[FN_REFLEN]
Definition: binlog.h:118
char * get_log_file_name()
Definition: binlog.h:224
uint8 checksum_alg_reset
Definition: binlog.h:285
PSI_mutex_key m_key_LOCK_log_info
The instrumentation key to use for @ m_key_LOCK_log_info.
Definition: binlog.h:154
Definition: rpl_mi.h:87
Definition: rpl_rli.h:208
Common base class for all row-containing log events.
Definition: log_event.h:2807
Transaction Coordinator Log.
Definition: tc_log.h:144
enum_result
Definition: tc_log.h:160
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
enum_trx_scope
Definition: transaction_info.h:69
Dependency tracker is a container singleton that dispatches between the three methods associated with...
Definition: rpl_trx_tracking.h:186
Represents a bidirectional map between TSID and SIDNO.
Definition: rpl_gtid.h:751
Helper class to switch to a new thread and then go back to the previous one, when the object is destr...
Definition: binlog.cc:351
This is the base class for verifying transaction boundaries.
Definition: trx_boundary_parser.h:50
Error representation used internally in case final error code is unknown and error situation handling...
Definition: error.h:45
Definition: item_func.h:3167
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
void harvest_bytes_written(Relay_log_info *rli, bool need_log_space_lock)
Adds bytes written in the current relay log into the variable handling the total number of bytes acqu...
Definition: binlog.cc:6525
bool mysql_show_binlog_events(THD *thd)
Execute a SHOW BINLOG EVENTS statement.
Definition: binlog.cc:3199
bool stmt_cannot_safely_rollback(const THD *thd)
This function checks if current statement cannot be rollded back safely.
Definition: binlog.cc:2925
bool binlog_register_observer()
Definition: binlog.cc:7980
int write_xa_to_cache(THD *thd)
Logging XA commit/rollback of a prepared transaction.
Definition: binlog.cc:2253
std::pair< int, std::list< std::string > > get_log_index(bool need_lock_index=true)
Definition: binlog.cc:4823
int raw_get_current_log(Log_info *linfo)
Definition: binlog.cc:4763
std::pair< std::list< std::string >, mysql::utils::Error > get_filename_list()
Definition: binlog.cc:1624
void set_max_size(ulong max_size_arg)
Definition: binlog.cc:6544
ulong rpl_read_size
Definition: binlog.cc:191
int flush_cache_to_file(my_off_t *flush_end_pos)
Flush the I/O cache to file.
Definition: binlog.cc:7298
void report_cache_write_error(THD *thd, bool is_transactional)
Definition: binlog.cc:4790
bool is_transaction_empty(THD *thd)
Check if the the transaction is empty.
Definition: binlog.cc:2816
bool is_persistence_enabled()
Definition: binlog.cc:7988
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:3036
bool trans_cannot_safely_rollback(const THD *thd)
This function checks if a transaction cannot be rolled back safely.
Definition: binlog.cc:2912
int rotate(bool force_rotate, bool *check_purge)
The method executes rotation when LOCK_log is already acquired by the caller.
Definition: binlog.cc:6060
void update_thd_next_event_pos(THD *thd)
Definition: binlog.cc:5840
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:2854
void close() override
This is called on shutdown, after ha_panic.
Definition: binlog.cc:6751
int new_file_without_locking(Format_description_log_event *extra_description_event)
Definition: binlog.cc:5370
void report_missing_purged_gtids(const Gtid_set *slave_executed_gtid_set, std::string &errmsg)
Function to report the missing GTIDs.
Definition: binlog.cc:7831
uint next_file_id()
Definition: binlog.cc:6182
void cleanup()
Definition: binlog.cc:3248
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:6258
int rollback(THD *thd, bool all) override
Write a rollback record of the transaction to the binary log.
Definition: binlog.cc:2380
int remove_logs_outside_range_from_index(const std::string &first, const std::string &last)
Definition: binlog.cc:5008
void init_pthread_objects()
Definition: binlog.cc:3273
int get_current_log(Log_info *linfo, bool need_lock_log=true)
Definition: binlog.cc:4755
bool reencrypt_logs()
Re-encrypt previous existent binary/relay logs as below.
Definition: binlog.cc:1628
int log_in_use(const char *log_name)
Check if any threads use log name.
Definition: binlog.cc:6225
const char * log_bin_index
Definition: binlog.cc:187
int open_binlog(const char *opt_name)
Definition: binlog.cc:6590
~MYSQL_BIN_LOG() override
Definition: binlog.cc:3244
bool binlog_enabled()
Check whether binlog_hton has valid slot and enabled.
Definition: binlog.cc:1023
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:2835
int get_gtid_executed(Tsid_map *tsid_map, Gtid_set *gtid_set)
Deep copy global_tsid_map and gtid_executed.
Definition: binlog.cc:6190
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:1500
void process_commit_stage_queue(THD *thd, THD *queue)
Commit a sequence of sessions.
Definition: binlog.cc:7161
void wait_for_prep_xids()
Wait until the number of prepared XIDs are zero.
Definition: binlog.cc:5340
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:3503
bool write_buffer(const char *buf, uint len, Master_info *mi)
Definition: binlog.cc:5781
const char * log_bin_basename
Definition: binlog.cc:188
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:5038
void reset_thread_caches(THD *thd)
Definition: binlog.cc:7105
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:5722
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:6712
int find_log_pos(Log_info *linfo, const char *log_name, bool need_lock_index)
Definition: binlog.cc:4810
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:984
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:2676
bool write_event_to_binlog_and_sync(Log_event *ev)
Definition: binlog.cc:6329
void set_tc_log_processing(std::shared_ptr< Binlog_tc_log_processing > tc_log_processing)
Definition: binlog.cc:7992
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:6560
bool is_active(const char *log_file_name) const
Check if we are writing/reading to the given log file.
Definition: binlog.cc:5313
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:1004
std::pair< bool, bool > sync_binlog_file(bool force)
Call fsync() to sync the file to disk.
Definition: binlog.cc:7311
int find_next_relay_log(char log_name[FN_REFLEN+1])
Definition: binlog.cc:4819
int generate_new_name(char *new_name, const char *log_name, uint32 new_index_number=0)
Definition: binlog.cc:3437
void finish_transaction_in_engines(THD *thd, bool all, bool run_after_commit)
Finishes the transaction in the engines.
Definition: binlog.cc:7420
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event *event, bool is_transactional)
Definition: binlog.cc:5856
int finish_commit(THD *thd)
Helper function executed when leaving ordered_commit.
Definition: binlog.cc:7354
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:6284
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:2901
void unregister_log_info(Log_info *log_info)
Unregister Log_info when it is no longer needed.
Definition: binlog.cc:6219
enum_result commit(THD *thd, bool all) override
Commit the transaction in the transaction coordinator.
Definition: binlog.cc:6794
bool check_write_error(const THD *thd)
Definition: binlog.cc:4771
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:2940
int wait_for_update()
Wait until we get a signal that the binary log has been updated.
Definition: binlog.cc:6416
void make_log_name(char *buf, const char *log_ident)
Create a new log file name.
Definition: binlog.cc:5302
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:7262
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:4069
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:6366
bool write_event(Log_event *event_info)
Write an event to the binary log cache.
Definition: binlog.cc:5897
void update_binlog_end_pos(bool need_lock=true)
Definition: binlog.cc:7962
int rotate_and_purge(THD *thd, bool force_rotate)
Execute a FLUSH LOGS statement.
Definition: binlog.cc:6150
bool is_query_in_union(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:5831
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:5390
bool write_event_to_binlog(Log_event *ev)
Definition: binlog.cc:6308
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:4847
bool purge_source_logs_before_date(THD *thd, time_t purge_time)
Execute a PURGE BINARY LOGS BEFORE <date> command.
Definition: binlog.cc:2980
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:2868
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:2886
int query_error_code(const THD *thd, bool not_killed)
Definition: binlog.cc:3008
void process_after_commit_stage_queue(THD *thd, THD *first)
Process after commit for a sequence of sessions.
Definition: binlog.cc:7234
std::pair< int, my_off_t > flush_thread_caches(THD *thd)
Flush caches for session.
Definition: binlog.cc:7088
bool write_transaction(THD *thd, binlog_cache_data *cache_data, Binlog_event_writer *writer, bool parallelization_barrier)
Write the Gtid_log_event to the binary log (prior to writing the statement or transaction cache).
Definition: binlog.cc:1342
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:7895
int purge_index_entry(THD *thd, ulonglong *decrease_log_space, bool need_lock_index)
Definition: binlog.cc:5161
void binlog_unregister_observer()
Definition: binlog.cc:7984
bool init_and_set_log_file_name(const char *log_name, const char *new_name, uint32 new_index_number)
Definition: binlog.cc:3477
const char * generate_name(const char *log_name, const char *suffix, char *buff)
Definition: binlog.cc:3458
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:5186
bool opt_binlog_order_commits
Definition: binlog.cc:185
void init_thd_variables(THD *thd, bool all, bool skip_commit)
Set thread variables used while flushing a transaction.
Definition: binlog.cc:7110
int find_next_log(Log_info *linfo, bool need_lock_index)
Definition: binlog.cc:4815
void start_union_events(THD *thd, query_id_t query_id_param)
Definition: binlog.cc:5818
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:4182
bool open_index_file(const char *index_file_name_arg, const char *log_name, bool need_lock_index)
Definition: binlog.cc:3556
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:1277
void auto_purge()
This function runs automatic purge if the conditions to meet automatic purge are met.
Definition: binlog.cc:6090
int prepare(THD *thd, bool all) override
Log a prepare record of the transaction to the storage engines.
Definition: binlog.cc:6763
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:6213
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:7465
int ordered_commit(THD *thd, bool all, bool skip_commit=false)
Flush and commit the transaction.
Definition: binlog.cc:7513
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:6235
int call_after_sync_hook(THD *queue_head)
Auxiliary function used in ordered_commit.
Definition: binlog.cc:7429
MYSQL_BIN_LOG(uint *sync_period, bool relay_log=false)
Definition: binlog.cc:3220
bool flush_and_sync(const bool force=false)
Flush binlog cache and synchronize to disk.
Definition: binlog.cc:5808
int new_file(Format_description_log_event *extra_description_event)
Definition: binlog.cc:5361
bool show_binlog_events(THD *thd, MYSQL_BIN_LOG *binary_log)
Definition: binlog.cc:3071
void inc_prep_xids(THD *thd)
Increment the prepared XID counter.
Definition: binlog.cc:5317
void dec_prep_xids(THD *thd)
Decrement the prepared XID counter.
Definition: binlog.cc:5328
void stop_union_events(THD *thd)
Definition: binlog.cc:5826
bool flush()
Definition: binlog.cc:5804
void signal_update()
Notifies waiting threads that binary log has been updated.
Definition: binlog.cc:7954
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:2823
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:4084
void report_binlog_write_error()
Definition: binlog.cc:6408
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:5626
void auto_purge_at_server_startup()
This member function is to be called at server startup.
Definition: binlog.cc:6078
bool write_incident_commit(THD *thd, std::string_view incident_message)
Write an incident and call commit.
Definition: binlog.cc:2281
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:44
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:48
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
#define mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
Definition: mysql_mutex.h:126
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint8_t uint8
Definition: my_inttypes.h:63
ulonglong my_off_t
Definition: my_inttypes.h:72
int64_t int64
Definition: my_inttypes.h:68
int32_t int32
Definition: my_inttypes.h:66
uint32_t uint32
Definition: my_inttypes.h:67
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:87
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:71
enum_sql_command
Definition: my_sqlcommand.h:46
Common header for many mysys elements.
static int not_killed
Definition: myisamchk.cc:1619
static uint update
Definition: myisamlog.cc:94
static QUEUE queue
Definition: myisampack.cc:210
Common definition between mysql server & client.
#define NAME_LEN
Definition: mysql_com.h:67
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:293
Definition: base.h:75
Definition: buf0block_hint.cc:30
const std::string opt_name("mysql_option_tracker_option")
Definition: os0file.h:89
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:499
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:455
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:32
Definition: binlog.h:90
Item_result type
Definition: binlog.h:94
ulong length
Definition: binlog.h:93
char * value
Definition: binlog.h:92
bool unsigned_flag
Definition: binlog.h:96
user_var_entry * user_var_event
Definition: binlog.h:91
uint charset_number
Definition: binlog.h:95
TODO: Move this structure to mysql/binlog/event/control_events.h when we start using C++11.
Definition: rpl_gtid.h:1102
Definition: my_sys.h:342
Definition: binlog.h:1031
bool log_delayed
Definition: binlog.h:1034
my_off_t last_pos_in_file
Definition: binlog.h:1033
bool logged_data_file
Definition: binlog.h:1034
THD * thd
Definition: binlog.h:1032
Definition: binlog_index.h:86
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
MySQL mutex implementation.
#define log_info(msg,...)
Definition: tm_log.h:79
Transaction boundary parser definitions.
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:890