• zhaozhao.zz's avatar
    Unified db rehash method for both standalone and cluster (#12848) · d8a21c57
    zhaozhao.zz authored
    After #11695, we added two functions `rehashingStarted` and
    `rehashingCompleted` to the dict structure. We also registered two
    handlers for the main database's dict and expire structures. This allows
    the main database to record the dict in `rehashing` list when rehashing
    starts. Later, in `serverCron`, the `incrementallyRehash` function is
    continuously called to perform the rehashing operation. However,
    currently, when rehashing is completed, `rehashingCompleted` does not
    remove the dict from the `rehashing` list. This results in the
    `rehashing` list containing many invalid dicts. Although subsequent cron
    checks and removes dicts that don't require rehashing, it is still
    inefficient.
    
    This PR implements the functionality to remove the dict from the
    `rehashing` list in `rehashingCompleted`. This is achieved by adding
    `metadata` to the dict structure, which keeps track of its position in
    the `rehashing` list, allowing for quick removal. This approach avoids
    storing duplicate dicts in the `rehashing` list.
    
    Additionally, there are other modifications:
    
    1. Whether in standalone or cluster mode, the dict in database is
    inserted into the rehashing linked list when rehashing starts. This
    eliminates the need to distinguish between standalone and cluster mode
    in `incrementallyRehash`. The function only needs to focus on the dicts
    in the `rehashing` list that require rehashing.
    2. `rehashing` list is moved from per-database to Redis server level.
    This decouples `incrementallyRehash` from the database ID, and in
    standalone mode, there is no need to iterate over all databases,
    avoiding unnecessary access to databases that do not require rehashing.
    In the future, even if unsharded-cluster mode supports multiple
    databases, there will be no risk involved.
    3. The insertion and removal operations of dict structures in the
    `rehashing` list are decoupled from `activerehashing` config.
    `activerehashing` only controls whether `incrementallyRehash` is
    executed in serverCron. There is no need for additional steps when
    modifying the `activerehashing` switch, as in #12705.
    d8a21c57
lazyfree.c 9 KB