• Yuchen Pei's avatar
    MDEV-33661 MENT-1591 Keep spider in memory until exit in ASAN builds · 662bb176
    Yuchen Pei authored
    Same as MDEV-29579. For some reason, libodbc does not clean up
    properly if unloaded too early with the dlclose() of spider. So we add
    UNIQUE symbols to spider so the spider does not reload in dlclose().
    
    This change, however, uncovers some hidden problems in the spider
    codebase, for which we move the initialisation of some spider global
    variables into the initialisation of spider itself.
    
    Spider has some global variables. Their initialisation should be done
    in the initialisation of spider itself, otherwise, if spider were
    re-initialised without these symbol being unloaded, the values could
    be inconsistent and causing issues.
    
    One such issue is caused by the variables
    spider_mon_table_cache_version and spider_mon_table_cache_version_req.
    They are used for resetting the spider monitoring table cache and have
    initial values of 0 and 1 respectively. We have that always
    spider_mon_table_cache_version_req >= spider_mon_table_cache_version,
    and when the relation is strict, the cache is reset,
    spider_mon_table_cache_version is brought to be equal to
    spider_mon_table_cache_version_req, and the cache is searched for
    matching table_name, db_name and link_idx. If the relation is equal,
    no reset would happen and the cache would be searched directly.
    
    When spider is re-inited without resetting the values of
    spider_mon_table_cache_version and spider_mon_table_cache_version_req
    that were set to be equal in the previous cache reset action, the
    cache was emptied in the previous spider deinit, which would result in
    HA_ERR_KEY_NOT_FOUND unexpectedly.
    
    An alternative way to fix this issue would be to call the spider udf
    spider_flush_mon_cache_table(), which increments
    spider_mon_table_cache_version_req thus making sure the inequality is
    strict. However, there's no reason for spider to initialise these
    global variables on dlopen(), rather than on spider init, which is
    cleaner and "purer".
    
    To reproduce this issue, simply revert the changes involving the two
    variables and then run:
    
    mtr --no-reorder spider.ha{,_part}
    662bb176
spd_table.cc 333 KB