Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19439

Allow THD member (or base) class constructor/destructor to allocate/free memory

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Server
    • None

    Description

      Currently such attempts lead to assertions like this:

      mysqld.cc:3757: void my_malloc_size_cb_func(long long int, my_bool): Assertion `!is_thread_specific || (mysqld_server_initialized && thd)' failed.
      

      The reason is that memory accounting is done in THD constructor (which is called after member/base class constructor). Thus memory allocated by member/base constructor is not accounted. Same problem (but turn it upside down) with destructor.

      This causes ugly constructor/destructor simulation like:

      THD::~THD()
      {
        ...
        /* trick to make happy memory accounting system */
      #ifndef EMBEDDED_LIBRARY
        session_tracker.sysvars.deinit();
      #endif //EMBEDDED_LIBRARY
       
        if (status_var.local_memory_used != 0)
        {
          DBUG_PRINT("error", ("memory_used: %lld", status_var.local_memory_used));
          SAFEMALLOC_REPORT_MEMORY(thread_id);
          DBUG_ASSERT(status_var.local_memory_used == 0 ||
                      !debug_assert_on_not_freed_memory);
        }
        update_global_memory_status(status_var.global_memory_used);
        set_current_thd(orig_thd == this ? 0 : orig_thd);
        DBUG_VOID_RETURN;
      }
      

      Original implementation was declined due to convoluted current_thd juggling. This juggling is needed, because in some cases THD objects are created by thread creator, not thread itself.

      Patches implementing this task are in bb-10.5-svoj-MDEV-19439, but they are incomplete and fail on assertions. Move THD creation from creator to creature and do whatever is needed to make them work.

      Attachments

        Activity

          People

            Unassigned Unassigned
            svoj Sergey Vojtovich
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.