Add diagnostic post-condition check to ensure ingest table is empty after truncation

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: Major - P3
    • WT12.0.0
    • Affects Version/s: None
    • Component/s: Truncate
    • None
    • Storage Engines - Foundations, Storage Engines - Persistence
    • SE Persistence - 2026-03-27
    • 2

      Issue Summary

      When draining an ingest table, the current implementation truncates the table but does not verify that it is actually empty afterward. This can lead to undetected issues if the truncation fails or leaves residual records.

      Context

      • The proposal is to add a sanity check in diagnostic builds to assert that the ingest table is empty after truncation.
      • The suggested implementation introduces a new function, __layered_assert_ingest_table_empty, which opens a cursor on the ingest table, counts remaining records, and asserts that the count is zero.
      • This check is wrapped in #ifdef HAVE_DIAGNOSTIC to ensure it only runs in diagnostic builds.
      • Code snippet provided:
        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
        #ifdef HAVE_DIAGNOSTIC
        /*
         * __layered_assert_ingest_table_empty --
         *     Verify that the ingest table has no records. Called after truncation as a post-condition
         *     check.
         */
        static int
        __layered_assert_ingest_table_empty(WT_SESSION_IMPL *session, const char *uri)
        {
            WT_CURSOR *cursor;
            WT_DECL_RET;
            uint64_t count;
        
            count = 0;
            WT_RET(__wt_open_cursor(session, uri, NULL, NULL, &cursor));
            while ((ret = cursor->next(cursor)) == 0)
                ++count;
            WT_TRET(cursor->close(cursor));
        
            if (ret == WT_NOTFOUND)
                ret = 0;
            WT_RET(ret);
        
            if (count != 0) {
                __wt_verbose_error(session, WT_VERB_LAYERED,
                  "Ingest table \"%s\" is not empty after truncation: %" PRIu64 " record(s) remaining", uri,
                  count);
                WT_ASSERT(session, count == 0);
            }
        
            return (0);
        }
        #endif
        
      • The function is called immediately after __layered_clear_ingest_table in the drain worker logic.

      Proposed Solution

      • Integrate the provided function into the codebase for diagnostic builds.
      • Ensure the check is executed after every ingest table truncation to catch any failures.
      • Add verbose logging and assertion to facilitate debugging if records remain.

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

            Assignee:
            Etienne Petrel
            Reporter:
            Memento Slack Bot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: