From dd8ffe952d3976afe409efe9eb8c7d4f8071dc65 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Fri, 17 Jan 2025 14:09:04 +0100 Subject: [PATCH] MDEV-34705: Binlog-in-engine: Misc. small fixes to make normal test suite mostly pass Signed-off-by: Kristian Nielsen --- mysql-test/main/mysqld--help.result | 10 +++++ .../suite/sys_vars/r/sysvars_innodb.result | 12 ++++++ .../r/sysvars_server_notembedded.result | 10 +++++ sql/log.cc | 20 ++++++---- sql/mysqld.cc | 7 ++-- storage/innobase/handler/innodb_binlog.cc | 37 ++++++++++++------- 6 files changed, 70 insertions(+), 26 deletions(-) diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index adc10ecd44e..eb5e2453790 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -78,6 +78,10 @@ The following specify which files/extra groups are read (specified before remain tables such as in the statement INSERT INTO t_myisam SELECT * FROM t_innodb; otherwise, slaves may diverge from the master. + --binlog-directory=name + Directory path (absolute or relative to datadir) where + binlog files are stored. If this is used, must not + specify a directory path for --log-bin --binlog-do-db=name Tells the master it should log updates for the specified database, and exclude all others not explicitly mentioned. @@ -158,6 +162,10 @@ The following specify which files/extra groups are read (specified before remain non-transactional engines for the binary log. If you often use statements updating a great number of rows, you can increase this to get more performance. + --binlog-storage-engine=name + Store the binlog transactionally in a supporting storage + engine instead of as separate files. Currently only + InnoDB is supported. --block-encryption-mode=name Default block encryption mode for AES_ENCRYPT() and AES_DECRYPT() functions. One of: aes-128-ecb, aes-192-ecb, @@ -1629,6 +1637,7 @@ binlog-checksum CRC32 binlog-commit-wait-count 0 binlog-commit-wait-usec 100000 binlog-direct-non-transactional-updates FALSE +binlog-directory (No default value) binlog-expire-logs-seconds 0 binlog-file-cache-size 16384 binlog-format MIXED @@ -1642,6 +1651,7 @@ binlog-row-image FULL binlog-row-metadata NO_LOG binlog-space-limit 0 binlog-stmt-cache-size 32768 +binlog-storage-engine block-encryption-mode aes-128-ecb bulk-insert-buffer-size 8388608 character-set-client-handshake TRUE diff --git a/mysql-test/suite/sys_vars/r/sysvars_innodb.result b/mysql-test/suite/sys_vars/r/sysvars_innodb.result index 35bc5cba9e1..f35b09faf2b 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_innodb.result +++ b/mysql-test/suite/sys_vars/r/sysvars_innodb.result @@ -91,6 +91,18 @@ NUMERIC_BLOCK_SIZE 0 ENUM_VALUE_LIST NULL READ_ONLY YES COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME INNODB_BINLOG_STATE_INTERVAL +SESSION_VALUE NULL +DEFAULT_VALUE 2097152 +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE BIGINT UNSIGNED +VARIABLE_COMMENT Interval (in bytes) at which to write the GTID binlog state to binlog files to speed up GTID lookups. Must be a multiple of innodb_page_size +NUMERIC_MIN_VALUE 65536 +NUMERIC_MAX_VALUE 18446744073709551615 +NUMERIC_BLOCK_SIZE 0 +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME INNODB_BUFFER_POOL_CHUNK_SIZE SESSION_VALUE NULL DEFAULT_VALUE 0 diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 347b5eebebb..784402c0998 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -402,6 +402,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME BINLOG_DIRECTORY +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT Directory path (absolute or relative to datadir) where binlog files are stored. If this is used, must not specify a directory path for --log-bin +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME BINLOG_DIRECT_NON_TRANSACTIONAL_UPDATES VARIABLE_SCOPE SESSION VARIABLE_TYPE BOOLEAN diff --git a/sql/log.cc b/sql/log.cc index cb60d722cca..b1cd9cc4bb7 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -402,14 +402,18 @@ public: last_commit_pos_file[0]= 0; last_commit_pos_offset= 0; } - /* - Use a custom write_function to spill to the engine-implemented binlog. - And re-use the IO_CACHE::append_read_pos as a handle for our - write_function; it is unused when the cache is not SEQ_READ_APPEND. - */ - trx_cache.cache_log.write_function= binlog_spill_to_engine; - trx_cache.cache_log.append_read_pos= (uchar *)this; - engine_binlog_info= {0, 0, 0}; + if (likely(opt_binlog_engine_hton) && + likely(opt_binlog_engine_hton->binlog_oob_data)) + { + /* + Use a custom write_function to spill to the engine-implemented binlog. + And re-use the IO_CACHE::append_read_pos as a handle for our + write_function; it is unused when the cache is not SEQ_READ_APPEND. + */ + trx_cache.cache_log.write_function= binlog_spill_to_engine; + trx_cache.cache_log.append_read_pos= (uchar *)this; + engine_binlog_info= {0, 0, 0}; + } } binlog_cache_data* get_binlog_cache_data(bool is_transactional) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 2983b0a91ff..8ec0f64a07e 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5558,13 +5558,12 @@ static int init_server_components() if (opt_bin_log) { mysql_mutex_t *log_lock= mysql_bin_log.get_log_lock(); - int error; + bool error; if (opt_binlog_engine_hton) { mysql_mutex_lock(log_lock); - if ((*opt_binlog_engine_hton->binlog_init)((size_t)max_binlog_size, - opt_binlog_directory)) - error= 1; + error= (*opt_binlog_engine_hton->binlog_init)((size_t)max_binlog_size, + opt_binlog_directory); mysql_mutex_unlock(log_lock); if (unlikely(error)) unireg_abort(1); diff --git a/storage/innobase/handler/innodb_binlog.cc b/storage/innobase/handler/innodb_binlog.cc index cfb051deb8c..687c8bdaf83 100644 --- a/storage/innobase/handler/innodb_binlog.cc +++ b/storage/innobase/handler/innodb_binlog.cc @@ -32,6 +32,8 @@ InnoDB implementation of binlog. #include "log.h" +static int innodb_binlog_inited= 0; + uint32_t innodb_binlog_size_in_pages; const char *innodb_binlog_directory; @@ -426,6 +428,7 @@ innodb_binlog_startup_init() { fsp_binlog_init(); binlog_diff_state.init(); + innodb_binlog_inited= 1; } @@ -493,6 +496,7 @@ innodb_binlog_init(size_t binlog_size, const char *directory) innodb_binlog_directory= directory; innodb_binlog_init_state(); + innodb_binlog_inited= 2; /* Find any existing binlog files and continue writing in them. */ int res= innodb_binlog_discover(); @@ -780,24 +784,28 @@ innodb_binlog_discover() void innodb_binlog_close(bool shutdown) { - if (binlog_prealloc_thr_obj.joinable()) { - mysql_mutex_lock(&active_binlog_mutex); - prealloc_thread_end= true; - pthread_cond_signal(&active_binlog_cond); - mysql_mutex_unlock(&active_binlog_mutex); - binlog_prealloc_thr_obj.join(); - } + if (innodb_binlog_inited >= 2) + { + if (binlog_prealloc_thr_obj.joinable()) { + mysql_mutex_lock(&active_binlog_mutex); + prealloc_thread_end= true; + pthread_cond_signal(&active_binlog_cond); + mysql_mutex_unlock(&active_binlog_mutex); + binlog_prealloc_thr_obj.join(); + } - uint64_t file_no= first_open_binlog_file_no; - if (file_no != ~(uint64_t)0) { - if (file_no <= last_created_binlog_file_no) { - fsp_binlog_tablespace_close(file_no); - if (file_no + 1 <= last_created_binlog_file_no) { - fsp_binlog_tablespace_close(file_no + 1); + uint64_t file_no= first_open_binlog_file_no; + if (file_no != ~(uint64_t)0) { + if (file_no <= last_created_binlog_file_no) { + fsp_binlog_tablespace_close(file_no); + if (file_no + 1 <= last_created_binlog_file_no) { + fsp_binlog_tablespace_close(file_no + 1); + } } } } - if (shutdown) + + if (shutdown && innodb_binlog_inited >= 1) { binlog_diff_state.free(); fsp_binlog_shutdown(); @@ -2192,6 +2200,7 @@ innodb_reset_binlogs() { bool err= false; + ut_a(innodb_binlog_inited >= 2); /* Close existing binlog tablespaces and stop the pre-alloc thread. */ innodb_binlog_close(false);