Skip to content
  • Vasil Dimov's avatar
    54d574af
    Fix Bug#14007109 RECURSIVE ACQ OF BLOCK LOCK IN S MODE, STATS UPDATE · 54d574af
    Vasil Dimov authored
    ASRT !RW_LOCK_OWN(LOCK, 352)
    
    Manually release the latch on the last page before calling btr_pcur_close().
    If that latch is not released we will stumble on the latched page upon our
    next iteration on the same level which causes an assertion failure because
    recursive S-latches are not allowed.
    
    The code, roughly does this:
    dict_stats_analyze_index()
      start mtr
      dict_stats_analyze_index_level(mtr)
        traverse the level (leaves the last page in the middle level S-latched)
      dict_stats_analyze_index_for_n_prefix(mtr)
        traverse the level (would try to S-latch the last page)
      commit mtr
    Notice that if the level has just one page, then this bug does not resurface
    because the pcur code always latches the first page (where opened) in X-mode
    and a page left latched in X-mode is not a problem because X-mode latches are
    allowed to be recursive.
    
    Another way to fix this would be to commit the mtr in order to release the
    page latch, but that will also release the tree-level S-lock and the tree may
    change in between and we must take care to recognize such change.
    
    Given that those page-level latches are acquired internally by the pcur code
    and that they are released internally by the pcur code when jumping to the
    next page, it makes most sense to release the latch on the current page when
    closing the cursor in btr_pcur_close(). But that would require passing the
    mtr to btr_pcur_close() and this function is used in lots of places. Another
    consideration (raised by Marko) is that the page may contain changes in which
    case the mtr should be committed instead of releasing the page latch. On the
    other hand, the pcur code already releases the latches on pages it leaves.
    54d574af
    Fix Bug#14007109 RECURSIVE ACQ OF BLOCK LOCK IN S MODE, STATS UPDATE
    Vasil Dimov authored
    ASRT !RW_LOCK_OWN(LOCK, 352)
    
    Manually release the latch on the last page before calling btr_pcur_close().
    If that latch is not released we will stumble on the latched page upon our
    next iteration on the same level which causes an assertion failure because
    recursive S-latches are not allowed.
    
    The code, roughly does this:
    dict_stats_analyze_index()
      start mtr
      dict_stats_analyze_index_level(mtr)
        traverse the level (leaves the last page in the middle level S-latched)
      dict_stats_analyze_index_for_n_prefix(mtr)
        traverse the level (would try to S-latch the last page)
      commit mtr
    Notice that if the level has just one page, then this bug does not resurface
    because the pcur code always latches the first page (where opened) in X-mode
    and a page left latched in X-mode is not a problem because X-mode latches are
    allowed to be recursive.
    
    Another way to fix this would be to commit the mtr in order to release the
    page latch, but that will also release the tree-level S-lock and the tree may
    change in between and we must take care to recognize such change.
    
    Given that those page-level latches are acquired internally by the pcur code
    and that they are released internally by the pcur code when jumping to the
    next page, it makes most sense to release the latch on the current page when
    closing the cursor in btr_pcur_close(). But that would require passing the
    mtr to btr_pcur_close() and this function is used in lots of places. Another
    consideration (raised by Marko) is that the page may contain changes in which
    case the mtr should be committed instead of releasing the page latch. On the
    other hand, the pcur code already releases the latches on pages it leaves.
Loading