• Vicențiu Ciorbaru's avatar
    MDEV-17964: Assertion `status == 0' failed in add_role_user_mapping_action · 9e6c3838
    Vicențiu Ciorbaru authored
    This happens upon CREATE USER and DROP ROLE.
    
    The underlying problem is that our HASH implementation shuffles elements
    around when performing an update or delete. This means that when doing a
    scan through the HASH table by index, in search of elements to delete or
    update one must restart the scan to make sure nothing is missed if at least
    one delete / update happened.
    
    More specifically, what happened in this case:
    The hash has 131 element, DROP ROLE removes the element
    [119]. Its [119]->next was element [129], so [129] is moved to [119].
    Now we need to compact the hash, removing the last element [130]. It
    gets one bit off its hash value and becomes element [2]. The existing
    element [2] is moved to [129], and old [130] is moved to [2].
    
    We cannot simply move [130] to [129] and make [2]->next=130, it won't
    work if [2] is itself in the collision list and doesn't belong in [2].
    
    The handle_grant_struct code assumed that it is safe to continue by only
    reexamining the currently modified / deleted element index, but that is
    not true.
    
    Missing to delete an element in the hash triggered the assertion in
    the test case. DROP ROLE would not clear all necessary role->role or
    role->user mappings.
    
    To fix the problem we ensure that the scan is restarted, only if an
    element was deleted / updated, similar to how bubble-sort keeps sorting
    until it finds no more elements to swap.
    9e6c3838
rebuild_role_grants.test 1.78 KB