1. 06 Jun, 2024 3 commits
    • Marko Mäkelä's avatar
      MDEV-34296 extern thread_local is a CPU waste · 699d38d9
      Marko Mäkelä authored
      In commit 99bd2260 (MDEV-31558)
      we wrongly thought that there would be minimal overhead for accessing
      a thread-local variable mariadb_stats.
      
      It turns out that in C++11, each access to an extern thread_local
      variable requires conditionally invoking an initialization function.
      In fact, the initializer expression of mariadb_stats is dynamic, and
      those calls were actually unavoidable.
      
      In C++20, one could declare constinit thread_local variables, but
      the address of a thread_local variable (&mariadb_dummy_stats) is not
      a compile-time constant. We did not want to declare mariadb_dummy_stats
      without thread_local, because then the dummy accesses could lead to
      cache line contention between threads.
      
      mariadb_stats: Declare as __thread or __declspec(thread) so that
      there will be no dynamic initialization, but zero-initialization.
      
      mariadb_dummy_stats: Remove. It is a lesser evil to let
      the environment perform zero-initialization and check if
      !mariadb_stats.
      
      Reviewed by: Sergei Petrunia
      699d38d9
    • Marko Mäkelä's avatar
      MDEV-34283 A misplaced btr_cur_need_opposite_intention() check may fail to prevent hangs · 9fac857f
      Marko Mäkelä authored
      btr_cur_t::search_leaf(): Invoke btr_cur_need_opposite_intention() after
      positioning page_cur.rec so that the record will be in the intended page.
      This is something that was broken in
      commit f2096478 or
      commit de4030e4 or related changes.
      
      btr_cur_need_opposite_intention(): Add a debug assertion that would
      catch the misuse.
      
      The "next line of defence" that should have caught this bug in debug builds
      are assertions that mtr_t::m_memo contains MTR_MEMO_X_LOCK for the
      dict_index_t::lock. When btr_cur_need_opposite_intention() holds,
      we should escalate to acquiring an exclusive index->lock in
      btr_cur_t::pessimistic_search_leaf().
      
      Reviewed by: Debarun Banerjee
      9fac857f
    • Marko Mäkelä's avatar
      MDEV-34307 On startup, [FATAL] InnoDB: Page ... still fixed or dirty · bc366092
      Marko Mäkelä authored
      buf_pool_invalidate(): Properly wait for
      os_aio_wait_until_no_pending_writes() to ensure so that there
      are no pending buf_page_t::write_complete() or buf_page_write_complete()
      operations. This will avoid a failure of buf_pool.assert_all_freed().
      
      This bug should affect debug builds only. At this point, the
      buf_pool.flush_list should be clear and all changes should have
      been written out. The loop around buf_LRU_scan_and_free_block() should
      have eventually completed and freed all pages as soon as
      buf_page_t::write_complete() had a chance to release the page latches.
      
      It is worth noting that buf_flush_wait() is working as intended.
      As soon as buf_flush_page_cleaner() invokes
      buf_pool.get_oldest_modification() it will observe that
      buf_page_t::write_complete() had assigned oldest_modification_ to 1,
      and remove such blocks from buf_pool.flush_list. Upon reaching
      buf_pool.flush_list.count=0 the buf_flush_page_cleaner() will mark
      itself idle and wake buf_flush_wait() by broadcasting
      buf_pool.done_flush_list.
      
      This regression was introduced in
      commit a55b951e (MDEV-26827).
      
      Reviewed by: Debarun Banerjee
      bc366092
  2. 05 Jun, 2024 2 commits
    • mariadb-DebarunBanerjee's avatar
      MDEV-34265 Possible hang during IO burst with innodb_flush_sync enabled · b12c14e3
      mariadb-DebarunBanerjee authored
      When checkpoint age goes beyond the sync flush threshold and
      buf_flush_sync_lsn is set, page cleaner enters into "furious flush"
      stage to aggressively flush dirty pages from flush list and pull
      checkpoint LSN above safe margin. In this stage, page cleaner skips
      doing LRU flush and eviction.
      
      In 10.6, all other threads entirely rely on page cleaner to generate
      free pages. If free pages get over while page cleaner is busy in
      "furious flush" stage, a session thread could wait for free page in the
      middle of a min-transaction(mtr) while holding latches on other pages.
      
      It, in turn, can prevent page cleaner to flush such pages preventing
      checkpoint LSN to move forward creating a deadlock situation. Even
      otherwise, it could create a stall and hang like situation for large BP
      with plenty of dirty pages to flush before the stage could finish.
      
      Fix: During furious flush, check and evict LRU pages after each flush
      iteration.
      b12c14e3
    • Tuukka Pasanen's avatar
      MDEV-34261: Detect if build is running under 32-bit container · b2048179
      Tuukka Pasanen authored
      When building on 64-bit kernel machine in 32-bit docker container
      CMake falsely (but it works as expected) detects that container
      runtime in also 64-bits. Use linux32 command to change runtime
      enviroment to 32-bit and then CMake will correctly disable for
      example ColumnStore and not try to build it
      
      This commit only works with debian/autobake-debs.sh
      b2048179
  3. 03 Jun, 2024 1 commit
  4. 30 May, 2024 7 commits
  5. 29 May, 2024 2 commits
  6. 28 May, 2024 1 commit
    • Souradeep Saha's avatar
      Fix Various Typos · 83a04be8
      Souradeep Saha authored
      Fix various typos, in comments and DEBUG statements, and code changes
      are non-functional.
      
      All new code of the whole pull request, including one or several files
      that are either new files or modified ones, are contributed under the
      BSD-new license. I am contributing on behalf of my employer Amazon Web
      Services, Inc.
      83a04be8
  7. 27 May, 2024 3 commits
    • Sergei Petrunia's avatar
      MDEV-34125: ANALYZE FORMAT=JSON: r_engine_stats.pages_read_time_ms has wrong scale · 36ab6cc8
      Sergei Petrunia authored
      - Change the comments in class ha_handler_stats to say the members
        are in ticks, not milliseconds.
      - In sql_explain.cc, adjust the scale to print milliseconds.
      36ab6cc8
    • Alexander Barkov's avatar
      MDEV-34226 On startup: UBSAN: applying zero offset to null pointer in... · 4a158ec1
      Alexander Barkov authored
      MDEV-34226 On startup: UBSAN: applying zero offset to null pointer in my_copy_fix_mb from strings/ctype-mb.c and other locations
      
      nullptr+0 is an UB (undefined behavior).
      
      - Fixing my_string_metadata_get_mb() to handle {nullptr,0} without UB.
      - Fixing THD::copy_with_error() to disallow {nullptr,0} by DBUG_ASSERT().
      - Fixing parse_client_handshake_packet() to call THD::copy_with_error()
        with an empty string {"",0} instead of NULL string {nullptr,0}.
      4a158ec1
    • Alexander Barkov's avatar
      MDEV-30931 UBSAN: negation of -X cannot be represented in type 'long long... · 79253261
      Alexander Barkov authored
      MDEV-30931 UBSAN: negation of -X cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself in get_interval_value on SELECT
      
      - Fixing the code in get_interval_value() to use Longlong_hybrid_null.
        This allows to handle correctly:
      
        - Signed and unsigned arguments
          (the old code assumed the argument to be signed)
        - Avoid undefined negation behavior the corner case with LONGLONG_MIN
      
        This fixes the UBSAN warning:
          negation of -9223372036854775808 cannot be represented
          in type 'long long int';
      
      - Fixing the code in get_interval_value() to avoid overflow in
        the INTERVAL_QUARTER and INTERVAL_WEEK branches.
        This fixes the UBSAN warning:
          signed integer overflow: -9223372036854775808 * 7 cannot be represented
          in type 'long long int'
      
      - Fixing the INTERVAL_WEEK branch in date_add_interval() to handle
        huge numbers correctly. Before the change, huge positive numeber
        were treated as their negative complements.
        Note, some other branches still can be affected by this problem
        and should also be fixed eventually.
      79253261
  8. 24 May, 2024 2 commits
  9. 23 May, 2024 2 commits
    • Vladislav Vaintroub's avatar
      MDEV-34205: ASAN stack buffer overflow in strxnmov() in frm_file_exists · 736449d3
      Vladislav Vaintroub authored
      Correct the second parameter for strxnmov to prevent potential buffer
      overflows. The second parameter must be one less than the size of the
      input buffer to avoid writing past the end of the buffer.
      
      While the second parameter is usually correct, there are exceptions
      that need fixing.
      
      This commit addresses the issue within frm_file_exists() and other
      affected places.
      736449d3
    • Alexander Barkov's avatar
      MDEV-28387 UBSAN: runtime error: negation of -9223372036854775808 cannot be... · 7c4c0823
      Alexander Barkov authored
      MDEV-28387 UBSAN: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself in my_strtoll10 on SELECT
      
      Fixing the condition to raise an overflow in the ulonglong
      representation of the number is greater or equal to 0x8000000000000000ULL.
      Before this change the condition did not catch -9223372036854775808
      (the smallest possible signed negative longlong number).
      7c4c0823
  10. 21 May, 2024 6 commits
    • Yuchen Pei's avatar
    • Marko Mäkelä's avatar
      MDEV-33817 fixup: Disable for macOS · 266495b9
      Marko Mäkelä authored
      According to https://discussions.apple.com/thread/8256853
      an attempt to use AVX512 registers on macOS will result in #UD
      (crash at runtime).
      
      Also, starting with clang-18 and GCC 14, we must add "evex512" to the
      target flags so that AVX and SSE instructions can use AVX512 specific
      encodings. This flag was introduced together with the avx10.1-512 target.
      Older compiler versions do not recognize "evex512". We do not want to
      write "avx10.1-512" because it could enable some AVX512 subfeatures
      that we do not have any CPUID check for.
      
      Reviewed by: Vladislav Vaintroub
      Tested on macOS by: Valerii Kravchuk
      266495b9
    • Alexander Barkov's avatar
      Backporting bugs fixes fixed by MDEV-31340 from 11.5 · 310fd6ff
      Alexander Barkov authored
      The patch for MDEV-31340 fixed the following bugs:
      
      MDEV-33084 LASTVAL(t1) and LASTVAL(T1) do not work well with lower-case-table-names=0
      MDEV-33085 Tables T1 and t1 do not work well with ENGINE=CSV and lower-case-table-names=0
      MDEV-33086 SHOW OPEN TABLES IN DB1 -- is case insensitive with lower-case-table-names=0
      MDEV-33088 Cannot create triggers in the database `MYSQL`
      MDEV-33103 LOCK TABLE t1 AS t2 -- alias is not case sensitive with lower-case-table-names=0
      MDEV-33108 TABLE_STATISTICS and INDEX_STATISTICS are case insensitive with lower-case-table-names=0
      MDEV-33109 DROP DATABASE MYSQL -- does not drop SP with lower-case-table-names=0
      MDEV-33110 HANDLER commands are case insensitive with lower-case-table-names=0
      MDEV-33119 User is case insensitive in INFORMATION_SCHEMA.VIEWS
      MDEV-33120 System log table names are case insensitive with lower-cast-table-names=0
      
      Backporting the fixes from 11.5 to 10.5
      310fd6ff
    • mariadb-DebarunBanerjee's avatar
      MDEV-34166 Server could hang with BP < 80M under stress · b2944adb
      mariadb-DebarunBanerjee authored
      BUF_LRU_MIN_LEN (256) is too high value for low buffer pool(BP) size.
      For example, for BP size lower than 80M and 16 K page size, the limit is
      more than 5% of total BP and for lowest BP 5M, it is 80% of the BP.
      Non-data objects like explicit locks could occupy part of the BP pool
      reducing the pages available for LRU. If LRU reaches minimum limit and
      if no free pages are available, server would hang with page cleaner not
      able to free any more pages.
      
      Fix: To avoid such hang, we adjust the LRU limit lower than the limit
      for data objects as checked in buf_LRU_check_size_of_non_data_objects()
      i.e. one page less than 5% of BP.
      b2944adb
    • Marko Mäkelä's avatar
      MDEV-34204 Assertion `!*detailed_error' failed on shutdown after XA PREPARE · 0907df3d
      Marko Mäkelä authored
      trx_free_at_shutdown(): Similar to trx_t::commit_in_memory(),
      clear the detailed_error (FOREIGN KEY constraint error) before
      invoking trx_t::free(). We only do this on debug instrumented
      builds in order to avoid a debug assertion failure on shutdown.
      0907df3d
    • mariadb-DebarunBanerjee's avatar
      MDEV-34167 We fail to terminate transaction early with ER_LOCK_TABLE_FULL when... · 2d5cba22
      mariadb-DebarunBanerjee authored
      MDEV-34167 We fail to terminate transaction early with ER_LOCK_TABLE_FULL when lock memory is growing
      
      This regression is introduced in 10.6 by following commit.
      commit b6a24724
      MDEV-27891: SIGSEGV in InnoDB buffer pool resize
      
      During DML, we check if buffer pool is running out of data pages in
      buf_pool_t::running_out. Here is 75% of the buffer pool is occupied by
      non-data pages we rollback the current transaction and exit with
      ER_LOCK_TABLE_FULL.
      
      The integer division (n_chunks_new / 4) becomes zero whenever the total
      number of chunks are < 4 making the check completely ineffective for
      such cases. Also the check is inaccurate for larger chunks.
      
      Fix-1: Correct the check in buf_pool_t::running_out.
      
      Fix-2: While waiting for free page, check for
      buf_LRU_check_size_of_non_data_objects.
      2d5cba22
  11. 20 May, 2024 5 commits
    • Yuchen Pei's avatar
      MDEV-31475 Spider: only reset wide_handler when owning it · 698dae54
      Yuchen Pei authored
      A wide_handler is shared among ha_spider of partitions of the same
      spider table, where the last partition is designated the owner of the
      wide_handler, and is responsible for its deallocation. Therefore in
      case of failure, we only reset wide_handler in error handling if the
      current ha_spider is the owner of the wide_handler, otherwise it will
      result in segv in the destructor of ha_spider, or during
      ha_spider::close().
      698dae54
    • Yuchen Pei's avatar
      MDEV-31475 remove unnecessary assignment to spider share init_error · 86adee38
      Yuchen Pei authored
      The init, init_error, and init_error_time fields of a SPIDER_SHARE
      should only be assigned when actually doing the initialisation of a
      SPIDER_SHARE, otherwise they could result in spurious failures from
      spider_get_share() in a subsequent statement.
      86adee38
    • mariadb-DebarunBanerjee's avatar
      MDEV-28800 SIGABRT due to running out of memory for InnoDB locks · 8047c8bc
      mariadb-DebarunBanerjee authored
      This regression is introduced in 10.6 by following commit.
      commit 898dcf93
      (Cleanup the lock creation)
      
      It removed one important optimization for lock bitmap pre-allocation.
      We pre-allocate about 8 byte extra space along with every lock object to
      adjust for similar locks on newly created records on the same page by
      same transaction. When it is exhausted, a new lock object is created
      with similar 8 byte pre-allocation. With this optimization removed we
      are left with only 1 byte pre-allocation. When large number of records
      are inserted and locked in a single page, we end up creating too many
      new locks almost in n^2 order.
      
      Fix-1: Bring back LOCK_PAGE_BITMAP_MARGIN for pre-allocation.
      
      Fix-2: Use the extra space (40 bytes) for bitmap in trx->lock.rec_pool.
      8047c8bc
    • Thirunarayanan Balathandayuthapani's avatar
      MDEV-34175 mtr_t::log_close() warning should change the shutdown condition · ac2e02e9
      Thirunarayanan Balathandayuthapani authored
      - InnoDB should print the warning message saying
      "Shutdown is in progress" only when shutdown state
      is greater than SRV_SHUTDOWN_INITIATED.
      ac2e02e9
    • Alexander Barkov's avatar
      MDEV-34187 On startup: UBSAN: runtime error: applying zero offset to null... · 28073a97
      Alexander Barkov authored
      MDEV-34187 On startup: UBSAN: runtime error: applying zero offset to null pointer in skip_trailing_space and my_hash_sort_utf8mb3_general1400_nopad_as_ci
      
      The last element in func_array_oracle_overrides[] equal to {0,0}
      was erroneously passed to Native_functions_hash::replace().
      Removing this element.
      28073a97
  12. 17 May, 2024 1 commit
    • Robin Newhouse's avatar
      Minimize unsafe C functions with safe_strcpy() · dc38d8ea
      Robin Newhouse authored
      Similar to #2480.
      567b6812 introduced safe_strcpy() to minimize the use of C with
      potentially unsafe memory overflow with strcpy() whose use is
      discouraged.
      Replace instances of strcpy() with safe_strcpy() where possible, limited
      here to files in the `sql/` directory.
      
      All new code of the whole pull request, including one or several files
      that are either new files or modified ones, are contributed under the
      BSD-new license. I am contributing on behalf of my employer
      Amazon Web Services, Inc.
      dc38d8ea
  13. 16 May, 2024 1 commit
  14. 15 May, 2024 2 commits
  15. 14 May, 2024 2 commits
    • Sergei Golubchik's avatar
    • Yuchen Pei's avatar
      MDEV-28105 Return error in ha_spider::write_row() if info(HA_STATUS_AUTO) fails · fd767462
      Yuchen Pei authored
      Spider calls info with HA_STATUS_AUTO to update auto increment info,
      which may attempt to connect the data node. If the connection fails,
      it may emit an error and return the same error. This error should not
      be of lower priority than any possible error from the later call to
      handler::update_auto_increment().
      
      Without this change, certain errors from update_auto_increment() such
      as HA_ERR_AUTOINC_ERANGE may get ignored, causing my_insert() to call
      my_ok(), which fails the assertion because the error was emitted in
      the info() call (Diagnostics_area::is_set() returns true).
      fd767462