• Chen Tianjie's avatar
    Optimize resizing hash table to resize not only non-empty dicts. (#12819) · af7ceeb7
    Chen Tianjie authored
    The function `tryResizeHashTables` only attempts to shrink the dicts
    that has keys (change from #11695), this was a serious problem until the
    change in #12850 since it meant if all keys are deleted, we won't shrink
    the dick.
    But still, both dictShrink and dictExpand may be blocked by a fork child
    process, therefore, the cron job needs to perform both dictShrink and
    dictExpand, for not just non-empty dicts, but all dicts in DBs.
    
    What this PR does:
    
    1. Try to resize all dicts in DBs (not just non-empty ones, as it was
    since #12850)
    2. handle both shrink and expand (not just shrink, as it was since
    forever)
    3. Refactor some APIs about dict resizing (get rid of `htNeedsShrink`
    `htNeedsShrink` `dictShrinkToFit`, and expose `dictShrinkIfNeeded`
    `dictExpandIfNeeded` which already contains all the code of those
    functions we get rid of, to make APIs more neat)
    4. In the `Don't rehash if redis has child process` test, now that cron
    would do resizing, we no longer need to write to DB after the child
    process got killed, and can wait for the cron to expand the hash table.
    af7ceeb7
t_zset.c 152 KB