Refactor page selection logic in evict_lru.c for improved readability

XMLWordPrintableJSON

    • Type: Technical Debt
    • Resolution: Unresolved
    • Priority: Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Cache and Eviction
    • Storage Engines - Transactions
    • SE Transactions - 2026-04-10
    • 1

      Issue Summary

      The code in evict_lru.c responsible for determining whether a page should be considered for eviction is currently implemented as a single complex boolean expression. This reduces readability and makes future maintenance more difficult.

      Context

      The current logic is as follows:

      /* Skip pages we don't want. */
      want_page =
        (F_ISSET(evict, WT_EVICT_CACHE_CLEAN) && !F_ISSET(btree, WT_BTREE_IN_MEMORY) && !modified) ||
        (F_ISSET(evict, WT_EVICT_CACHE_DIRTY) && modified) ||
        (F_ISSET(evict, WT_EVICT_CACHE_UPDATES) && page->modify != NULL);
      if (!want_page) {
          WT_STAT_CONN_INCR(session, eviction_server_skip_unwanted_pages);
          return;
      }
      

      A proposed refactor splits the logic into named boolean variables, improving clarity:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      +    bool evict_clean = F_ISSET(evict, WT_EVICT_CACHE_CLEAN) && !F_ISSET(btree, WT_BTREE_IN_MEMORY) && !modified;
      +    bool evict_dirty = F_ISSET(evict, WT_EVICT_CACHE_DIRTY) && modified;
      +    bool evict_updates = F_ISSET(evict, WT_EVICT_CACHE_UPDATES) && page->modify != NULL;
      +    bool want_page = evict_clean || evict_dirty || evict_updates;
      

      Proposed Solution

      • Refactor the page selection logic in evict_lru.c to use named boolean variables as shown above.
      • This will improve code readability and maintainability without changing the underlying logic.

      Original Slack thread: Slack Thread
      This ticket was generated by AI from a Slack thread.

            Assignee:
            Ayesha Ahmed
            Reporter:
            Memento Slack Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: