1. 23 Jan, 2024 6 commits
    • Michael Widenius's avatar
      MDEV-32551: "Read semi-sync reply magic number error" warnings on master · 7af50e4d
      Michael Widenius authored
      rpl_semi_sync_slave_enabled_consistent.test and the first part of
      the commit message comes from Brandon Nesterenko.
      
      A test to show how to induce the "Read semi-sync reply magic number
      error" message on a primary. In short, if semi-sync is turned on
      during the hand-shake process between a primary and replica, but
      later a user negates the rpl_semi_sync_slave_enabled variable while
      the replica's IO thread is running; if the io thread exits, the
      replica can skip a necessary call to kill_connection() in
      repl_semisync_slave.slave_stop() due to its reliance on a global
      variable. Then, the replica will send a COM_QUIT packet to the
      primary on an active semi-sync connection, causing the magic number
      error.
      
      The test in this patch exits the IO thread by forcing an error;
      though note a call to STOP SLAVE could also do this, but it ends up
      needing more synchronization. That is, the STOP SLAVE command also
      tries to kill the VIO of the replica, which makes a race with the IO
      thread to try and send the COM_QUIT before this happens (which would
      need more debug_sync to get around). See THD::awake_no_mutex for
      details as to the killing of the replica’s vio.
      
      Notes:
      - The MariaDB documentation does not make it clear that when one
        enables semi-sync replication it does not matter if one enables
        it first in the master or slave. Any order works.
      
      Changes done:
      - The rpl_semi_sync_slave_enabled variable is now a default value for
        when semisync is started. The variable does not anymore affect
        semisync if it is already running. This fixes the original reported
        bug.  Internally we now use repl_semisync_slave.get_slave_enabled()
        instead of rpl_semi_sync_slave_enabled. To check if semisync is
        active on should check the @@rpl_semi_sync_slave_status variable (as
        before).
      - The semisync protocol conflicts in the way that the original
        MySQL/MariaDB client-server protocol was designed (client-server
        send and reply packets are strictly ordered and includes a packet
        number to allow one to check if a packet is lost). When using
        semi-sync the master and slave can send packets at 'any time', so
        packet numbering does not work. The 'solution' has been that each
        communication starts with packet number 1, but in some cases there
        is still a chance that the packet number check can fail.  Fixed by
        adding a flag (pkt_nr_can_be_reset) in the NET struct that one can
        use to signal that packet number checking should not be done. This
        is flag is set when semi-sync is used.
      - Added Master_info::semi_sync_reply_enabled to allow one to configure
        some slaves with semisync and other other slaves without semisync.
        Removed global variable semi_sync_need_reply that would not work
        with multi-master.
      - Repl_semi_sync_master::report_reply_packet() can now recognize
        the COM_QUIT packet from semisync slave and not give a
        "Read semi-sync reply magic number error" error for this case.
        The slave will be removed from the Ack listener.
      - On Windows, don't stop semisync Ack listener just because one
        slave connection is using socket_id > FD_SETSIZE.
      - Removed busy loop in Ack_receiver::run() by using
       "Self-pipe trick" to signal new slave and stop Ack_receiver.
      - Changed some Repl_semi_sync_slave functions that always returns 0
        from int to void.
      - Added Repl_semi_sync_slave::slave_reconnect().
      - Removed dummy_function Repl_semi_sync_slave::reset_slave().
      - Removed some duplicate semisync notes from the error log.
      - Add test of "if (get_slave_enabled() && semi_sync_need_reply)"
        before calling Repl_semi_sync_slave::slave_reply().
        (Speeds up the code as we can skip all initializations).
      - If epl_semisync_slave.slave_reply() fails, we disable semisync
        for that connection.
      - We do not call semisync.switch_off() if there are no active slaves.
        Instead we check in Repl_semi_sync_master::commit_trx() if there are
        no active threads. This simplices the code.
      - Changed assert() to DBUG_ASSERT() to ensure that the DBUG log is
        flushed in case of asserts.
      - Removed the internal rpl_semi_sync_slave_status as it is not needed
        anymore. The @@rpl_semi_sync_slave_status status variable is now
        mapped to rpl_semi_sync_enabled.
      - Removed rpl_semi_sync_slave_enabled  as it is not needed anymore.
        Repl_semi_sync_slave::get_slave_enabled() contains the active status.
      - Added checking that we do not add a slave twice with
        Ack_receiver::add_slave(). This could happen with old code.
      - Removed Repl_semi_sync_master::check_and_switch() as it is not
        needed anymore.
      - Ensure that when we call Ack_receiver::remove_slave() that the slave
        is removed from the listener before function returns.
      - Call listener.listen_on_sockets() outside of mutex for better
        performance and less contested mutex.
      - Ensure that listening is ignoring newly added slaves when checking for
        responses.
      - Fixed the master ack_receiver listener is not killed if there are no
        connected slaves (and thus stop semisync handling of future
        connections). This could happen if all slaves sockets where would be
        marked as unreliable.
      - Added unlink() to base_ilist_iterator and remove() to
        I_List_iterator. This enables us to remove 'dead' slaves in
        Ack_recever::run().
      - kill_zombie_dump_threads() now does killing of dump threads properly.
        - It can now kill several threads (should be impossible but could
          happen if IO slaves reconnects very fast).
        - We now wait until the dump thread is done before starting the
          dump.
      - Added an error if kill_zombie_dump_threads() fails.
      - Set thd->variables.server_id before calling
        kill_zombie_dump_threads(). This simplies the code.
      - Added a lot of comments both in code and tests.
      - Removed DBUG_EVALUATE_IF "failed_slave_start" as it is not used.
      
      Test changes:
      - rpl.rpl_session_var2 added which runs rpl.rpl_session_var test with
        semisync enabled.
      - Some timings changed slight with startup of slave which caused
        rpl_binlog_dump_slave_gtid_state_info.text to fail as it checked the
        error log file before the slave had started properly. Fixed by
        adding wait_for_pattern_in_file.inc that allows waiting for the
        pattern to appear in the log file.
      - Tests have been updated so that we first set
        rpl_semi_sync_master_enabled on the master and then set
        rpl_semi_sync_slave_enabled on the slaves (this is according to how
        the MariaDB documentation document how to setup semi-sync).
      - Error text "Master server does not have semi-sync enabled" has been
        replaced with "Master server does not support semi-sync" for the
        case when the master supports semi-sync but semi-sync is not
        enabled.
      
      Other things:
      - Some trivial cleanups in Repl_semi_sync_master::update_sync_header().
      - We should in 11.3 changed the default value for
        rpl-semi-sync-master-wait-no-slave from TRUE to FALSE as the TRUE
        does not make much sense as default. The main difference with using
        FALSE is that we do not wait for semisync Ack if there are no slave
        threads.  In the case of TRUE we wait once, which did not bring any
        notable benefits except slower startup of master configured for
        using semisync.
      
      Co-author: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
      
      This solves the problem reported in MDEV-32960 where a new
      slave may not be registered in time and the master disables
      semi sync because of that.
      7af50e4d
    • Rucha Deodhar's avatar
      MDEV-32906: The SQL error plugin prints (null) as database if the mariadb · ee7cc0a4
      Rucha Deodhar authored
      client is not using any database to execute the SQL.
      
      Analysis:
      When there is no database, the database string is NULL so (null) gets
      printed.
      Fix:
      Print NULL instead of (null) because when there is no database SELECT
      DATABASE() return NULL. SO NULL is more appropriate choice.
      ee7cc0a4
    • Rucha Deodhar's avatar
      MDEV-27087: Add thread ID and database / table, where the error occured · 90cd712b
      Rucha Deodhar authored
      to SQL error plugin
      
      New plugin variable "with_db_and_thread_info" is added which prints the
      thread id and databse name to the logfile. the value is stored in variable
      "with_db_and_thread_info"
      
      log_sql_errors() is responsible for printing in the log. If detailed is
      enabled, print thread id and database name both, otherwise skip it.
      90cd712b
    • Daniel Black's avatar
      Merge remote-tracking branch 10.5 into 10.6 · 4ef9c9bb
      Daniel Black authored
      Notably MDEV-33290, columnstore disable stays in 10.5.
      4ef9c9bb
    • Daniel Black's avatar
      MDEV-33290: Disable ColumnStore based on boost version · 5ce6a352
      Daniel Black authored
      MCOL-5611 supporting with Boost-1.80, the version "next_prime"
      disappears from https://github.com/boostorg/unordered/blob/boost-1.79.0/include/boost/unordered/detail/implementation.hpp
      makes it the currenly highest supported versions.
      
      Lets check this version.
      
      While CMake-3.19+ supports version ranges in package determinations this
      isn't supported for Boost in Cmake-3.28. So we check for the 1.80 and
      don't compile ColumnStore.
      5ce6a352
    • Dmitry Shulga's avatar
      sql_test.cc compile fix · 13e49b78
      Dmitry Shulga authored
      13e49b78
  2. 22 Jan, 2024 7 commits
  3. 19 Jan, 2024 8 commits
  4. 18 Jan, 2024 1 commit
  5. 17 Jan, 2024 4 commits
    • Sophist's avatar
    • Marko Mäkelä's avatar
      Merge 10.5 into 10.6 · 3a96eba2
      Marko Mäkelä authored
      3a96eba2
    • Marko Mäkelä's avatar
      MDEV-30940: Try to fix the test · 6a514ef6
      Marko Mäkelä authored
      6a514ef6
    • Marko Mäkelä's avatar
      MDEV-33213 History list is not shrunk unless there is a pause in the workload · f8c88d90
      Marko Mäkelä authored
      The parameter innodb_undo_log_truncate=ON enables a multi-phased logic:
      1. Any "producers" (new starting transactions) are prohibited
      from using the rollback segments that reside in the undo tablespace.
      2. Any transactions that use any of the rollback segments must be
      committed or aborted.
      3. The purge of committed transaction history must process all the
      rollback segments.
      4. The undo tablespace is truncated and rebuilt.
      5. The rollback segments are re-enabled for new transactions.
      
      There was one flaw in this logic: The first step was not being invoked
      as often as it could be, and therefore innodb_undo_log_truncate=ON
      would have no chance to work during a heavy write workload.
      
      Independent of innodb_undo_log_truncate, even after
      commit 86767bcc
      we are missing some chances to free processed undo log pages.
      If we prohibited the creation of new transactions in one busy
      rollback segment at a time, we would be eventually guaranteed
      to be able to free such pages.
      
      purge_sys_t::skipped_rseg: The current candidate rollback segment
      for shrinking the history independent of innodb_undo_log_truncate.
      
      purge_sys_t::iterator::free_history_rseg(): Renamed from
      trx_purge_truncate_rseg_history(). Implement the logic
      around purge_sys.m_skipped_rseg.
      
      purge_sys_t::truncate_undo_space: Renamed from truncate.
      
      purge_sys.truncate_undo_space.last: Changed the type to integer
      to get rid of some pointer dereferencing and conditional branches.
      
      purge_sys_t::truncating_tablespace(), purge_sys_t::undo_truncate_try():
      Refactored from trx_purge_truncate_history().
      Set purge_sys.truncate_undo_space.current if applicable,
      or return an already set purge_sys.truncate_undo_space.current.
      
      purge_coordinator_state::do_purge(): Invoke
      purge_sys_t::truncating_tablespace() as part of the normal work loop,
      to implement innodb_undo_log_truncate=ON as often as possible.
      
      trx_purge_truncate_rseg_history(): Remove a redundant parameter.
      
      trx_undo_truncate_start(): Replace dead code with a debug assertion.
      
      Correctness tested by: Matthias Leich
      Performance tested by: Axel Schwenke
      Reviewed by: Debarun Banerjee
      f8c88d90
  6. 16 Jan, 2024 2 commits
  7. 15 Jan, 2024 1 commit
    • Thirunarayanan Balathandayuthapani's avatar
      MDEV-32968 InnoDB fails to restore tablespace first page from doublewrite... · caad34df
      Thirunarayanan Balathandayuthapani authored
      MDEV-32968  InnoDB fails to restore tablespace first page from doublewrite buffer when page is empty
      
      - InnoDB fails to find the space id from the page0 of
      the tablespace. In that case, InnoDB can use
      doublewrite buffer to recover the page0 and write
      into the file.
      
      - buf_dblwr_t::init_or_load_pages(): Loads only the pages
      which are valid.(page lsn >= checkpoint). To do that,
      InnoDB has to open the redo log before system
      tablespace, read the latest checkpoint information.
      
      recv_dblwr_t::find_first_page():
      1) Iterate the doublewrite buffer pages and find the 0th page
      2) Read the tablespace flags, space id from the 0th page.
      3) Read the 1st, 2nd and 3rd page from tablespace file and
      compare the space id with the space id which is stored
      in doublewrite buffer.
      4) If it matches then we can write into the file.
      5) Return space which matches the pages from the file.
      
      SysTablespace::read_lsn_and_check_flags(): Remove the
      retry logic for validating the first page. After
      restoring the first page from doublewrite buffer,
      assign tablespace flags by reading the first page.
      
      recv_recovery_read_max_checkpoint(): Reads the maximum
      checkpoint information from log file
      
      recv_recovery_from_checkpoint_start(): Avoid reading
      the checkpoint header information from log file
      
      Datafile::validate_first_page(): Throw error in case
      of first page validation fails.
      caad34df
  8. 14 Jan, 2024 1 commit
  9. 13 Jan, 2024 1 commit
  10. 12 Jan, 2024 3 commits
  11. 11 Jan, 2024 5 commits
  12. 10 Jan, 2024 1 commit
    • Marko Mäkelä's avatar
      MDEV-33112 innodb_undo_log_truncate=ON is blocking page write · 3613fb2a
      Marko Mäkelä authored
      When innodb_undo_log_truncate=ON causes an InnoDB undo tablespace
      to be truncated, we must guarantee that the undo tablespace will
      be rebuilt atomically: After mtr_t::commit_shrink() has durably
      written the mini-transaction that rebuilds the undo tablespace,
      we must not write any old pages to the tablespace.
      
      To guarantee this, in trx_purge_truncate_history() we used to
      traverse the entire buf_pool.flush_list in order to acquire
      exclusive latches on all pages for the undo tablespace that
      reside in the buffer pool, so that those pages cannot be written
      and will be evicted during mtr_t::commit_shrink(). But, this
      traversal may interfere with the page writing activity of
      buf_flush_page_cleaner(). It would be better to lazily discard
      the old pages of the truncated undo tablespace.
      
      fil_space_t::is_being_truncated, fil_space_t::clear_stopping(): Remove.
      
      fil_space_t::create_lsn: A new field, identifying the LSN of the
      latest rebuild of a tablespace.
      
      buf_page_t::flush(), buf_flush_try_neighbors(): Evict pages whose
      FIL_PAGE_LSN is below fil_space_t::create_lsn.
      
      mtr_t::commit_shrink(): Update fil_space_t::create_lsn and
      fil_space_t::size right before the log is durably written and the
      tablespace file is being truncated.
      
      fsp_page_create(), trx_purge_truncate_history(): Simplify the logic.
      
      Reviewed by: Thirunarayanan Balathandayuthapani, Vladislav Lesin
      Performance tested by: Axel Schwenke
      Correctness tested by: Matthias Leich
      3613fb2a