Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashing innodb due to innobase_share usage_count not being reduced for temp table accesses #5212

Open
wants to merge 1 commit into
base: 5.7
Choose a base branch
from

Commits on Jan 25, 2024

  1. Fix crashing innodb due to innobase_share usage_count not being reduc…

    …ed for temp table accesses
    
    The MySQL engine is designed with the assumption that accesses to
    temporary tables will only ever occur from the thread that created
    the temporary table. Cross thread accesses of temporary tables are
    not expected and are therefore not designed for. However, if the
    information schema is queried for details about a temporary table,
    then the temporary table gets accessed from a thread that is
    different from the thread that created the temporary table,
    breaking the design assumption.
    
    When this cross-thread accesss of a temporary table happens for
    engines that use the InnoDB storage engine, the INNOBASE_SHARE
    use_count for the table gets incremented, but never gets
    decremented when the none-owning thread completes. In certain
    situations, this can lead to a crash of the database engine, when
    invariants in the function innobase_build_index_translation fail
    on assertion. For example we found a use case that cause MySQL
    to crash with the assertion failure below:
    
        (gdb) bt
        #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
        percona#1  0x00007f3132141859 in __GI_abort () at abort.c:79
        percona#2  0x000055ed7452a19a in ut_dbg_assertion_failed (expr=0x55ed7489f848 "share->idx_trans_tbl.index_count == mysql_num_index",
            file=0x55ed7489ea90 "/github/MySQL5.7/mysql-server/storage/innobase/handler/ha_innodb.cc", line=5680)
            at /github/MySQL5.7/mysql-server/storage/innobase/ut/ut0dbg.cc:75
        percona#3  0x000055ed7437ecda in innobase_build_index_translation (table=0x7f30bcaaa4d0, ib_table=0x7f30bc023888, share=0x7f30b002c100)
            at /github/MySQL5.7/mysql-server/storage/innobase/handler/ha_innodb.cc:5680
        percona#4  0x000055ed7437fe6d in ha_innobase::open (this=0x7f30bcaa6a10, name=0x7f30bcaab1c0 "./test/#sql-bae1d_3", mode=2, test_if_locked=2)
            at /github/MySQL5.7/mysql-server/storage/innobase/handler/ha_innodb.cc:6115
    
    The above issue is fixed by allowing the use_count for an
    INNODB_SHARE object of a temporary table to be decremented during
    query cleanup, whenever a temporary table is accessed from a
    none-owning thread. Care is taken to make sure that the use_count
    decrement is done inside of the a critical region protected by
    the innobase_share_mutex mutex.
    
    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.
    lottaquestions committed Jan 25, 2024
    Configuration menu
    Copy the full SHA
    e6c6b18 View commit details
    Browse the repository at this point in the history